tmf: Bug 499251: Call Stack view double-click listener no longer works
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 5 Aug 2016 18:52:15 +0000 (14:52 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Mon, 15 Aug 2016 11:51:45 +0000 (07:51 -0400)
The Call Stack view's time graph double-click listener is fixed to
handle the updated structured selection's content.

The class TimeGraphSelection is deprecated.

The spacing ratio added around the call stack event's range is removed.

Change-Id: I81d40aea54cd74b469cbcf3e119fde2db3b3b38f
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/78566
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/FindDialogTestBase.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphSelection.java

index 092d60160533c6423871a93e3f87c68ab2765d7c..aeb7b150f46b7f25e62da2191dda25d49f3ae3d7 100644 (file)
@@ -12,7 +12,6 @@ import static org.junit.Assert.assertTrue;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.SWTBot;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
@@ -39,7 +38,6 @@ import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphSelection;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.Test;
@@ -307,10 +305,8 @@ public abstract class FindDialogTestBase extends KernelTestBase {
     private static String getTimegraphSelectionName(final SWTBotView view) {
         final TimeGraphControl timegraph = view.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
         return UIThreadRunnable.syncExec(() -> {
-            ISelection selection = timegraph.getSelectionTrace();
-            if (selection instanceof TimeGraphSelection) {
-                TimeGraphSelection sel = (TimeGraphSelection) selection;
-                ITimeGraphEntry entry = (ITimeGraphEntry) sel.getFirstElement();
+            ITimeGraphEntry entry = timegraph.getSelectedTrace();
+            if (entry != null) {
                 return entry.getName();
             }
             return null;
index 749bc3ce672d821b99e8daa35811dd63025a8018..5d1efd58fb5d8a80ffb7d458a0a8429afa5b6c6d 100644 (file)
@@ -86,7 +86,6 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphSelection;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchActionConstants;
 
@@ -119,9 +118,6 @@ public class CallStackView extends AbstractTimeGraphView {
     /** Timeout between updates in the build thread in ms */
     private static final long BUILD_UPDATE_TIMEOUT = 500;
 
-    // Fraction of a function duration to be added as spacing
-    private static final double SPACING_RATIO = 0.01;
-
     private static final Image PROCESS_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/process_obj.gif"); //$NON-NLS-1$
     private static final Image THREAD_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/thread_obj.gif"); //$NON-NLS-1$
     private static final Image STACKFRAME_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/stckframe_obj.gif"); //$NON-NLS-1$
@@ -394,9 +390,6 @@ public class CallStackView extends AbstractTimeGraphView {
                     if (entry.getFunctionName().length() > 0) {
                         long entryTime = entry.getFunctionEntryTime();
                         long exitTime = entry.getFunctionExitTime();
-                        long spacingTime = (long) ((exitTime - entryTime) * SPACING_RATIO);
-                        entryTime -= spacingTime;
-                        exitTime += spacingTime;
                         TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(entryTime), TmfTimestamp.fromNanos(exitTime));
                         broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range));
                         getTimeGraphViewer().setStartFinishTime(entryTime, exitTime);
@@ -411,19 +404,18 @@ public class CallStackView extends AbstractTimeGraphView {
             public void mouseDoubleClick(MouseEvent e) {
                 TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
                 ISelection selection = timeGraphControl.getSelection();
-                if (selection instanceof TimeGraphSelection) {
-                    Object o = ((TimeGraphSelection) selection).getFirstElement();
-                    if (o instanceof CallStackEvent) {
-                        CallStackEvent event = (CallStackEvent) o;
-                        long startTime = event.getTime();
-                        long endTime = startTime + event.getDuration();
-                        long spacingTime = (long) ((endTime - startTime) * SPACING_RATIO);
-                        startTime -= spacingTime;
-                        endTime += spacingTime;
-                        TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
-                        broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range));
-                        getTimeGraphViewer().setStartFinishTime(startTime, endTime);
-                        startZoomThread(startTime, endTime);
+                if (selection instanceof IStructuredSelection) {
+                    for (Object object : ((IStructuredSelection) selection).toList()) {
+                        if (object instanceof CallStackEvent) {
+                            CallStackEvent event = (CallStackEvent) object;
+                            long startTime = event.getTime();
+                            long endTime = startTime + event.getDuration();
+                            TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
+                            broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range));
+                            getTimeGraphViewer().setStartFinishTime(startTime, endTime);
+                            startZoomThread(startTime, endTime);
+                            break;
+                        }
                     }
                 }
             }
index 4705e72d9181feeb6405d092ab70b8fb772f7a3c..e8cee6feb5c15d52336ed1dec26606b08ec76cbb 100644 (file)
@@ -41,7 +41,9 @@ import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
@@ -843,19 +845,25 @@ public class TimeGraphControl extends TimeGraphBaseControl
         return super.setFocus();
     }
 
+    /**
+     * Returns the current selection for this time graph. If a time graph entry
+     * is selected, it will be the first element in the selection. If a time
+     * event is selected, it will be the second element in the selection.
+     *
+     * @return the current selection
+     */
     @Override
     public ISelection getSelection() {
-        TimeGraphSelection sel = new TimeGraphSelection();
-        ITimeGraphEntry trace = getSelectedTrace();
-        if (null != trace && null != fTimeProvider) {
+        ITimeGraphEntry entry = getSelectedTrace();
+        if (null != entry && null != fTimeProvider) {
             long selectedTime = fTimeProvider.getSelectionBegin();
-            ITimeEvent event = Utils.findEvent(trace, selectedTime, 0);
-            sel.add(trace);
-            if (event != null) {
-                sel.add(event);
+            ITimeEvent event = Utils.findEvent(entry, selectedTime, 0);
+            if (event == null) {
+                return new StructuredSelection(entry);
             }
+            return new StructuredSelection(new Object[] { entry, event });
         }
-        return sel;
+        return StructuredSelection.EMPTY;
     }
 
     /**
@@ -864,12 +872,11 @@ public class TimeGraphControl extends TimeGraphBaseControl
      * @return The selection
      */
     public ISelection getSelectionTrace() {
-        TimeGraphSelection sel = new TimeGraphSelection();
-        ITimeGraphEntry trace = getSelectedTrace();
-        if (null != trace) {
-            sel.add(trace);
+        ITimeGraphEntry entry = getSelectedTrace();
+        if (null != entry) {
+            return new StructuredSelection(entry);
         }
-        return sel;
+        return StructuredSelection.EMPTY;
     }
 
     /**
@@ -3108,12 +3115,10 @@ public class TimeGraphControl extends TimeGraphBaseControl
 
     @Override
     public void setSelection(ISelection selection) {
-        if (selection instanceof TimeGraphSelection) {
-            TimeGraphSelection sel = (TimeGraphSelection) selection;
-            Object ob = sel.getFirstElement();
+        if (selection instanceof IStructuredSelection) {
+            Object ob = ((IStructuredSelection) selection).getFirstElement();
             if (ob instanceof ITimeGraphEntry) {
-                ITimeGraphEntry trace = (ITimeGraphEntry) ob;
-                selectItem(trace, false);
+                selectItem((ITimeGraphEntry) ob, false);
             }
         }
 
index cf849da50b9dbe39c69430a58cab3ad04ba7ba50..9df95df4618341f7097f5f446a14c7a0fe792bb4 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2007, 2014 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2016 Intel Corporation, Ericsson
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -19,6 +19,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
 
 /**
  * Selection object for the time graph scale
@@ -26,7 +27,9 @@ import org.eclipse.jface.viewers.IStructuredSelection;
  * @version 1.0
  * @author Alvaro Sanchez-Leon
  * @author Patrick Tasse
+ * @deprecated Use {@link StructuredSelection} instead.
  */
+@Deprecated
 public class TimeGraphSelection implements IStructuredSelection {
 
     private List<Object> list = new ArrayList<>();
This page took 0.034721 seconds and 5 git commands to generate.