tmf: Bug 494810: SelectionEvent not sent after using vertical slider
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 31 May 2016 20:58:05 +0000 (16:58 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 2 Jun 2016 21:13:32 +0000 (17:13 -0400)
The vertical slider used by the TmfVirtualTable is created with the
SWT.NO_FOCUS style. In Linux-GTK, this hint is not respected and the
slider can gain focus. When this happens, give back the focus to the
table.

This allows the SelectionEvent to be sent when extending a selection
using Shift+Click in the event table after using the vertical slider.

Change-Id: I9a8d7083300a5c515c24110d5572d30b6bd9d7d6
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/74119
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/virtualtable/TmfVirtualTable.java

index 655fdbf84c73cd3fdecc7265117d7587ca2907b3..d878e7e5f0ee2508fb5259f2a7ee8ccffde7b7e0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson and others.
+ * Copyright (c) 2010, 2016 Ericsson and others.
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -20,6 +20,8 @@ import org.eclipse.swt.SWTException;
 import org.eclipse.swt.custom.TableEditor;
 import org.eclipse.swt.events.ControlAdapter;
 import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
 import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.KeyListener;
@@ -657,6 +659,16 @@ public class TmfVirtualTable extends Composite {
             }
         });
 
+        /*
+         * The SWT.NO_FOCUS style is only a hint and is not always respected. If
+         * the slider gains focus, give it back to the table.
+         */
+        fSlider.addFocusListener(new FocusAdapter() {
+            @Override
+            public void focusGained(FocusEvent e) {
+                fTable.setFocus();
+            }
+        });
     }
 
     // ------------------------------------------------------------------------
@@ -1074,12 +1086,31 @@ public class TmfVirtualTable extends Composite {
         }
         if (start <= end) {
             fTable.setSelection(start, end);
+            /* Reset origin in case partially visible item selected */
+            fTable.setTopIndex(0);
             if (startRank == fSelectedEventRank) {
                 fTable.select(start);
             } else {
                 fTable.select(end);
             }
         } else {
+            /*
+             * In GTK2, when the table is given focus, one table item is
+             * highlighted even if there is no selection. In that case the
+             * highlighted item is the last selected item. Make that last
+             * selected item the top or bottom item depending on if the
+             * out-of-range selection is above or below the visible items.
+             */
+            if (SWT.getPlatform().equals("gtk") && fTableRows > 0) { //$NON-NLS-1$
+                fTable.setRedraw(false);
+                if (start < Integer.MAX_VALUE) {
+                    fTable.setSelection(0);
+                } else {
+                    fTable.setSelection(fTableRows - 1);
+                    fTable.setTopIndex(0);
+                }
+                fTable.setRedraw(true);
+            }
             fTable.deselectAll();
         }
     }
This page took 0.028422 seconds and 5 git commands to generate.