tmf: Support adjustment of time graph window range on range selection
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 5 Nov 2015 15:43:41 +0000 (10:43 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 9 Nov 2015 20:00:47 +0000 (15:00 -0500)
When the selection range is modified and 'ensureVisible' is true, then
the window range will be centered on either the selection begin time (if
it has changed) otherwise on the selection end time, if that time is
outside of the current window.

This adjustment is now enabled in time graph views when the
TmfSelectionRangeUpdatedSignal is received.

Change-Id: I8b5ec885b00009be05222db02acd745218759131
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/59758
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
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/views/timechart/TimeChartView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeDataProviderCyclesConverter.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index 2f9ec2ce6accd1eeef29474290721003f08f7d87..f6ad3e3c23939f2cf87d641677970301facfd3fe 100644 (file)
@@ -699,7 +699,7 @@ public class CallStackView extends TmfView implements ITmfTimeAligned {
                 if (beginTime == endTime) {
                     fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(beginTime, true);
                 } else {
-                    fTimeGraphCombo.getTimeGraphViewer().setSelectionRange(beginTime, endTime);
+                    fTimeGraphCombo.getTimeGraphViewer().setSelectionRange(beginTime, endTime, true);
                 }
                 synchingToTime(beginTime);
                 startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1());
@@ -1069,7 +1069,7 @@ public class CallStackView extends TmfView implements ITmfTimeAligned {
                 long endTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
                 startTime = (fStartTime == SWT.DEFAULT ? SWT.DEFAULT : Math.max(startTime, fStartTime));
                 endTime = (fEndTime == SWT.DEFAULT ? SWT.DEFAULT : Math.min(endTime, fEndTime));
-                fTimeGraphCombo.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime);
+                fTimeGraphCombo.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime, false);
                 synchingToTime(selectionBeginTime);
                 fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
                 startZoomThread(startTime, endTime);
index beb9367faaa176b9c4774e789e6f6ac9f6e01a14..9c8a4280ee55ce70e9a6d75c34f5d58b22e10508 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -647,7 +647,7 @@ public class TimeChartView extends TmfView implements ITimeGraphRangeListener, I
             TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
             long beginTime = ctx.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
             long endTime = ctx.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-            fViewer.setSelectionRange(beginTime, endTime);
+            fViewer.setSelectionRange(beginTime, endTime, false);
         }
     }
 
@@ -691,7 +691,7 @@ public class TimeChartView extends TmfView implements ITimeGraphRangeListener, I
                         itemize(fStartTime, fStopTime);
                     }
                 } else {
-                    fViewer.setSelectionRange(beginTime, endTime);
+                    fViewer.setSelectionRange(beginTime, endTime, true);
                 }
             }
         });
index 9b5e99ed8f2467a094f16b91ba3c2b2583b7ee46..68e98e42636b83c307cd8bd1171edf312572d255 100644 (file)
@@ -1288,7 +1288,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                 if (beginTime == endTime) {
                     fTimeGraphWrapper.getTimeGraphViewer().setSelectedTime(beginTime, true);
                 } else {
-                    fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(beginTime, endTime);
+                    fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(beginTime, endTime, true);
                 }
                 synchingToTime(fTimeGraphWrapper.getTimeGraphViewer().getTime0());
             }
@@ -1597,7 +1597,7 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                 long endTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
                 startTime = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : Math.max(startTime, fStartTime));
                 endTime = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : Math.min(endTime, fEndTime));
-                fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime);
+                fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime, false);
                 fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime);
 
                 if (fTimeGraphWrapper instanceof TimeGraphComboWrapper && !fPackDone) {
index 79c3453591c50ac66636ba697784aec2609120b5..6853d25cf279444b065deb1ce284a54d66f20cad 100644 (file)
@@ -922,60 +922,52 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         setSelectedTimeInt(time, ensureVisible, false);
     }
 
+    private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
+        setSelectionRangeInt(time, time, ensureVisible, doNotify);
+    }
+
+    /**
+     * @since 2.0
+     */
     @Override
