swtbot: Fix time graph item bounds and menu detect event coordinates
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 20 Dec 2016 19:04:20 +0000 (14:04 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 27 Jan 2017 19:28:44 +0000 (14:28 -0500)
The method TimeGraphControl.getItemBounds(ITimeGraphEntry) should return
bounds relative to the item's parent, e.g. the time graph control, not
its parent.

The method SWTBotTimeGraphEntry.contextMenu(Control) should fire a
SWT.MenuDetect event where the coordinates are relative to the display.
The item should also be selected after firing the SWT.MenuDetect event
but before firing the SWT.Show menu event.

The method SWTBotTimeGraphEntry.select() should replace the selection
with the selected item, not add it to the selection. It should also fire
a SelectionEvent and a SelectionChangedEvent.

Change-Id: I5743af433c51b97255aafb0ce433d69069858e50
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/87498
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.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotTimeGraphEntry.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index 5a1d5319ccb6d5fca52b06778cb18275667a8845..98b68c447a24febbd4e8f7e806c5c4b534807fd0 100644 (file)
@@ -17,6 +17,7 @@ import java.util.List;
 
 import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Event;
@@ -64,15 +65,17 @@ public class SWTBotTimeGraphEntry extends AbstractSWTBotControl<TimeGraphControl
                 if (bounds == null) {
                     return;
                 }
+                Point location = widget.toDisplay(bounds.x, bounds.y);
                 final Event event = new Event();
                 event.time = (int) System.currentTimeMillis();
                 event.display = control.getDisplay();
                 event.widget = control;
-                event.x = bounds.x + widget.getTimeDataProvider().getNameSpace() / 2;
-                event.y = bounds.y + bounds.height / 2;
+                event.x = location.x + widget.getTimeDataProvider().getNameSpace() / 2;
+                event.y = location.y + bounds.height / 2;
                 control.notifyListeners(SWT.MenuDetect, event);
             }
         });
+        select();
 
         WaitForObjectCondition<Menu> waitForMenu = Conditions.waitForPopupMenu(control);
         new SWTBot().waitUntilWidgetAppears(waitForMenu);
@@ -157,7 +160,8 @@ public class SWTBotTimeGraphEntry extends AbstractSWTBotControl<TimeGraphControl
             @Override
             public void run() {
                 widget.setFocus();
-                widget.selectItem(fEntry, true);
+                widget.selectItem(fEntry, false);
+                widget.fireSelectionChanged();
             }
         });
         return this;
index 1696f658b88de3c2c555a1cfae9b0748e8f7afe4..7c8246352fc1cc2524b45004df5cc6e382b5c171 100644 (file)
@@ -1725,7 +1725,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
     }
 
     /**
-     * Get the bounds of the specified entry
+     * Get the bounds of the specified entry relative to its parent time graph.
      *
      * @param entry the time graph entry
      * @return the bounds of the entry, or null if the entry is not visible
@@ -1734,7 +1734,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
     public Rectangle getItemBounds(ITimeGraphEntry entry) {
         int idx = fItemData.findItemIndex(entry);
         if (idx >= 0) {
-            return getItemRect(getBounds(), idx);
+            return getItemRect(getClientArea(), idx);
         }
         return null;
     }
This page took 0.027433 seconds and 5 git commands to generate.