releng: adjust jacoco report path to new folder structure
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / TmfTimeViewer.java
CommitLineData
843c272b 1/*******************************************************************************
4e72adee 2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal and others.
843c272b
GB
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation in TmfXYChartViewer
11 * Geneviève Bastien - Moved methods from TmfXYChartViewer to this interface
12 *******************************************************************************/
13
2bdf0193 14package org.eclipse.tracecompass.tmf.ui.viewers;
843c272b 15
843c272b 16import org.eclipse.swt.widgets.Composite;
97c71024 17import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
2bdf0193
AM
18import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
19import org.eclipse.tracecompass.tmf.core.signal.TmfSignalThrottler;
97c71024 20import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
2bdf0193
AM
21import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
22import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
23import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
24import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
25import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal;
26import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
27import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
28import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
29import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
21852dfa 30import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
2bdf0193 31import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
843c272b
GB
32
33/**
34 * Abstract class that extends {@link TmfViewer} that adds methods to
35 * synchronize with a trace's time information.
36 *
37 * This class will be extended by viewers who require time information to update
38 * their content.
39 *
40 * <pre>
41 * It provides three times of data:
42 * - start and end time of the trace (available)
43 * - start, end and duration of the current time window, ie the visible time range
44 * - start and end of the time range selected
45 * </pre>
46 *
47 * @author Bernd Hufmann
48 * @author Geneviève Bastien
843c272b
GB
49 */
50public abstract class TmfTimeViewer extends TmfViewer implements ITmfTimeProvider {
51
52 /** Start time of trace */
53 private long fStartTime;
54 /** End time of trace */
55 private long fEndTime;
56 /** Start time of current time range */
57 private long fWindowStartTime;
58 /** End time of current time range */
59 private long fWindowEndTime;
843c272b
GB
60 /** Current begin time of selection range */
61 private long fSelectionBeginTime;
62 /** Current end of selection range */
63 private long fSelectionEndTime;
64 /** The trace that is displayed by this viewer */
65 private ITmfTrace fTrace;
66 /** A signal throttler for range updates */
67 private final TmfSignalThrottler fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200);
68
69 /**
70 * Default constructor.
71 */
72 public TmfTimeViewer() {
73 super();
74 }
75
76 /**
77 * Constructor that initializes the parent of the viewer
78 *
79 * @param parent
80 * The parent composite that holds this viewer
81 */
82 public TmfTimeViewer(Composite parent) {
83 this(parent, ""); //$NON-NLS-1$
84 }
85
86 /**
87 * Constructor that initializes the parent of the viewer and that sets the
88 * name of the viewer
89 *
90 * @param parent
91 * The parent composite that holds this viewer
92 * @param name
93 * The name of the viewer
94 */
95 public TmfTimeViewer(Composite parent, String name) {
96 init(parent, name);
97 }
98
99 // ------------------------------------------------------------------------
100 // Getter/Setters
101 // ------------------------------------------------------------------------
102
103 /**
104 * Sets the start time of the trace
105 *
106 * @param startTime
107 * The start time to set
108 */
109 protected void setStartTime(long startTime) {
110 fStartTime = startTime;
111 }
112
113 /**
114 * Sets the end time of the trace
115 *
116 * @param endTime
117 * The start time to set
118 */
119 protected void setEndTime(long endTime) {
120 fEndTime = endTime;
121 }
122
123 /**
2a3d8f39 124 * Sets the start time and end of the current time range window (visible range)
843c272b
GB
125 *
126 * @param windowStartTime
127 * The start time to set
843c272b
GB
128 * @param windowEndTime
129 * The start time to set
2a3d8f39 130 * @since 1.0
843c272b 131 */
2a3d8f39
BH
132 protected void setWindowRange(long windowStartTime, long windowEndTime) {
133 fWindowStartTime = windowStartTime;
843c272b
GB
134 fWindowEndTime = windowEndTime;
135 }
136
843c272b 137 /**
842b496e
BH
138 * Sets the begin and end time of the selected range without sending the
139 * {@link TmfSelectionRangeUpdatedSignal} signal.
843c272b
GB
140 *
141 * @param selectionBeginTime
142 * The begin time to set
843c272b
GB
143 * @param selectionEndTime
144 * The end time to set
842b496e
BH
145 *
146 * @since 1.0
843c272b 147 */
842b496e
BH
148 protected void setSelectionRange(long selectionBeginTime, long selectionEndTime) {
149 fSelectionBeginTime = selectionBeginTime;
843c272b
GB
150 fSelectionEndTime = selectionEndTime;
151 }
152
153 /**
154 * Sets the trace that is displayed by this viewer.
155 *
156 * @param trace
157 * The trace to set
158 */
159 protected void setTrace(ITmfTrace trace) {
160 fTrace = trace;
161 }
162
163 /**
164 * Gets the trace that is displayed by this viewer.
165 *
166 * @return the trace
167 */
168 protected ITmfTrace getTrace() {
169 return fTrace;
170 }
171
172 // ------------------------------------------------------------------------
173 // ITmfTimeProvider
174 // ------------------------------------------------------------------------
175
176 @Override
177 public long getStartTime() {
178 return fStartTime;
179 }
180
181 @Override
182 public long getEndTime() {
183 return fEndTime;
184 }
185
186 @Override
187 public long getWindowStartTime() {
188 return fWindowStartTime;
189 }
190
191 @Override
192 public long getWindowEndTime() {
193 return fWindowEndTime;
194 }
195
196 @Override
197 public long getWindowDuration() {
4e72adee 198 return getWindowEndTime() - getWindowStartTime();
843c272b
GB
199 }
200
201 @Override
202 public long getSelectionBeginTime() {
203 return fSelectionBeginTime;
204 }
205
206 @Override
207 public long getSelectionEndTime() {
208 return fSelectionEndTime;
209 }
210
211 @Override
212 public void updateSelectionRange(final long currentBeginTime, final long currentEndTime) {
213 if (fTrace != null) {
842b496e 214 setSelectionRange(currentBeginTime, currentEndTime);
843c272b
GB
215
216 final ITmfTimestamp startTimestamp = new TmfTimestamp(getSelectionBeginTime(), ITmfTimestamp.NANOSECOND_SCALE);
217 final ITmfTimestamp endTimestamp = new TmfTimestamp(getSelectionEndTime(), ITmfTimestamp.NANOSECOND_SCALE);
218
97c71024 219 TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(this, startTimestamp, endTimestamp);
843c272b
GB
220 broadcast(signal);
221 }
222 }
223
224 @Override
225 public void updateWindow(long windowStartTime, long windowEndTime) {
226
2a3d8f39 227 setWindowRange(windowStartTime, windowEndTime);
843c272b
GB
228
229 // Build the new time range; keep the current time
230 TmfTimeRange timeRange = new TmfTimeRange(
231 new TmfTimestamp(getWindowStartTime(), ITmfTimestamp.NANOSECOND_SCALE),
232 new TmfTimestamp(getWindowEndTime(), ITmfTimestamp.NANOSECOND_SCALE));
233
234 // Send the signal
97c71024 235 TmfWindowRangeUpdatedSignal signal = new TmfWindowRangeUpdatedSignal(this, timeRange);
843c272b
GB
236 fTimeRangeSyncThrottle.queue(signal);
237 }
238
239 // ------------------------------------------------------------------------
240 // Operations
241 // ------------------------------------------------------------------------
242 /**
243 * A Method to load a trace into the viewer.
244 *
245 * @param trace
246 * A trace to apply in the viewer
247 */
248 public void loadTrace(ITmfTrace trace) {
249 fTrace = trace;
250
21852dfa 251 TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
33168583
BH
252 long selectionStart = ctx.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
253 long selectionEnd = ctx.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
21852dfa
AM
254 TmfTimeRange windowRange = ctx.getWindowRange();
255
256 long windowStartTime = windowRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
257 long windowEndTime = windowRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
843c272b
GB
258 long startTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
259 long endTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
260
842b496e
BH
261 setSelectionRange(selectionStart, selectionEnd);
262
843c272b 263 setStartTime(startTime);
2a3d8f39 264 setWindowRange(windowStartTime, windowEndTime);
843c272b 265 setEndTime(endTime);
843c272b
GB
266 }
267
268 /**
269 * Resets the content of the viewer
270 */
271 public void reset() {
272 // Reset the internal data
842b496e 273 setSelectionRange(0, 0);
843c272b 274 setStartTime(0);
2a3d8f39 275 setWindowRange(0, 0);
843c272b 276 setEndTime(0);
843c272b
GB
277 setTrace(null);
278 }
279
280 // ------------------------------------------------------------------------
281 // Signal Handler
282 // ------------------------------------------------------------------------
283
284 /**
285 * Signal handler for handling of the trace opened signal.
286 *
287 * @param signal
288 * The trace opened signal {@link TmfTraceOpenedSignal}
289 */
290 @TmfSignalHandler
291 public void traceOpened(TmfTraceOpenedSignal signal) {
292 fTrace = signal.getTrace();
293 loadTrace(getTrace());
294 }
295
296 /**
297 * Signal handler for handling of the trace selected signal.
298 *
299 * @param signal
300 * The trace selected signal {@link TmfTraceSelectedSignal}
301 */
302 @TmfSignalHandler
303 public void traceSelected(TmfTraceSelectedSignal signal) {
304 if (fTrace != signal.getTrace()) {
305 fTrace = signal.getTrace();
306 loadTrace(getTrace());
307 }
308 }
309
310 /**
311 * Signal handler for handling of the trace closed signal.
312 *
313 * @param signal
314 * The trace closed signal {@link TmfTraceClosedSignal}
315 */
316 @TmfSignalHandler
317 public void traceClosed(TmfTraceClosedSignal signal) {
318
319 if (signal.getTrace() != fTrace) {
320 return;
321 }
322
323 // Reset the internal data
324 fTrace = null;
325 reset();
326 }
327
328 /**
97c71024 329 * Signal handler for handling of the selected range signal.
843c272b
GB
330 *
331 * @param signal
97c71024
AM
332 * The {@link TmfSelectionRangeUpdatedSignal}
333 * @since 1.0
843c272b
GB
334 */
335 @TmfSignalHandler
97c71024 336 public void selectionRangeUpdated(TmfSelectionRangeUpdatedSignal signal) {
843c272b
GB
337 if ((signal.getSource() != this) && (fTrace != null)) {
338 ITmfTimestamp selectedTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
339 ITmfTimestamp selectedEndTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
842b496e 340 setSelectionRange(selectedTime.getValue(), selectedEndTime.getValue());
843c272b
GB
341 }
342 }
343
344 /**
97c71024 345 * Signal handler for handling of the window range signal.
843c272b
GB
346 *
347 * @param signal
97c71024
AM
348 * The {@link TmfWindowRangeUpdatedSignal}
349 * @since 1.0
843c272b
GB
350 */
351 @TmfSignalHandler
97c71024 352 public void windowRangeUpdated(TmfWindowRangeUpdatedSignal signal) {
843c272b
GB
353
354 if (fTrace != null) {
355 // Validate the time range
356 TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange());
357 if (range == null) {
358 return;
359 }
360
361 if (signal.getSource() != this) {
362 // Update the time range
363 long windowStartTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
364 long windowEndTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
843c272b 365
2a3d8f39 366 setWindowRange(windowStartTime, windowEndTime);
843c272b
GB
367 }
368 }
369 }
370
371 /**
372 * Signal handler for handling of the trace range updated signal.
373 *
374 * @param signal
375 * The trace range signal {@link TmfTraceRangeUpdatedSignal}
376 */
377 @TmfSignalHandler
378 public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) {
379
380 if (signal.getTrace() != fTrace) {
381 return;
382 }
383
384 TmfTimeRange fullRange = signal.getRange();
385
386 long traceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
387 long traceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
388
389 setStartTime(traceStartTime);
390 setEndTime(traceEndTime);
391 }
392
393 /**
394 * Signal handler for handling of the trace updated signal.
395 *
396 * @param signal
397 * The trace updated signal {@link TmfTraceUpdatedSignal}
398 */
399 @TmfSignalHandler
400 public void traceUpdated(TmfTraceUpdatedSignal signal) {
401 if (signal.getTrace() != fTrace) {
402 return;
403 }
404 TmfTimeRange fullRange = signal.getTrace().getTimeRange();
405 long traceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
406 long traceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
407
408 setStartTime(traceStartTime);
409 setEndTime(traceEndTime);
410 }
411
412}
This page took 0.15201 seconds and 5 git commands to generate.