From 843c272b126b4924a421afb10e5286c650d8cd77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Fri, 14 Feb 2014 14:23:29 -0500 Subject: [PATCH] TMF: Move methods from TmfXYChartViewer to new abstract TmfTimeViewer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The TmfXYChartViewer already had time synchronization methods implemented, but those can be used by other types of viewer. They have been moved to an abstract class. All viewers who need to synchronize with trace time may extend this class. Change-Id: I5d64c4412ea2de06e88ae8000b29770dbeecca83 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/22029 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../tmf/ui/viewers/ITmfTimeProvider.java | 95 ++++ .../tmf/ui/viewers/TmfTimeViewer.java | 439 ++++++++++++++++++ .../xycharts/ITmfChartTimeProvider.java | 105 +---- .../ui/viewers/xycharts/TmfXYChartViewer.java | 330 +------------ 4 files changed, 565 insertions(+), 404 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/ITmfTimeProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/TmfTimeViewer.java diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/ITmfTimeProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/ITmfTimeProvider.java new file mode 100644 index 0000000000..39c9420b27 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/ITmfTimeProvider.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2014 É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 + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation in ITmfChartTimeProvider + * Geneviève Bastien - Moved methods from ITmfChartTimeProvider to this interface + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.viewers; + +/** + * Interface for providing and updating time information. This is typically + * implemented by a viewer that is displaying trace data over time. + * + * @author Bernd Hufmann + * @author Geneviève Bastien + * @since 3.0 + */ +public interface ITmfTimeProvider extends ITmfViewer { + + /** + * Gets the start time of trace + * + * @return start time of trace + */ + long getStartTime(); + + /** + * Gets the end time of trace + * + * @return End time of trace + */ + long getEndTime(); + + /** + * Gets the start time of current time range displayed + * + * @return start time of current time range + */ + long getWindowStartTime(); + + /** + * Gets the end time of current time range displayed + * + * @return End time of current time range + */ + long getWindowEndTime(); + + /** + * Gets the duration of the current time range displayed + * + * @return duration of current time range + */ + long getWindowDuration(); + + /** + * Gets the begin time of the selected range + * + * @return the begin time of the selected range + */ + long getSelectionBeginTime(); + + /** + * Gets the end time of the selected range + * + * @return end time of the selected range + */ + long getSelectionEndTime(); + + /** + * Method to notify about a change of the current selected time. + * + * @param currentBeginTime + * The current selection begin time + * @param currentEndTime + * The current selection end time + */ + void updateSelectionRange(long currentBeginTime, long currentEndTime); + + /** + * Updates the current time range window. + * + * @param windowStartTime + * The window start time + * @param windowEndTime + * The window end time. + */ + void updateWindow(long windowStartTime, long windowEndTime); + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/TmfTimeViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/TmfTimeViewer.java new file mode 100644 index 0000000000..0de95d5ee1 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/TmfTimeViewer.java @@ -0,0 +1,439 @@ +/******************************************************************************* + * Copyright (c) 2014 É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 + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation in TmfXYChartViewer + * Geneviève Bastien - Moved methods from TmfXYChartViewer to this interface + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.viewers; + +import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; +import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler; +import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; +import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; +import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; +import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; +import org.eclipse.swt.widgets.Composite; + +/** + * Abstract class that extends {@link TmfViewer} that adds methods to + * synchronize with a trace's time information. + * + * This class will be extended by viewers who require time information to update + * their content. + * + *
+ * It provides three times of data:
+ *   - start and end time of the trace (available)
+ *   - start, end and duration of the current time window, ie the visible time range
+ *   - start and end of the time range selected
+ * 
+ * + * @author Bernd Hufmann + * @author Geneviève Bastien + * @since 3.0 + */ +public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvider { + + /** Start time of trace */ + private long fStartTime; + /** End time of trace */ + private long fEndTime; + /** Start time of current time range */ + private long fWindowStartTime; + /** End time of current time range */ + private long fWindowEndTime; + /** Duration of current time range */ + private long fWindowDuration; + /** Current begin time of selection range */ + private long fSelectionBeginTime; + /** Current end of selection range */ + private long fSelectionEndTime; + /** The trace that is displayed by this viewer */ + private ITmfTrace fTrace; + /** A signal throttler for range updates */ + private final TmfSignalThrottler fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200); + + /** + * Default constructor. + */ + public TmfTimeViewer() { + super(); + } + + /** + * Constructor that initializes the parent of the viewer + * + * @param parent + * The parent composite that holds this viewer + */ + public TmfTimeViewer(Composite parent) { + this(parent, ""); //$NON-NLS-1$ + } + + /** + * Constructor that initializes the parent of the viewer and that sets the + * name of the viewer + * + * @param parent + * The parent composite that holds this viewer + * @param name + * The name of the viewer + */ + public TmfTimeViewer(Composite parent, String name) { + init(parent, name); + } + + // ------------------------------------------------------------------------ + // Getter/Setters + // ------------------------------------------------------------------------ + + /** + * Sets the start time of the trace + * + * @param startTime + * The start time to set + */ + protected void setStartTime(long startTime) { + fStartTime = startTime; + } + + /** + * Sets the end time of the trace + * + * @param endTime + * The start time to set + */ + protected void setEndTime(long endTime) { + fEndTime = endTime; + } + + /** + * Sets the start time of the current time range window (visible range) + * + * @param windowStartTime + * The start time to set + */ + protected void setWindowStartTime(long windowStartTime) { + fWindowStartTime = windowStartTime; + } + + /** + * Sets the end time of the current time range window (visible range) + * + * @param windowEndTime + * The start time to set + */ + protected void setWindowEndTime(long windowEndTime) { + fWindowEndTime = windowEndTime; + } + + /** + * Sets the duration of the current time range window (visible range) + * + * @param windowDuration + * The window duration + */ + protected void setWindowDuration(long windowDuration) { + fWindowDuration = windowDuration; + } + + /** + * Sets the begin time of the selected range. + * + * @param selectionBeginTime + * The begin time to set + */ + protected void setSelectionBeginTime(long selectionBeginTime) { + fSelectionBeginTime = selectionBeginTime; + } + + /** + * Sets the end time of the selected range. + * + * @param selectionEndTime + * The end time to set + */ + protected void setSelectionEndTime(long selectionEndTime) { + fSelectionEndTime = selectionEndTime; + } + + /** + * Sets the trace that is displayed by this viewer. + * + * @param trace + * The trace to set + */ + protected void setTrace(ITmfTrace trace) { + fTrace = trace; + } + + /** + * Gets the trace that is displayed by this viewer. + * + * @return the trace + */ + protected ITmfTrace getTrace() { + return fTrace; + } + + // ------------------------------------------------------------------------ + // ITmfTimeProvider + // ------------------------------------------------------------------------ + + @Override + public long getStartTime() { + return fStartTime; + } + + @Override + public long getEndTime() { + return fEndTime; + } + + @Override + public long getWindowStartTime() { + return fWindowStartTime; + } + + @Override + public long getWindowEndTime() { + return fWindowEndTime; + } + + @Override + public long getWindowDuration() { + return fWindowDuration; + } + + @Override + public long getSelectionBeginTime() { + return fSelectionBeginTime; + } + + @Override + public long getSelectionEndTime() { + return fSelectionEndTime; + } + + @Override + public void updateSelectionRange(final long currentBeginTime, final long currentEndTime) { + if (fTrace != null) { + setSelectionBeginTime(currentBeginTime); + setSelectionEndTime(currentEndTime); + + final ITmfTimestamp startTimestamp = new TmfTimestamp(getSelectionBeginTime(), ITmfTimestamp.NANOSECOND_SCALE); + final ITmfTimestamp endTimestamp = new TmfTimestamp(getSelectionEndTime(), ITmfTimestamp.NANOSECOND_SCALE); + + TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, startTimestamp, endTimestamp); + broadcast(signal); + } + } + + @Override + public void updateWindow(long windowStartTime, long windowEndTime) { + + setWindowStartTime(windowStartTime); + setWindowEndTime(windowEndTime); + setWindowDuration(windowEndTime - windowStartTime); + + // Build the new time range; keep the current time + TmfTimeRange timeRange = new TmfTimeRange( + new TmfTimestamp(getWindowStartTime(), ITmfTimestamp.NANOSECOND_SCALE), + new TmfTimestamp(getWindowEndTime(), ITmfTimestamp.NANOSECOND_SCALE)); + + // Send the signal + TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange); + fTimeRangeSyncThrottle.queue(signal); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * A Method to load a trace into the viewer. + * + * @param trace + * A trace to apply in the viewer + */ + public void loadTrace(ITmfTrace trace) { + fTrace = trace; + + long timestamp = TmfTraceManager.getInstance().getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long windowStartTime = TmfTraceManager.getInstance().getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long startTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long endTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + + setSelectionBeginTime(timestamp); + setSelectionEndTime(timestamp); + setStartTime(startTime); + setWindowStartTime(windowStartTime); + setWindowDuration(fTrace.getInitialRangeOffset().getValue()); + setEndTime(endTime); + setWindowEndTime(windowStartTime + getWindowDuration()); + } + + /** + * Resets the content of the viewer + */ + public void reset() { + // Reset the internal data + setSelectionBeginTime(0); + setSelectionEndTime(0); + setStartTime(0); + setWindowStartTime(0); + setWindowDuration(0); + setEndTime(0); + setWindowEndTime(0); + setTrace(null); + } + + // ------------------------------------------------------------------------ + // Signal Handler + // ------------------------------------------------------------------------ + + /** + * Signal handler for handling of the trace opened signal. + * + * @param signal + * The trace opened signal {@link TmfTraceOpenedSignal} + */ + @TmfSignalHandler + public void traceOpened(TmfTraceOpenedSignal signal) { + fTrace = signal.getTrace(); + loadTrace(getTrace()); + } + + /** + * Signal handler for handling of the trace selected signal. + * + * @param signal + * The trace selected signal {@link TmfTraceSelectedSignal} + */ + @TmfSignalHandler + public void traceSelected(TmfTraceSelectedSignal signal) { + if (fTrace != signal.getTrace()) { + fTrace = signal.getTrace(); + loadTrace(getTrace()); + } + } + + /** + * Signal handler for handling of the trace closed signal. + * + * @param signal + * The trace closed signal {@link TmfTraceClosedSignal} + */ + @TmfSignalHandler + public void traceClosed(TmfTraceClosedSignal signal) { + + if (signal.getTrace() != fTrace) { + return; + } + + // Reset the internal data + fTrace = null; + reset(); + } + + /** + * Signal handler for handling of the time synch signal, ie the selected range. + * + * @param signal + * The time synch signal {@link TmfTimeSynchSignal} + */ + @TmfSignalHandler + public void selectionRangeUpdated(TmfTimeSynchSignal signal) { + if ((signal.getSource() != this) && (fTrace != null)) { + ITmfTimestamp selectedTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); + ITmfTimestamp selectedEndTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); + setSelectionBeginTime(selectedTime.getValue()); + setSelectionEndTime(selectedEndTime.getValue()); + } + } + + /** + * Signal handler for handling of the time range synch signal, ie the visible range. + * + * @param signal + * The time range synch signal {@link TmfRangeSynchSignal} + */ + @TmfSignalHandler + public void timeRangeUpdated(TmfRangeSynchSignal signal) { + + if (fTrace != null) { + // Validate the time range + TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange()); + if (range == null) { + return; + } + + if (signal.getSource() != this) { + // Update the time range + long windowStartTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long windowEndTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long windowDuration = windowEndTime - windowStartTime; + + setWindowStartTime(windowStartTime); + setWindowEndTime(windowEndTime); + setWindowDuration(windowDuration); + } + } + } + + /** + * Signal handler for handling of the trace range updated signal. + * + * @param signal + * The trace range signal {@link TmfTraceRangeUpdatedSignal} + */ + @TmfSignalHandler + public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) { + + if (signal.getTrace() != fTrace) { + return; + } + + TmfTimeRange fullRange = signal.getRange(); + + long traceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long traceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + + setStartTime(traceStartTime); + setEndTime(traceEndTime); + } + + /** + * Signal handler for handling of the trace updated signal. + * + * @param signal + * The trace updated signal {@link TmfTraceUpdatedSignal} + */ + @TmfSignalHandler + public void traceUpdated(TmfTraceUpdatedSignal signal) { + if (signal.getTrace() != fTrace) { + return; + } + TmfTimeRange fullRange = signal.getTrace().getTimeRange(); + long traceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + long traceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + + setStartTime(traceStartTime); + setEndTime(traceEndTime); + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/ITmfChartTimeProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/ITmfChartTimeProvider.java index 66cbcc4181..0b5439e4d1 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/ITmfChartTimeProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/ITmfChartTimeProvider.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2013 Ericsson + * Copyright (c) 2013, 2014 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 @@ -8,116 +8,47 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Geneviève Bastien - Moved some methods to ITmfTimeProvider **********************************************************************/ package org.eclipse.linuxtools.tmf.ui.viewers.xycharts; -import org.eclipse.linuxtools.tmf.ui.viewers.ITmfViewer; +import org.eclipse.linuxtools.tmf.ui.viewers.ITmfTimeProvider; /** - * Interface for providing and updating time information. This is typically - * implemented by a chart viewer that is displaying trace data over time where - * the time is shown on the x-axis. + * Interface adding some methods specific for SWT charts to the base time + * provider interface. Typically, the time will be shown on the x-axis. * * @author Bernd Hufmann * @since 3.0 */ -public interface ITmfChartTimeProvider extends ITmfViewer { - /** - * Gets the start time of trace - * - * @return start time of trace - */ - long getStartTime(); - - /** - * Gets the end time of trace - * - * @return End time of trace - */ - long getEndTime(); - - /** - * Gets the start time of current time range displayed - * - * @return start time of current time range - */ - long getWindowStartTime(); - - /** - * Gets the end time of current time range displayed - * - * @return End time of current time range - */ - long getWindowEndTime(); - - /** - * Gets the duration of the current time range displayed - * - * @return duration of current time range - */ - long getWindowDuration(); - - /** - * Gets the begin time of the selected range - * - * @return the begin time of the selected range - */ - long getSelectionBeginTime(); - - /** - * Gets the end time of the selected range - * - * @return end time of the selected range - */ - long getSelectionEndTime(); +public interface ITmfChartTimeProvider extends ITmfTimeProvider { /** * Returns a constant time offset that is used to normalize the time values - * to a range of 0..53 bits to avoid loss of precision when converting - * long <-> double. + * to a range of 0..53 bits to avoid loss of precision when converting long + * <-> double. * - * Time values are stored in TMF as long values. The SWT chart library - * uses values of type double (on x and y axis). To avoid loss of - * precision when converting long <-> double the values need to fit - * within 53 bits. + * Time values are stored in TMF as long values. The SWT chart library uses + * values of type double (on x and y axis). To avoid loss of precision when + * converting long <-> double the values need to fit within 53 bits. * * Subtract the offset when using time values provided externally for * internal usage in SWT chart. Add the offset when using time values * provided by SWT chart (e.g. for display purposes) and when broadcasting * them externally (e.g. time synchronization signals). * - * For example the offset can be calculated as the time of the first - * time value in the current time range to be displayed in the chart. - * Add +1 to avoid 0 when using logarithmic scale. + * For example the offset can be calculated as the time of the first time + * value in the current time range to be displayed in the chart. Add +1 to + * avoid 0 when using logarithmic scale. * - * t0=10000, t2=20000, tn=N -> timeOffset=t0-1 - * -> t0'=1, t1'=10001, tn'=N-timeOffset + * t0=10000, t2=20000, tn=N -> timeOffset=t0-1 -> t0'=1, t1'=10001, + * tn'=N-timeOffset * - * where t0 ... tn are times used externally and t0' ... tn' are times - * used internally by the SWT chart. + * where t0 ... tn are times used externally and t0' ... tn' are times used + * internally by the SWT chart. * * @return the time offset */ long getTimeOffset(); - /** - * Method to notify about a change of the current selected time. - * - * @param currentBeginTime - * The current selection begin time - * @param currentEndTime - * The current selection end time - */ - void updateSelectionRange(long currentBeginTime, long currentEndTime); - - /** - * Updates the current time range window. - * - * @param windowStartTime - * The window start time - * @param windowEndTime - * The window end time. - */ - void updateWindow(long windowStartTime, long windowEndTime); - } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/TmfXYChartViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/TmfXYChartViewer.java index fdb1959327..fdb92f032a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/TmfXYChartViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/xycharts/TmfXYChartViewer.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2013 Ericsson + * Copyright (c) 2013, 2014 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 @@ -8,25 +8,16 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Geneviève Bastien - Moved some methods to TmfTimeViewer **********************************************************************/ package org.eclipse.linuxtools.tmf.ui.viewers.xycharts; import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; -import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler; import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; -import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; -import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; -import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; -import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; -import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; -import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; -import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; -import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; -import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; -import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewer; +import org.eclipse.linuxtools.tmf.ui.viewers.TmfTimeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -44,7 +35,7 @@ import org.swtchart.ISeriesSet; * @author Bernd Hufmann * @since 3.0 */ -public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTimeProvider { +public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChartTimeProvider { // ------------------------------------------------------------------------ // Attributes @@ -54,26 +45,8 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim * precision when converting long to double and back. */ private long fTimeOffset; - /** Start time of trace */ - private long fStartTime; - /** End time of trace */ - private long fEndTime; - /** Start time of current time range */ - private long fWindowStartTime; - /** End time of current time range */ - private long fWindowEndTime; - /** Duration of current time range */ - private long fWindowDuration; - /** Current begin time of selection range */ - private long fSelectionBeginTime; - /** Current end of selection range */ - private long fSelectionEndTime; - /** The trace that is displayed by this viewer */ - private ITmfTrace fTrace; /** The SWT Chart reference */ private Chart fSwtChart; - /** A signal throttler for range updates */ - private final TmfSignalThrottler fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200); /** The mouse selection provider */ private TmfBaseProvider fMouseSelectionProvider; /** The mouse drag zoom provider */ @@ -146,95 +119,6 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim fTimeOffset = timeOffset; } - /** - * Sets the start time of the trace - * - * @param startTime - * The start time to set - */ - protected void setStartTime(long startTime) { - fStartTime = startTime; - } - - /** - * Sets the end time of the trace - * - * @param endTime - * The start time to set - */ - protected void setEndTime(long endTime) { - fEndTime = endTime; - } - - /** - * Sets the start time of the current time range window - * - * @param windowStartTime - * The start time to set - */ - protected void setWindowStartTime(long windowStartTime) { - fWindowStartTime = windowStartTime; - } - - /** - * Sets the end time of the current time range window - * - * @param windowEndTime - * The start time to set - */ - protected void setWindowEndTime(long windowEndTime) { - fWindowEndTime = windowEndTime; - } - - /** - * Sets the start time of the current time range window - * - * @param windowDuration - * The start time to set - */ - protected void setWindowDuration(long windowDuration) { - fWindowDuration = windowDuration; - } - - /** - * Sets the begin time of the selection range. - * - * @param selectionBeginTime - * The begin time to set - */ - protected void setSelectionBeginTime(long selectionBeginTime) { - fSelectionBeginTime = selectionBeginTime; - } - - /** - * Sets the end time of the selection range. - * - * @param selectionEndTime - * The end time to set - */ - protected void setSelectionEndTime(long selectionEndTime) { - fSelectionEndTime = selectionEndTime; - } - - /** - * Sets the trace that is displayed by this viewer. - * - * @param trace - * The trace to set - */ - protected void setTrace(ITmfTrace trace) { - fTrace = trace; - } - - /** - * Gets the trace that is displayed by this viewer. - * - * @return the trace - */ - protected ITmfTrace getTrace() { - return fTrace; - } - /** * Sets the SWT Chart reference * @@ -328,77 +212,12 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim // ------------------------------------------------------------------------ // ITmfChartTimeProvider // ------------------------------------------------------------------------ - @Override - public long getStartTime() { - return fStartTime; - } - - @Override - public long getEndTime() { - return fEndTime; - } - - @Override - public long getWindowStartTime() { - return fWindowStartTime; - } - - @Override - public long getWindowEndTime() { - return fWindowEndTime; - } - - @Override - public long getWindowDuration() { - return fWindowDuration; - } - - @Override - public long getSelectionBeginTime() { - return fSelectionBeginTime; - } - - @Override - public long getSelectionEndTime() { - return fSelectionEndTime; - } @Override public long getTimeOffset() { return fTimeOffset; } - @Override - public void updateSelectionRange(final long currentBeginTime, final long currentEndTime) { - if (fTrace != null) { - setSelectionBeginTime(currentBeginTime); - setSelectionEndTime(currentEndTime); - - final ITmfTimestamp startTimestamp = new TmfTimestamp(fSelectionBeginTime, ITmfTimestamp.NANOSECOND_SCALE); - final ITmfTimestamp endTimestamp = new TmfTimestamp(fSelectionEndTime, ITmfTimestamp.NANOSECOND_SCALE); - - TmfTimeSynchSignal signal = new TmfTimeSynchSignal(TmfXYChartViewer.this, startTimestamp, endTimestamp); - broadcast(signal); - } - } - - @Override - public void updateWindow(long windowStartTime, long windowEndTime) { - - setWindowStartTime(windowStartTime); - setWindowEndTime(windowEndTime); - fWindowDuration = windowEndTime - windowStartTime; - - // Build the new time range; keep the current time - TmfTimeRange timeRange = new TmfTimeRange( - new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE), - new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE)); - - // Send the signal - TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange); - fTimeRangeSyncThrottle.queue(signal); - } - // ------------------------------------------------------------------------ // ITmfViewer interface // ------------------------------------------------------------------------ @@ -450,21 +269,9 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim * @param trace * A trace to apply in the viewer */ + @Override public void loadTrace(ITmfTrace trace) { - fTrace = trace; - - long timestamp = TmfTraceManager.getInstance().getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long windowStartTime = TmfTraceManager.getInstance().getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long startTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long endTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - - setSelectionBeginTime(timestamp); - setSelectionEndTime(timestamp); - setStartTime(startTime); - setWindowStartTime(windowStartTime); - setWindowDuration(fTrace.getInitialRangeOffset().getValue()); - setEndTime(endTime); - setWindowEndTime(windowStartTime + getWindowDuration()); + super.loadTrace(trace); clearContent(); updateContent(); } @@ -472,16 +279,9 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim /** * Resets the content of the viewer */ + @Override public void reset() { - // Reset the internal data - setSelectionBeginTime(0); - setSelectionEndTime(0); - setStartTime(0); - setWindowStartTime(0); - setWindowDuration(0); - setEndTime(0); - setWindowEndTime(0); - setTrace(null); + super.reset(); clearContent(); } @@ -494,63 +294,17 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim // Signal Handler // ------------------------------------------------------------------------ - /** - * Signal handler for handling of the trace opened signal. - * - * @param signal - * The trace opened signal {@link TmfTraceOpenedSignal} - */ - @TmfSignalHandler - public void traceOpened(TmfTraceOpenedSignal signal) { - fTrace = signal.getTrace(); - loadTrace(getTrace()); - } - - /** - * Signal handler for handling of the trace selected signal. - * - * @param signal - * The trace selected signal {@link TmfTraceSelectedSignal} - */ - @TmfSignalHandler - public void traceSelected(TmfTraceSelectedSignal signal) { - if (fTrace != signal.getTrace()) { - fTrace = signal.getTrace(); - loadTrace(getTrace()); - } - } - - /** - * Signal handler for handling of the trace closed signal. - * - * @param signal - * The trace closed signal {@link TmfTraceClosedSignal} - */ - @TmfSignalHandler - public void traceClosed(TmfTraceClosedSignal signal) { - - if (signal.getTrace() != fTrace) { - return; - } - - // Reset the internal data - fTrace = null; - reset(); - } - /** * Signal handler for handling of the time synch signal. * * @param signal * The time synch signal {@link TmfTimeSynchSignal} */ + @Override @TmfSignalHandler public void selectionRangeUpdated(TmfTimeSynchSignal signal) { - if ((signal.getSource() != this) && (fTrace != null)) { - ITmfTimestamp selectedTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); - ITmfTimestamp selectedEndTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); - setSelectionBeginTime(selectedTime.getValue()); - setSelectionEndTime(selectedEndTime.getValue()); + super.selectionRangeUpdated(signal); + if ((signal.getSource() != this) && (getTrace() != null)) { if (fMouseSelectionProvider != null) { fMouseSelectionProvider.refresh(); } @@ -563,71 +317,13 @@ public abstract class TmfXYChartViewer extends TmfViewer implements ITmfChartTim * @param signal * The time range synch signal {@link TmfRangeSynchSignal} */ + @Override @TmfSignalHandler public void timeRangeUpdated(TmfRangeSynchSignal signal) { - - if (fTrace != null) { - // Validate the time range - TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange()); - if (range == null) { - return; - } - - if (signal.getSource() != this) { - // Update the time range - long windowStartTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long windowEndTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long windowDuration = windowEndTime - windowStartTime; - - setWindowStartTime(windowStartTime); - setWindowEndTime(windowEndTime); - setWindowDuration(windowDuration); - } - } + super.timeRangeUpdated(signal); updateContent(); } - /** - * Signal handler for handling of the trace range updated signal. - * - * @param signal - * The trace range signal {@link TmfTraceRangeUpdatedSignal} - */ - @TmfSignalHandler - public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) { - - if (signal.getTrace() != fTrace) { - return; - } - - TmfTimeRange fullRange = signal.getRange(); - - long traceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long traceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - - setStartTime(traceStartTime); - setEndTime(traceEndTime); - } - - /** - * Signal handler for handling of the trace updated signal. - * - * @param signal - * The trace updated signal {@link TmfTraceUpdatedSignal} - */ - @TmfSignalHandler - public void traceUpdated(TmfTraceUpdatedSignal signal) { - if (signal.getTrace() != fTrace) { - return; - } - TmfTimeRange fullRange = signal.getTrace().getTimeRange(); - long traceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - long traceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - - setStartTime(traceStartTime); - setEndTime(traceEndTime); - } - /** * Signal handler for handling the signal that notifies about an updated * timestamp format. -- 2.34.1