### Eclipse Workspace Patch 1.0
#P org.eclipse.jface
Index: src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java,v
retrieving revision 1.7
diff -u -r1.7 FocusCellOwnerDrawHighlighter.java
--- src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java 1 Feb 2008 15:18:01 -0000 1.7
+++ src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java 20 Feb 2008 15:07:40 -0000
@@ -34,6 +34,11 @@
*
*/
public class FocusCellOwnerDrawHighlighter extends FocusCellHighlighter {
+
+ private ColumnViewer viewer;
+ private Object item;
+ private int index;
+
/**
* Create a new instance which can be passed to a
* {@link TreeViewerFocusCellManager}
@@ -43,27 +48,28 @@
*/
public FocusCellOwnerDrawHighlighter(ColumnViewer viewer) {
super(viewer);
+ this.viewer = viewer;
hookListener(viewer);
}
private void markFocusedCell(Event event, ViewerCell cell) {
- Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell)
- : getSelectedCellBackgroundColorNoFocus(cell);
- Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell)
- : getSelectedCellForegroundColorNoFocus(cell);
+ Color background = cell.getItem().getDisplay().getSystemColor(
+ SWT.COLOR_LIST_SELECTION);
+ Color foreground = cell.getItem().getDisplay().getSystemColor(
+ SWT.COLOR_LIST_SELECTION_TEXT);
if (foreground != null || background != null || onlyTextHighlighting(cell)) {
GC gc = event.gc;
- if (background == null) {
- background = cell.getItem().getDisplay().getSystemColor(
- SWT.COLOR_LIST_SELECTION);
- }
-
- if (foreground == null) {
- foreground = cell.getItem().getDisplay().getSystemColor(
- SWT.COLOR_LIST_SELECTION_TEXT);
- }
+// if (background == null) {
+// background = cell.getItem().getDisplay().getSystemColor(
+// SWT.COLOR_LIST_SELECTION);
+// }
+//
+// if (foreground == null) {
+// foreground = cell.getItem().getDisplay().getSystemColor(
+// SWT.COLOR_LIST_SELECTION_TEXT);
+// }
gc.setBackground(background);
gc.setForeground(foreground);
@@ -84,11 +90,22 @@
}
private void removeSelectionInformation(Event event, ViewerCell cell) {
+ Color background = getSelectedCellBackgroundColor(cell);
+ Color foreground = getSelectedCellForegroundColor(cell);
+
+ if(background == null) {
+ background = cell.getViewerRow().getBackground(
+ cell.getColumnIndex());
+ }
+
+ if(foreground == null) {
+ foreground = cell.getViewerRow().getForeground(
+ cell.getColumnIndex());
+ }
+
GC gc = event.gc;
- gc.setBackground(cell.getViewerRow().getBackground(
- cell.getColumnIndex()));
- gc.setForeground(cell.getViewerRow().getForeground(
- cell.getColumnIndex()));
+ gc.setBackground(background);
+ gc.setForeground(foreground);
gc.fillRectangle(cell.getBounds());
event.detail &= ~SWT.SELECTED;
}
@@ -108,8 +125,16 @@
ViewerCell cell = row.getCell(event.index);
- if (focusCell == null || !cell.equals(focusCell)) {
+ /*
+ * removeSelectionInformation is used for selected cell,
+ * markFocusedCell is used for other cells
+ *
+ * Reason is to allow multiSelection but it needs at least
+ * adjust logic around colors.
+ */
+ if (cell.equals(focusCell)) {
removeSelectionInformation(event, cell);
+ notifyTraverseListeners(event);
} else {
markFocusedCell(event, cell);
}
@@ -119,6 +144,39 @@
};
viewer.getControl().addListener(SWT.EraseItem, listener);
}
+
+ /**
+ * Send event to viewer's control (SWT.Traverse) when selected cell is changed
+ * @param event event with details about item and index
+ *
+ * Snippet:
+ *
+ + table.addListener(SWT.MouseDown, listener); + table.addListener(SWT.Traverse, listener); + + Listener listener = new Listener() { + + public void handleEvent(Event event) { + if(event.item == null) return; + + TableItem item = (TableItem) event.item; + int column = event.index; + + Object element = item.getData(); + + //.. propagate element and column to other workbench parts ... + } + }; + *+ */ + protected void notifyTraverseListeners(Event event){ + if(event.index != index || event.item != item){ + index = event.index; + item = event.item; + viewer.getControl().notifyListeners(SWT.Traverse, event); + } + } /** * The color to use when rendering the background of the selected cell when