fixed display glitches in table value view
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 26 Aug 2016 11:16:38 +0000 (14:16 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 26 Aug 2016 11:16:38 +0000 (14:16 +0300)
src/java/netxms-eclipse/PerfView/src/org/netxms/ui/eclipse/perfview/widgets/helpers/CellSelectionHighlighter.java
src/java/netxms-eclipse/PerfView/src/org/netxms/ui/eclipse/perfview/widgets/helpers/CellSelectionManager.java
webui/webapp/Core/theme/classic.css
webui/webapp/PerfView/src/org/netxms/ui/eclipse/perfview/widgets/TableValue.java
webui/webapp/PerfView/src/org/netxms/ui/eclipse/perfview/widgets/helpers/CellSelectionHighlighter.java
webui/webapp/PerfView/src/org/netxms/ui/eclipse/perfview/widgets/helpers/CellSelectionManager.java

index 948a29d..03cb3bf 100644 (file)
@@ -1,5 +1,20 @@
 /**
- * 
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 package org.netxms.ui.eclipse.perfview.widgets.helpers;
 
@@ -28,6 +43,7 @@ public class CellSelectionHighlighter
        {
                this.viewer = viewer;
                this.manager = manager;
+
                viewer.getControl().addListener(SWT.PaintItem, new Listener() {
                        public void handleEvent(Event event)
                        {
@@ -37,21 +53,19 @@ public class CellSelectionHighlighter
 
                                if (cell.equals(focusCell))
                                        markFocusedCell(event, cell);
+            event.gc.setForeground(cell.getControl().getDisplay().getSystemColor(CellSelectionHighlighter.this.manager.isCellSelected(cell) ? SWT.COLOR_LIST_SELECTION_TEXT : SWT.COLOR_LIST_FOREGROUND));
                                
                                event.detail &= ~SWT.FOCUSED;
                        }
                });
-               
+
                viewer.getControl().addListener(SWT.EraseItem, new Listener() {
                        @Override
                        public void handleEvent(Event event)
                        {
                                ViewerRow row = CellSelectionHighlighter.this.viewer.getViewerRowFromItem(event.item);
                                ViewerCell cell = row.getCell(event.index);
-
-                               if (CellSelectionHighlighter.this.manager.isCellSelected(cell))
-                                       markSelectedCell(event, cell);
-
+                               drawCellBackground(event, cell, CellSelectionHighlighter.this.manager.isCellSelected(cell));
                                event.detail &= ~(SWT.SELECTED | SWT.FOCUSED | SWT.HOT);
                        }
                });
@@ -68,12 +82,12 @@ public class CellSelectionHighlighter
         * @param event
         * @param cell
         */
-       private void markSelectedCell(Event event, ViewerCell cell)
+       private void drawCellBackground(Event event, ViewerCell cell, boolean selected)
        {
                GC gc = event.gc;
                Display display = cell.getControl().getDisplay();
-               gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
-               gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
+               gc.setBackground(display.getSystemColor(selected ? SWT.COLOR_LIST_SELECTION : SWT.COLOR_LIST_BACKGROUND));
+               gc.setForeground(display.getSystemColor(selected ? SWT.COLOR_LIST_SELECTION_TEXT : SWT.COLOR_LIST_FOREGROUND));
                gc.fillRectangle(cell.getBounds());
        }
 
index 65f4bae..1fcb461 100644 (file)
@@ -1,5 +1,20 @@
 /**
- * 
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 package org.netxms.ui.eclipse.perfview.widgets.helpers;
 
@@ -20,6 +35,7 @@ import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
 import org.netxms.ui.eclipse.widgets.SortableTableViewer;
 
 /**
@@ -63,6 +79,10 @@ public class CellSelectionManager
                        {
                                setFocusCell(cell, (event.stateMask & SWT.CTRL) == 0);
                        }
+                       else if ((event.stateMask & SWT.CTRL) != 0)
+                       {
+            setFocusCell(cell, false);
+                       }
                }
        }
 
@@ -224,8 +244,47 @@ public class CellSelectionManager
        void setFocusCell(ViewerCell focusCell, boolean clearSelection)
        {
                if (clearSelection)
+               {
                        selectedCells.clear();
-               selectedCells.add(focusCell);
+                       viewer.getTable().deselectAll();
+                       if (focusCell != null)
+                       {
+            selectedCells.add(focusCell);
+            viewer.getTable().select(viewer.getTable().indexOf((TableItem)focusCell.getViewerRow().getItem()));
+                       }
+               }
+               else if (focusCell != null)
+               {
+                  if (selectedCells.contains(focusCell))
+                  {
+                     selectedCells.remove(focusCell);
+                     ViewerRow row = focusCell.getViewerRow();
+                     boolean removeRowSelection = true;
+                     for(ViewerCell c : selectedCells)
+                     {
+                        if (row.equals(c.getViewerRow()))
+                        {
+                           // other cells selected in same row
+                           removeRowSelection = false;
+                           break;
+                        }
+                     }
+                     if (removeRowSelection)
+                     {
+                        viewer.getTable().deselect(viewer.getTable().indexOf((TableItem)row.getItem()));
+                     }
+                     else
+                     {
+                        // keep selection
+               viewer.getTable().select(viewer.getTable().indexOf((TableItem)row.getItem()));
+                     }
+                  }
+                  else
+                  {
+                     selectedCells.add(focusCell);
+                viewer.getTable().select(viewer.getTable().indexOf((TableItem)focusCell.getViewerRow().getItem()));
+                  }
+               }
                
                ViewerCell oldCell = this.focusCell;
 
index dd807c9..0b1602f 100644 (file)
@@ -985,6 +985,22 @@ Table-Checkbox:checked:grayed:hover {
   background-image: url( theme/classic.resources/button/check-grayed-hover.png );
 }
 
+/* Table with individual cell selection */
+Table-RowOverlay.cellselect:hover {
+  background-color: transparent;
+  color: inherit;
+}
+
+Table-RowOverlay.cellselect:selected {
+  background-color: transparent;
+  color: inherit;
+}
+
+Table-RowOverlay.cellselect:selected:unfocused {
+  background-color: transparent;
+  color: inherit;
+}
+
 /* Text default theme */
 
 Text {
index ee7ebbf..09842dd 100644 (file)
@@ -34,6 +34,7 @@ import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.jface.viewers.ViewerRow;
+import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CLabel;
 import org.eclipse.swt.events.DisposeEvent;
@@ -43,6 +44,7 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPage;
@@ -105,6 +107,8 @@ public class TableValue extends Composite
       setLayout(new FormLayout());
 
       viewer = new SortableTableViewer(this, SWT.FULL_SELECTION | SWT.MULTI);
+      viewer.getTable().setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
+      viewer.getTable().setData(RWT.CUSTOM_VARIANT, "cellselect");
       viewer.setContentProvider(new TableContentProvider());
       labelProvider = new TableLabelProvider();
       viewer.setLabelProvider(labelProvider);
@@ -332,6 +336,11 @@ public class TableValue extends Composite
       
       labelProvider.setColumns(table.getColumns());
       viewer.setInput(table);
+      
+      // FIXME: workaround for Eclipse RAP bug #324721 (Items should inherit custom variants) 
+      for(TableItem i : viewer.getTable().getItems())
+         i.setData(RWT.CUSTOM_VARIANT, "cellselect");
+      
       currentData = table;
    }
 
index bd36e58..f959d38 100644 (file)
@@ -38,7 +38,8 @@ public class CellSelectionHighlighter
                if (cell.getItem().getData(key) == null)
                {
                        cell.getItem().setData(key, cell.getText());
-                       cell.setText("<b><span style='color:rgb(255,201,14)'>" + cell.getText() + "</span></b>");
+                       // FIXME: read colors from current theme
+                       cell.setText("<span style='color:white;background-color: #00589f;'>" + cell.getText() + "</span>");
                }
        }
        
