Commit 38729c94 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Highlight selected column

parent e61372b5
...@@ -34,15 +34,15 @@ import org.eclipse.core.databinding.observable.IChangeListener; ...@@ -34,15 +34,15 @@ import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties; import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
...@@ -58,7 +58,7 @@ import org.eclipse.swt.events.DisposeEvent; ...@@ -58,7 +58,7 @@ import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
...@@ -123,25 +123,43 @@ public class SheetDisplay extends Composite { ...@@ -123,25 +123,43 @@ public class SheetDisplay extends Composite {
} }
} }
private class TableLabelProvider extends LabelProvider implements ITableLabelProvider { private class TableLabelProvider extends CellLabelProvider {
@Override @Override
public Image getColumnImage(Object element, int columnIndex) { public void update(final ViewerCell cell) {
return null; final int columnIndex = cell.getColumnIndex();
} final Object element = cell.getElement();
if (element instanceof Object[]) {
@Override
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Object[]) {
Object[] elArr = (Object[]) element; Object[] elArr = (Object[]) element;
if (columnIndex < elArr.length) { if (columnIndex < elArr.length) {
Object el = ((Object[]) element)[columnIndex]; Object el = ((Object[]) element)[columnIndex];
return el == null ? "" : el.toString(); cell.setText(el == null ? "" : el.toString());
} else }
return null;
} }
return element.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);
}
}
}
}
}
private Table table; private Table table;
private Text txtColumnName; private Text txtColumnName;
...@@ -617,6 +635,12 @@ public class SheetDisplay extends Composite { ...@@ -617,6 +635,12 @@ public class SheetDisplay extends Composite {
public void handleEvent(Event event) { public void handleEvent(Event event) {
_log.debug("Selected " + column); _log.debug("Selected " + column);
dsw.setSelectedColumn(column); dsw.setSelectedColumn(column);
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
updateTable();
}
});
} }
}); });
} }
......
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