Commit f0e8a04f authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '12-highlight-selected-column' into 'master'

Resolve "Highlight selected column"

Closes #12

See merge request !10
parents 20f91089 58b20e98
...@@ -29,16 +29,17 @@ import org.apache.log4j.Logger; ...@@ -29,16 +29,17 @@ import org.apache.log4j.Logger;
import org.eclipse.core.databinding.Binding; import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties; 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.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener; 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.StyledCellLabelProvider;
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;
...@@ -72,6 +73,7 @@ import org.eclipse.swt.widgets.TabItem; ...@@ -72,6 +73,7 @@ import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.converter.RowConverter; import org.genesys2.anno.converter.RowConverter;
import org.genesys2.anno.model.Column; import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef; import org.genesys2.anno.model.ColumnDef;
...@@ -81,12 +83,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -81,12 +83,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import swing2swt.layout.BorderLayout;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; 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) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SheetDisplay extends Composite { public class SheetDisplay extends Composite {
...@@ -105,6 +105,11 @@ public class SheetDisplay extends Composite { ...@@ -105,6 +105,11 @@ public class SheetDisplay extends Composite {
@Autowired @Autowired
private ObjectMapper mapper; 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 { private static class ContentProvider implements IStructuredContentProvider {
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
...@@ -123,43 +128,38 @@ public class SheetDisplay extends Composite { ...@@ -123,43 +128,38 @@ public class SheetDisplay extends Composite {
} }
} }
private class TableLabelProvider extends CellLabelProvider { private class TableLabelProvider extends StyledCellLabelProvider {
@Override @Override
public void update(final ViewerCell cell) { public void update(final ViewerCell cell) {
final int columnIndex = cell.getColumnIndex(); final int columnIndex = cell.getColumnIndex();
final Object element = cell.getElement(); System.err.println("Update col " + columnIndex);
if (element instanceof Object[]) { final Object element = cell.getElement();
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];
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 selectedColumn = dsw.getSelectedColumn();
final Column currentColumn = dsw.getDataSourceSheet().getColumns().get(columnIndex); final Column currentColumn = dsw.getDataSourceSheet().getColumns().get(columnIndex);
if (currentColumn.getRdfTerm() != null && !currentColumn.getRdfTerm().isEmpty()) {
if (selectedColumn != null) { if (currentColumn.getRdfTerm() != null && !currentColumn.getRdfTerm().isEmpty()) {
if (selectedColumn.getPreferredName().equals(currentColumn.getPreferredName())) { if (currentColumn == selectedColumn) {
cell.setBackground(pinkColor); // pink cell.setBackground(pinkColor); // pink
} else { } else {
cell.setBackground(blueColor); // light blue cell.setBackground(blueColor); // light blue
} }
} else { } else {
cell.setBackground(blueColor); // light blue if (currentColumn == selectedColumn) {
} cell.setBackground(yellowColor); // yellow
} else { } else {
if (selectedColumn != null) { cell.setBackground(listBackgroundColor); // default
if (selectedColumn.getPreferredName().equals(currentColumn.getPreferredName())) { }
cell.setBackground(yellowColor); }
} }
} }
}
}
}
private Table table; private Table table;
private Text txtColumnName; private Text txtColumnName;
...@@ -635,12 +635,12 @@ public class SheetDisplay extends Composite { ...@@ -635,12 +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() { getDisplay().asyncExec(new Runnable() {
@Override @Override
public void run() { public void run() {
updateTable(); 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