@@ -47,7 +48,7 @@ public class CellSelectionHighlighter
         */
        protected void unmarkCell(ViewerCell cell)
        {
-               if (cell == null)
+               if ((cell == null) || cell.getItem().isDisposed())
                        return;
                
                final String key = "CELL#" + cell.getColumnIndex();
index d9ebaf7..ade13df 100644 (file)
@@ -63,6 +63,10 @@ public class CellSelectionManager
                        {
                                setFocusCell(cell, (event.stateMask & SWT.CTRL) == 0);
                        }
+                       else if ((event.stateMask & SWT.CTRL) != 0)
+         {
+            setFocusCell(cell, false);
+         }
                }
        }
 
@@ -228,9 +232,25 @@ public class CellSelectionManager
                        for(ViewerCell cell : selectedCells)
                                cellHighlighter.unmarkCell(cell);
                        selectedCells.clear();
+                       if (focusCell != null)
+                       {
+                     selectedCells.add(focusCell);
+                     cellHighlighter.markCell(focusCell);
+                       }
                }
-               selectedCells.add(focusCell);
-               cellHighlighter.markCell(focusCell);
+      else if (focusCell != null)
+      {
+         if (selectedCells.contains(focusCell))
+         {
+            selectedCells.remove(focusCell);
+            cellHighlighter.unmarkCell(focusCell);
+         }
+         else
+         {
+            selectedCells.add(focusCell);
+            cellHighlighter.markCell(focusCell);
+         }
+      }
                
                ViewerCell oldCell = this.focusCell;