-    public void setSelectionRangeNotify(long beginTime, long endTime) {
-        long time0 = fTime0;
-        long time1 = fTime1;
-        long selectionBegin = fSelectionBegin;
-        long selectionEnd = fSelectionEnd;
-        fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
-        fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
-        boolean changed = (selectionBegin != fSelectionBegin || selectionEnd != fSelectionEnd);
-        ensureVisible(fSelectionEnd);
-        fTimeGraphCtrl.redraw();
-        fTimeScaleCtrl.redraw();
-        updateMarkerActions();
-        if ((time0 != fTime0) || (time1 != fTime1)) {
-            notifyRangeListeners();
-        }
-        if (changed) {
-            notifyTimeListeners();
-        }
+    public void setSelectionRangeNotify(long beginTime, long endTime, boolean ensureVisible) {
+        setSelectionRangeInt(beginTime, endTime, ensureVisible, true);
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public void setSelectionRange(long beginTime, long endTime) {
+    public void setSelectionRange(long beginTime, long endTime, boolean ensureVisible) {
         /* if there is a pending time selection, ignore this one */
         if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) {
             return;
         }
-        fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
-        fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
-        fTimeGraphCtrl.redraw();
-        fTimeScaleCtrl.redraw();
-        updateMarkerActions();
+        setSelectionRangeInt(beginTime, endTime, ensureVisible, false);
     }
 
-    private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
-        long selection = Math.max(fTime0Bound, Math.min(fTime1Bound, time));
+    private void setSelectionRangeInt(long beginTime, long endTime, boolean ensureVisible, boolean doNotify) {
         long time0 = fTime0;
         long time1 = fTime1;
+        long selectionBegin = fSelectionBegin;
+        long selectionEnd = fSelectionEnd;
+        fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
+        fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
+        boolean changed = (selectionBegin != fSelectionBegin || selectionEnd != fSelectionEnd);
+
         if (ensureVisible) {
-            ensureVisible(selection);
+            ensureVisible(selectionBegin != fSelectionBegin ? fSelectionBegin : fSelectionEnd);
         }
+
         fTimeGraphCtrl.redraw();
         fTimeScaleCtrl.redraw();
-
-        boolean notifySelectedTime = (selection != fSelectionBegin || selection != fSelectionEnd);
-        fSelectionBegin = selection;
-        fSelectionEnd = selection;
         updateMarkerActions();
 
         if ((time0 != fTime0) || (time1 != fTime1)) {
             notifyRangeListeners();
         }
 
-        if (doNotify && notifySelectedTime) {
+        if (doNotify && changed) {
             notifyTimeListeners();
         }
     }
@@ -2255,7 +2247,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             if ((marker.getTime() > time ||
                     (marker.getTime() == time && marker.getDuration() > duration))
                     && !fSkippedMarkerCategories.contains(marker.getCategory())) {
-                setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration());
+                setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration(), true);
                 fTimeGraphCtrl.updateStatusLine();
                 return;
             }
@@ -2278,7 +2270,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             if ((marker.getTime() < time ||
                     (marker.getTime() == time && marker.getDuration() < duration))
                     && !fSkippedMarkerCategories.contains(marker.getCategory())) {
-                setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration());
+                setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration(), true);
                 fTimeGraphCtrl.updateStatusLine();
                 return;
             }
@@ -2302,7 +2294,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             }
         }
         if (nextMarker != null) {
-            setSelectionRangeNotify(fSelectionBegin, nextMarker.getTime() + nextMarker.getDuration());
+            setSelectionRangeNotify(fSelectionBegin, nextMarker.getTime() + nextMarker.getDuration(), true);
             fTimeGraphCtrl.updateStatusLine();
         }
     }
@@ -2319,7 +2311,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             IMarkerEvent marker = markers.get(i);
             if (marker.getTime() < fSelectionEnd
                     && !fSkippedMarkerCategories.contains(marker.getCategory())) {
-                setSelectionRangeNotify(fSelectionBegin, marker.getTime());
+                setSelectionRangeNotify(fSelectionBegin, marker.getTime(), true);
                 fTimeGraphCtrl.updateStatusLine();
                 return;
             }
index b6b170fbd02bf62964964e31a29d659a7d6da5d2..e83509f2eae507c44ac73023303e92def44c2b68 100644 (file)
@@ -28,21 +28,41 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeForma
 public interface ITimeDataProvider {
 
     /**
-     * Updates the selection begin and end time and notifies any registered
-     * listeners about the new time range (if necessary)
+     * Updates the selection begin and end time and notifies the selection
+     * listeners about the new selection range (if it has changed).
+     * <p>
+     * If ensureVisible is true, the window range will be centered either on the
+     * selection begin time (if it has changed) or otherwise on the selection
+     * end time, if and only if that time is outside of the current window. If
+     * the window range is modified, the range listeners will be notified.
      *
-     * @param beginTime the selection begin time
-     * @param endTime the selection end time
+     * @param beginTime
+     *            the selection begin time
+     * @param endTime
+     *            the selection end time
+     * @param ensureVisible
+     *            if true, ensure visibility of the new selection range boundary
+     * @since 2.0
      */
-    void setSelectionRangeNotify(long beginTime, long endTime);
+    void setSelectionRangeNotify(long beginTime, long endTime, boolean ensureVisible);
 
     /**
-     * Updates the selection begin and end time
+     * Updates the selection begin and end time.
+     * <p>
+     * If ensureVisible is true, the window range will be centered either on the
+     * selection begin time (if it has changed) or otherwise on the selection
+     * end time, if and only if that time is outside of the current window. If
+     * the window range is modified, the range listeners will be notified.
      *
-     * @param beginTime the selection begin time
-     * @param endTime the selection end time
+     * @param beginTime
+     *            the selection begin time
+     * @param endTime
+     *            the selection end time
+     * @param ensureVisible
+     *            if true, ensure visibility of the new selection range boundary
+     * @since 2.0
      */
-    void setSelectionRange(long beginTime, long endTime);
+    void setSelectionRange(long beginTime, long endTime, boolean ensureVisible);
 
     /**
      * @return The begin time of the current selection
@@ -96,48 +116,58 @@ public interface ITimeDataProvider {
     long getMinTimeInterval();
 
     /**
-     * Updates the time range and notify registered listeners
+     * Updates the window range and notify the range listeners.
      *
      * @param time0
+     *            the window start time
      * @param time1
+     *            the window end time
      */
     void setStartFinishTimeNotify(long time0, long time1);
 
     /**
-     * Update the time range but do not trigger event notification
+     * Update the window range but do not notify the range listeners.
      *
      * @param time0
+     *            the window start time
      * @param time1
+     *            the window end time
      */
     void setStartFinishTime(long time0, long time1);
 
     /**
-     * Notify registered listeners without updating the time range
+     * Notify the range listeners without updating the time range.
      */
     void notifyStartFinishTime();
 
     /**
-     * Updates the selected time, adjusts the time range if necessary and
-     * notifies any registered listeners about the new selected time and new
-     * range (if necessary)
+     * Updates the selection time and notifies the selection listeners about the
+     * new selection time (if it has changed).
+     * <p>
+     * If ensureVisible is true, the window range will be centered on the
+     * selection time, if and only if that time is outside of the current
+     * window. If the window range is modified, the range listeners will be
+     * notified.
      *
      * @param time
-     *            A Time to set
+     *            the selection time
      * @param ensureVisible
-     *            Ensure visibility of new time (will adjust time range if
-     *            necessary)
+     *            if true, ensure visibility of the new selection time
      */
     void setSelectedTimeNotify(long time, boolean ensureVisible);
 
     /**
-     * Updates the selected time and adjusts the time range if necessary without
-     * notifying registered listeners.
+     * Updates the selection time.
+     * <p>
+     * If ensureVisible is true, the window range will be centered on the
+     * selection time, if and only if that time is outside of the current
+     * window. If the window range is modified, the range listeners will be
+     * notified.
      *
      * @param time
-     *            A Time to set
+     *            the selection time
      * @param ensureVisible
-     *            Ensure visibility of new time (will adjust time range if
-     *            necessary)
+     *            if true, ensure visibility of the new selection time
      */
     void setSelectedTime(long time, boolean ensureVisible);
 
@@ -169,6 +199,7 @@ public interface ITimeDataProvider {
      *   <li>{@link TimeFormat#CALENDAR} absolute time, displayed as year/month/day/hours/minutes/seconds/ms/us/ns
      *   <li>{@link TimeFormat#RELATIVE} relative time, displayed as seconds/ms/us/ns
      *   <li>{@link TimeFormat#NUMBER}   number, displayed as long values.
+     *   <li>{@link TimeFormat#CYCLES}   cycles, displayed as long values.
      * </ul>
      */
     TimeFormat getTimeFormat();
index d120e5495f1c2f939860173c866c7158d95db797..624ff358d8d60b97aaa3ad0298aae536053d6f07 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -67,14 +67,20 @@ public class TimeDataProviderCyclesConverter implements ITimeDataProviderConvert
         return toCycles(time);
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public void setSelectionRangeNotify(long beginTime, long endTime) {
-        fProvider.setSelectionRangeNotify(toNanos(beginTime), toNanos(endTime));
+    public void setSelectionRangeNotify(long beginTime, long endTime, boolean ensureVisible) {
+        fProvider.setSelectionRangeNotify(toNanos(beginTime), toNanos(endTime), ensureVisible);
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public void setSelectionRange(long beginTime, long endTime) {
-        fProvider.setSelectionRange(toNanos(beginTime), toNanos(endTime));
+    public void setSelectionRange(long beginTime, long endTime, boolean ensureVisible) {
+        fProvider.setSelectionRange(toNanos(beginTime), toNanos(endTime), ensureVisible);
     }
 
     @Override
index b2edddd4fe208e821a42cccf0e2128a0e7ffea05..681f842cfe9559f99f691c04dbc64b760d656540 100644 (file)
@@ -788,14 +788,14 @@ public class TimeGraphControl extends TimeGraphBaseControl
                 nextTime = nextEvent.getTime() + nextEvent.getDuration();
             }
             if (extend) {
-                fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), nextTime);
+                fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), nextTime, true);
             } else {
                 fTimeProvider.setSelectedTimeNotify(nextTime, true);
             }
             fireSelectionChanged();
         } else if (n == 1) {
             if (extend) {
-                fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), endTime);
+                fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), endTime, true);
             } else {
                 fTimeProvider.setSelectedTimeNotify(endTime, true);
             }
@@ -1069,7 +1069,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
                 selectItem(link.getDestinationEntry(), false);
                 if (link.getDuration() != 0) {
                     if (extend) {
-                        fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime() + link.getDuration());
+                        fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime() + link.getDuration(), true);
                     } else {
                         fTimeProvider.setSelectedTimeNotify(link.getTime() + link.getDuration(), true);
                     }
@@ -1102,7 +1102,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
                 selectItem(link.getEntry(), false);
                 if (link.getDuration() != 0) {
                     if (extend) {
-                        fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime());
+                        fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime(), true);
                     } else {
                         fTimeProvider.setSelectedTimeNotify(link.getTime(), true);
                     }
@@ -2506,7 +2506,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
                 } else {
                     long time0 = fDragBeginMarker ? getTimeAtX(fDragX0) : fDragTime0;
                     long time1 = fDragBeginMarker ? fDragTime0 : getTimeAtX(fDragX);
-                    fTimeProvider.setSelectionRangeNotify(time0, time1);
+                    fTimeProvider.setSelectionRangeNotify(time0, time1, false);
                 }
                 fDragState = DRAG_NONE;
                 redraw();
This page took 0.033844 seconds and 5 git commands to generate.