From 84c8aef7ffc1a60afb1ecfd3d682b635c88e3fd9 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Thu, 5 Nov 2015 10:43:41 -0500 Subject: [PATCH] tmf: Support adjustment of time graph window range on range selection 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 Reviewed-on: https://git.eclipse.org/r/59758 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../tmf/ui/views/callstack/CallStackView.java | 4 +- .../tmf/ui/views/timechart/TimeChartView.java | 6 +- .../timegraph/AbstractTimeGraphView.java | 4 +- .../ui/widgets/timegraph/TimeGraphViewer.java | 64 +++++++-------- .../timegraph/widgets/ITimeDataProvider.java | 77 +++++++++++++------ .../TimeDataProviderCyclesConverter.java | 16 ++-- .../timegraph/widgets/TimeGraphControl.java | 10 +-- 7 files changed, 105 insertions(+), 76 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java index 2f9ec2ce6a..f6ad3e3c23 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/callstack/CallStackView.java @@ -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); diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timechart/TimeChartView.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timechart/TimeChartView.java index beb9367faa..9c8a4280ee 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timechart/TimeChartView.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timechart/TimeChartView.java @@ -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); } } }); diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java index 9b5e99ed8f..68e98e4263 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java @@ -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) { diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java index 79c3453591..6853d25cf2 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -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; } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java index b6b170fbd0..e83509f2ea 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java @@ -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). + *

+ * 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. + *

+ * 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). + *

+ * 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. + *

+ * 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 { *

  • {@link TimeFormat#CALENDAR} absolute time, displayed as year/month/day/hours/minutes/seconds/ms/us/ns *
  • {@link TimeFormat#RELATIVE} relative time, displayed as seconds/ms/us/ns *
  • {@link TimeFormat#NUMBER} number, displayed as long values. + *
  • {@link TimeFormat#CYCLES} cycles, displayed as long values. * */ TimeFormat getTimeFormat(); diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeDataProviderCyclesConverter.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeDataProviderCyclesConverter.java index d120e5495f..624ff358d8 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeDataProviderCyclesConverter.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeDataProviderCyclesConverter.java @@ -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 diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java index b2edddd4fe..681f842cfe 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -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(); -- 2.34.1