From: Patrick Tasse Date: Fri, 20 Feb 2015 15:39:25 +0000 (-0500) Subject: tmf: Fix time graph bounds reset on refresh and ignoring child entries X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=50d36521f4fbaf9d637d12f30b64dd6b6a746c7c;p=deliverable%2Ftracecompass.git tmf: Fix time graph bounds reset on refresh and ignoring child entries Calling refresh() or setInput() should not reset the bounds if they have been set to specific values by the user. When determining bounds based on the input time graph entries, only the root entries were considered. All roots and their recursive children should be considered. The value SWT.DEFAULT can now be used as a time bound to indicate that the bound should be set according to the input time graph entries. For any other value the bound will be fixed and unaffected by the input. This setting can be applied independently for each bound. The distinction between user-specified and actual bounds is made clearer in the API Javadoc. Change-Id: Ia79d35d41ed08cf7475807f9d352b1931196e5d5 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/42330 Reviewed-by: Hudson CI Reviewed-by: Alexandre Montplaisir Tested-by: Alexandre Montplaisir --- diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java index bbed6adeba..aaf19d6092 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -85,16 +85,16 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { private long fMinTimeInterval; private ITimeGraphEntry fSelectedEntry; - private long fBeginTime; - private long fEndTime; - private long fTime0; - private long fTime1; - private long fSelectionBegin = 0; - private long fSelectionEnd = 0; - private long fTime0Bound; - private long fTime1Bound; - private long fTime0ExtSynch = 0; - private long fTime1ExtSynch = 0; + private long fBeginTime = SWT.DEFAULT; // The user-specified bounds start time + private long fEndTime = SWT.DEFAULT; // The user-specified bounds end time + private long fTime0 = SWT.DEFAULT; // The current window start time + private long fTime1 = SWT.DEFAULT; // The current window end time + private long fSelectionBegin = SWT.DEFAULT; + private long fSelectionEnd = SWT.DEFAULT; + private long fTime0Bound = SWT.DEFAULT; // The bounds start time + private long fTime1Bound = SWT.DEFAULT; // The bounds end time + private long fTime0ExtSynch = SWT.DEFAULT; + private long fTime1ExtSynch = SWT.DEFAULT; private boolean fTimeRangeFixed; private int fNameWidthPref = DEFAULT_NAME_WIDTH; private int fMinNameWidth = MIN_NAME_WIDTH; @@ -271,8 +271,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { if (fTimeGraphCtrl != null) { setTimeRange(input); setTopIndex(0); - fSelectionBegin = 0; - fSelectionEnd = 0; + fSelectionBegin = SWT.DEFAULT; + fSelectionEnd = SWT.DEFAULT; fSelectedEntry = null; refreshAllData(input); } @@ -330,34 +330,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { resizeControls(); } - /** - * Handler for when the model is updated. Called from the display order in - * the API - * - * @param traces - * The traces in the model - * @param start - * The start time - * @param end - * The end time - * @param updateTimeBounds - * Should we updated the time bounds too - */ - public void modelUpdate(ITimeGraphEntry[] traces, long start, - long end, boolean updateTimeBounds) { - if (null != fTimeGraphCtrl) { - updateInternalData(traces, start, end); - if (updateTimeBounds) { - fTimeRangeFixed = true; - // set window to match limits - setStartFinishTime(fTime0Bound, fTime1Bound); - } else { - fTimeGraphCtrl.redraw(); - fTimeScaleCtrl.redraw(); - } - } - } - /** * @return The string representing the view type */ @@ -375,8 +347,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { void loadOptions() { fMinTimeInterval = 1; - fSelectionBegin = -1; - fSelectionEnd = -1; + fSelectionBegin = SWT.DEFAULT; + fSelectionEnd = SWT.DEFAULT; fNameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$ fNameWidthPref, fMinNameWidth, MAX_NAME_WIDTH); } @@ -553,40 +525,73 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } /** - * Try to set most convenient time range for display. + * Recalculate the time bounds based on the time graph entries, + * if the user-specified bound is set to SWT.DEFAULT. * - * @param traces - * The traces in the model - */ - public void setTimeRange(ITimeGraphEntry traces[]) { - fEndTime = 0; - fBeginTime = -1; - for (int i = 0; i < traces.length; i++) { - ITimeGraphEntry entry = traces[i]; - if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) { - if (fBeginTime < 0 || entry.getStartTime() < fBeginTime) { - fBeginTime = entry.getStartTime(); - } - if (entry.getEndTime() > fEndTime) { - fEndTime = entry.getEndTime(); - } + * @param entries + * The root time graph entries in the model + */ + public void setTimeRange(ITimeGraphEntry entries[]) { + fTime0Bound = (fBeginTime != SWT.DEFAULT ? fBeginTime : fEndTime); + fTime1Bound = (fEndTime != SWT.DEFAULT ? fEndTime : fBeginTime); + if (fBeginTime != SWT.DEFAULT && fEndTime != SWT.DEFAULT) { + return; + } + if (entries == null || entries.length == 0) { + return; + } + if (fTime0Bound == SWT.DEFAULT) { + fTime0Bound = Long.MAX_VALUE; + } + if (fTime1Bound == SWT.DEFAULT) { + fTime1Bound = Long.MIN_VALUE; + } + for (ITimeGraphEntry entry : entries) { + setTimeRange(entry); + } + } + + private void setTimeRange(ITimeGraphEntry entry) { + if (fBeginTime == SWT.DEFAULT && entry.hasTimeEvents() && entry.getStartTime() != SWT.DEFAULT) { + fTime0Bound = Math.min(entry.getStartTime(), fTime0Bound); + } + if (fEndTime == SWT.DEFAULT && entry.hasTimeEvents() && entry.getEndTime() != SWT.DEFAULT) { + fTime1Bound = Math.max(entry.getEndTime(), fTime1Bound); + } + if (entry.hasChildren()) { + for (ITimeGraphEntry child : entry.getChildren()) { + setTimeRange(child); } } + } - if (fBeginTime < 0) { - fBeginTime = 0; + /** + * Set the time bounds to the provided values. + * + * @param beginTime + * The bounds begin time, or SWT.DEFAULT to use the input bounds + * @param endTime + * The bounds end time, or SWT.DEFAULT to use the input bounds + */ + public void setTimeBounds(long beginTime, long endTime) { + fBeginTime = beginTime; + fEndTime = endTime; + fTime0Bound = (fBeginTime != SWT.DEFAULT ? fBeginTime : fEndTime); + fTime1Bound = (fEndTime != SWT.DEFAULT ? fEndTime : fBeginTime); + if (fTime0Bound > fTime1Bound) { + // only possible if both are not default + fBeginTime = endTime; + fEndTime = beginTime; + fTime0Bound = fBeginTime; + fTime1Bound = fEndTime; } + adjustHorizontalScrollBar(); } /** - * Recalculate the time bounds + * Recalculate the current time window when bounds have changed. */ public void setTimeBounds() { - fTime0Bound = fBeginTime; - if (fTime0Bound < 0) { - fTime0Bound = 0; - } - fTime1Bound = fEndTime; if (!fTimeRangeFixed) { fTime0 = fTime0Bound; fTime1 = fTime1Bound; @@ -598,29 +603,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } } - /** - * @param traces - * @param start - * @param end - */ - void updateInternalData(ITimeGraphEntry[] traces, long start, long end) { - ITimeGraphEntry[] realTraces = traces; - - if (null == realTraces) { - realTraces = new ITimeGraphEntry[0]; - } - if ((start == 0 && end == 0) || start < 0 || end < 0) { - // Start and end time are unspecified and need to be determined from - // individual processes - setTimeRange(realTraces); - } else { - fBeginTime = start; - fEndTime = end; - } - - refreshAllData(realTraces); - } - /** * @param traces */ @@ -789,29 +771,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { fTimeScaleCtrl.redraw(); } - /** - * Set the time bounds to the provided values - * - * @param beginTime - * The start time of the window - * @param endTime - * The end time - */ - public void setTimeBounds(long beginTime, long endTime) { - if (endTime >= beginTime) { - fBeginTime = beginTime; - fEndTime = endTime; - fTime0Bound = beginTime; - fTime1Bound = endTime; - } else { - fBeginTime = 0; - fEndTime = 0; - fTime0Bound = 0; - fTime1Bound = 0; - } - adjustHorizontalScrollBar(); - } - @Override public void resetStartFinishTime() { setStartFinishTime(fTime0Bound, fTime1Bound); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java index ab66cbd8cd..bba7514cf4 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal + * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal * * 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 java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.swt.SWT; + /** * An entry for use in the time graph views * @@ -35,8 +37,8 @@ public class TimeGraphEntry implements ITimeGraphEntry { /** Name of this entry (text to show) */ private String fName; - private long fStartTime = -1; - private long fEndTime = -1; + private long fStartTime = SWT.DEFAULT; + private long fEndTime = SWT.DEFAULT; private List fEventList = new ArrayList<>(); private List fZoomedEventList = new ArrayList<>(); private Comparator fComparator; @@ -177,10 +179,10 @@ public class TimeGraphEntry implements ITimeGraphEntry { } else { fEventList.add(event); } - if (fStartTime == -1 || start < fStartTime) { + if (fStartTime == SWT.DEFAULT || start < fStartTime) { fStartTime = start; } - if (fEndTime == -1 || end > fEndTime) { + if (fEndTime == SWT.DEFAULT || end > fEndTime) { fEndTime = end; } } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java index 44b63841a9..a92c7d41e9 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/ITimeDataProvider.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2007, 2014 Intel Corporation, Ericsson + * Copyright (c) 2007, 2015 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 @@ -60,32 +60,38 @@ public interface ITimeDataProvider { long getSelectionEnd(); /** - * @return The beginning time + * Get the user-specified bounds begin time. May be set to SWT.DEFAULT. For + * the actual bound use {@link #getMinTime()}. + * + * @return The user-specified begin time, or SWT.DEFAULT if input bound used */ long getBeginTime(); /** - * @return The end time + * Get the user-specified bounds end time. May be set to SWT.DEFAULT. For + * the actual bound use {@link #getMaxTime()}. + * + * @return The user-specified end time, or SWT.DEFAULT if input bound used */ long getEndTime(); /** - * @return The minimum time + * @return The bounds minimum time */ long getMinTime(); /** - * @return The maximum time + * @return The bounds maximum time */ long getMaxTime(); /** - * @return The start time of the current selection window + * @return The current window start time */ long getTime0(); /** - * @return The end time of the current selection window + * @return The current window end time */ long getTime1(); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java index cb3942bd53..d35e2794c7 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -745,7 +745,7 @@ public class TimeGraphControl extends TimeGraphBaseControl return; } long selectedTime = fTimeProvider.getSelectionBegin(); - long endTime = fTimeProvider.getEndTime(); + long endTime = fTimeProvider.getMaxTime(); ITimeEvent nextEvent; if (-1 == n && selectedTime > endTime) { nextEvent = Utils.findEvent(trace, selectedTime, 0);