Commit 58b20e98 authored by Matija Obreza's avatar Matija Obreza

Fixed jump-bug on column selection

parent 20f91089
......@@ -29,16 +29,17 @@ import org.apache.log4j.Logger;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
......@@ -72,6 +73,7 @@ import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.converter.RowConverter;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
......@@ -81,12 +83,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import swing2swt.layout.BorderLayout;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.wb.swt.SWTResourceManager;
import swing2swt.layout.BorderLayout;
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SheetDisplay extends Composite {
......@@ -105,6 +105,11 @@ public class SheetDisplay extends Composite {
@Autowired
private ObjectMapper mapper;
final Color pinkColor = SWTResourceManager.getColor(255, 192, 203);
final Color blueColor = SWTResourceManager.getColor(173, 216, 230);
final Color yellowColor = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
final Color listBackgroundColor = SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND);
private static class ContentProvider implements IStructuredContentProvider {
@Override
public Object[] getElements(Object inputElement) {
......@@ -123,43 +128,38 @@ public class SheetDisplay extends Composite {
}
}
private class TableLabelProvider extends CellLabelProvider {
@Override
public void update(final ViewerCell cell) {
final int columnIndex = cell.getColumnIndex();
final Object element = cell.getElement();
if (element instanceof Object[]) {
private class TableLabelProvider extends StyledCellLabelProvider {
@Override
public void update(final ViewerCell cell) {
final int columnIndex = cell.getColumnIndex();
System.err.println("Update col " + columnIndex);
final Object element = cell.getElement();
if (element instanceof Object[]) {
Object[] elArr = (Object[]) element;
if (columnIndex < elArr.length) {
Object el = ((Object[]) element)[columnIndex];
cell.setText(el == null ? "" : el.toString());
cell.setText(el == null ? "" : el.toString());
}
}
final Color pinkColor = SWTResourceManager.getColor(255,192,203);
final Color blueColor = SWTResourceManager.getColor(173,216,230);
final Color yellowColor = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
final Column selectedColumn = dsw.getSelectedColumn();
final Column currentColumn = dsw.getDataSourceSheet().getColumns().get(columnIndex);
if (currentColumn.getRdfTerm() != null && !currentColumn.getRdfTerm().isEmpty()) {
if (selectedColumn != null) {
if (selectedColumn.getPreferredName().equals(currentColumn.getPreferredName())) {
cell.setBackground(pinkColor); // pink
} else {
cell.setBackground(blueColor); // light blue
}
} else {
cell.setBackground(blueColor); // light blue
}
} else {
if (selectedColumn != null) {
if (selectedColumn.getPreferredName().equals(currentColumn.getPreferredName())) {
cell.setBackground(yellowColor);
}
}
}
}
}
if (currentColumn.getRdfTerm() != null && !currentColumn.getRdfTerm().isEmpty()) {
if (currentColumn == selectedColumn) {
cell.setBackground(pinkColor); // pink
} else {
cell.setBackground(blueColor); // light blue
}
} else {
if (currentColumn == selectedColumn) {
cell.setBackground(yellowColor); // yellow
} else {
cell.setBackground(listBackgroundColor); // default
}
}
}
}
private Table table;
private Text txtColumnName;
......@@ -635,12 +635,12 @@ public class SheetDisplay extends Composite {
public void handleEvent(Event event) {
_log.debug("Selected " + column);
dsw.setSelectedColumn(column);
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
updateTable();
}
});
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
tableViewer.refresh();
}
});
}
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment