ctf: Update paths in the CTF-Testsuite tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramView.java
CommitLineData
6e512b93 1/*******************************************************************************
c8422608 2 * Copyright (c) 2009, 2013 Ericsson
1b055dfa 3 *
6e512b93
ASL
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
1b055dfa 8 *
6e512b93 9 * Contributors:
b59134e1 10 * William Bourque - Initial API and implementation
c392540b 11 * Yuriy Vashchuk - GUI reorganisation, simplification and some related code improvements.
1b055dfa 12 * Yuriy Vashchuk - Histograms optimisation.
c392540b
FC
13 * Yuriy Vashchuk - Histogram Canvas Heritage correction
14 * Francois Chouinard - Cleanup and refactoring
e0752744 15 * Francois Chouinard - Moved from LTTng to TMF
65cdf787 16 * Patrick Tasse - Update for mouse wheel zoom
6e512b93 17 *******************************************************************************/
3e9fdb8b 18
e0752744 19package org.eclipse.linuxtools.tmf.ui.views.histogram;
6e512b93 20
95aa81ef
JCK
21import org.eclipse.jface.action.Action;
22import org.eclipse.jface.action.IAction;
23import org.eclipse.jface.action.Separator;
24import org.eclipse.linuxtools.internal.tmf.ui.Activator;
25import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
6c13869b 26import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
f6ad2e3d 27import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
6c13869b
FC
28import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
29import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
38df2c82 30import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler;
6c13869b 31import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
faa38350
PT
32import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
33import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
34import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
35import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
36import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
3bd46eef
AM
37import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
38import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
39import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
faa38350 40import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
b59134e1
WB
41import org.eclipse.linuxtools.tmf.ui.views.TmfView;
42import org.eclipse.swt.SWT;
65cdf787 43import org.eclipse.swt.events.MouseWheelListener;
b59134e1 44import org.eclipse.swt.layout.GridData;
252ae4bd 45import org.eclipse.swt.layout.GridLayout;
6e512b93 46import org.eclipse.swt.widgets.Composite;
95aa81ef 47import org.eclipse.ui.IActionBars;
6e512b93 48
544fe9b7 49/**
faa38350 50 * The purpose of this view is to provide graphical time distribution statistics about the trace events.
544fe9b7 51 * <p>
c392540b
FC
52 * The view is composed of two histograms and two controls:
53 * <ul>
faa38350 54 * <li>an event distribution histogram for the whole trace;
c392540b
FC
55 * <li>an event distribution histogram for current time window (window span);
56 * <li>the timestamp of the currently selected event;
57 * <li>the window span (size of the time window of the smaller histogram).
58 * </ul>
59 * The histograms x-axis show their respective time range.
abbdd66a 60 *
f8177ba2 61 * @version 2.0
2af7df97 62 * @author Francois Chouinard
544fe9b7 63 */
c392540b
FC
64public class HistogramView extends TmfView {
65
66 // ------------------------------------------------------------------------
67 // Constants
68 // ------------------------------------------------------------------------
69
b544077e
BH
70 /**
71 * The view ID as defined in plugin.xml
72 */
e0752744 73 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$
c392540b 74
c392540b
FC
75 // ------------------------------------------------------------------------
76 // Attributes
77 // ------------------------------------------------------------------------
78
79 // Parent widget
80 private Composite fParent;
81
faa38350
PT
82 // The current trace
83 private ITmfTrace fTrace;
c392540b 84
f8177ba2 85 // Current timestamp/time window - everything in the TIME_SCALE
faa38350
PT
86 private long fTraceStartTime;
87 private long fTraceEndTime;
c392540b
FC
88 private long fWindowStartTime;
89 private long fWindowEndTime;
d7ee91bb 90 private long fWindowSpan;
0fcf3b09
PT
91 private long fSelectionBeginTime;
92 private long fSelectionEndTime;
c392540b
FC
93
94 // Time controls
95 private HistogramTextControl fCurrentEventTimeControl;
96 private HistogramTextControl fTimeSpanControl;
97
98 // Histogram/request for the full trace range
99 private static FullTraceHistogram fFullTraceHistogram;
100 private HistogramRequest fFullTraceRequest;
101
102 // Histogram/request for the selected time range
103 private static TimeRangeHistogram fTimeRangeHistogram;
104 private HistogramRequest fTimeRangeRequest;
105
38df2c82
AM
106 // Throttlers for the time sync and time-range sync signals
107 private final TmfSignalThrottler fTimeSyncThrottle;
108 private final TmfSignalThrottler fTimeRangeSyncThrottle;
109
95aa81ef
JCK
110 // Action for toggle showing the lost events
111 private Action hideLostEventsAction;
112
c392540b
FC
113 // ------------------------------------------------------------------------
114 // Constructor
115 // ------------------------------------------------------------------------
116
b544077e
BH
117 /**
118 * Default constructor
119 */
c392540b
FC
120 public HistogramView() {
121 super(ID);
38df2c82
AM
122 fTimeSyncThrottle = new TmfSignalThrottler(this, 200);
123 fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200);
c392540b
FC
124 }
125
6a13fa07 126 @Override
c392540b 127 public void dispose() {
1b055dfa 128 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
4dc47e28
FC
129 fTimeRangeRequest.cancel();
130 }
1b055dfa 131 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
4dc47e28
FC
132 fFullTraceRequest.cancel();
133 }
6a13fa07
FC
134 fFullTraceHistogram.dispose();
135 fTimeRangeHistogram.dispose();
f8177ba2
FC
136 fCurrentEventTimeControl.dispose();
137 fTimeSpanControl.dispose();
4dc47e28 138 super.dispose();
c392540b
FC
139 }
140
141 // ------------------------------------------------------------------------
142 // TmfView
143 // ------------------------------------------------------------------------
144
145 @Override
c392540b
FC
146 public void createPartControl(Composite parent) {
147
148 fParent = parent;
149
150 // Control labels
151 final String currentEventLabel = Messages.HistogramView_currentEventLabel;
152 final String windowSpanLabel = Messages.HistogramView_windowSpanLabel;
153
154 // --------------------------------------------------------------------
155 // Set the HistogramView layout
156 // --------------------------------------------------------------------
157
158 Composite viewComposite = new Composite(fParent, SWT.FILL);
159 GridLayout gridLayout = new GridLayout();
160 gridLayout.numColumns = 2;
161 gridLayout.horizontalSpacing = 5;
162 gridLayout.verticalSpacing = 0;
163 gridLayout.marginHeight = 0;
164 gridLayout.marginWidth = 0;
165 viewComposite.setLayout(gridLayout);
166
167 // Use all available space
168 GridData gridData = new GridData();
169 gridData.horizontalAlignment = SWT.FILL;
170 gridData.verticalAlignment = SWT.FILL;
171 gridData.grabExcessHorizontalSpace = true;
172 viewComposite.setLayoutData(gridData);
173
174 // --------------------------------------------------------------------
175 // Time controls
176 // --------------------------------------------------------------------
177
178 Composite controlsComposite = new Composite(viewComposite, SWT.FILL);
179 gridLayout = new GridLayout();
180 gridLayout.numColumns = 2;
181 gridLayout.marginHeight = 0;
182 gridLayout.marginWidth = 0;
183 gridLayout.horizontalSpacing = 5;
184 gridLayout.verticalSpacing = 0;
f8177ba2 185 gridLayout.makeColumnsEqualWidth = false;
c392540b
FC
186 gridLayout.marginLeft = 5;
187 gridLayout.marginRight = 5;
188 controlsComposite.setLayout(gridLayout);
189
190 // Current event time control
191 gridData = new GridData();
192 gridData.horizontalAlignment = SWT.CENTER;
193 gridData.verticalAlignment = SWT.CENTER;
f8177ba2 194 fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, currentEventLabel, 0L);
c392540b 195 fCurrentEventTimeControl.setLayoutData(gridData);
da7bdcbc 196 fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
c392540b
FC
197
198 // Window span time control
199 gridData = new GridData();
200 gridData.horizontalAlignment = SWT.CENTER;
201 gridData.verticalAlignment = SWT.CENTER;
f8177ba2 202 fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L);
c392540b 203 fTimeSpanControl.setLayoutData(gridData);
da7bdcbc 204 fTimeSpanControl.setValue(Long.MIN_VALUE);
c392540b
FC
205
206 // --------------------------------------------------------------------
207 // Time range histogram
208 // --------------------------------------------------------------------
209
210 Composite timeRangeComposite = new Composite(viewComposite, SWT.FILL);
211 gridLayout = new GridLayout();
212 gridLayout.numColumns = 1;
213 gridLayout.marginHeight = 0;
214 gridLayout.marginWidth = 0;
215 gridLayout.marginTop = 5;
216 gridLayout.horizontalSpacing = 0;
217 gridLayout.verticalSpacing = 0;
218 gridLayout.marginLeft = 5;
219 gridLayout.marginRight = 5;
220 timeRangeComposite.setLayout(gridLayout);
221
222 // Use remaining horizontal space
223 gridData = new GridData();
224 gridData.horizontalAlignment = SWT.FILL;
225 gridData.verticalAlignment = SWT.FILL;
226 gridData.grabExcessHorizontalSpace = true;
227 timeRangeComposite.setLayoutData(gridData);
228
229 // Histogram
230 fTimeRangeHistogram = new TimeRangeHistogram(this, timeRangeComposite);
231
232 // --------------------------------------------------------------------
233 // Full range histogram
234 // --------------------------------------------------------------------
235
236 Composite fullRangeComposite = new Composite(viewComposite, SWT.FILL);
237 gridLayout = new GridLayout();
238 gridLayout.numColumns = 1;
239 gridLayout.marginHeight = 0;
240 gridLayout.marginWidth = 0;
241 gridLayout.marginTop = 5;
242 gridLayout.horizontalSpacing = 0;
243 gridLayout.verticalSpacing = 0;
244 gridLayout.marginLeft = 5;
245 gridLayout.marginRight = 5;
246 fullRangeComposite.setLayout(gridLayout);
247
248 // Use remaining horizontal space
249 gridData = new GridData();
250 gridData.horizontalAlignment = SWT.FILL;
251 gridData.verticalAlignment = SWT.FILL;
252 gridData.horizontalSpan = 2;
253 gridData.grabExcessHorizontalSpace = true;
254 fullRangeComposite.setLayoutData(gridData);
255
256 // Histogram
257 fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite);
258
65cdf787
PT
259 // Add mouse wheel listener to time span control
260 MouseWheelListener listener = fFullTraceHistogram.getZoom();
261 fTimeSpanControl.addMouseWheelListener(listener);
262
95aa81ef
JCK
263
264 // View Action Handling
265 contributeToActionBars();
266
3ac5721a
AM
267 ITmfTrace trace = getActiveTrace();
268 if (trace != null) {
269 traceSelected(new TmfTraceSelectedSignal(this, trace));
1b055dfa 270 }
ecfd1d41 271 }
c392540b
FC
272
273 @Override
c392540b 274 public void setFocus() {
faa38350 275 fFullTraceHistogram.fCanvas.setFocus();
833a21aa 276 }
c392540b 277
f8177ba2
FC
278 void refresh() {
279 fParent.layout(true);
280 }
281
c392540b
FC
282 // ------------------------------------------------------------------------
283 // Accessors
284 // ------------------------------------------------------------------------
285
faa38350
PT
286 /**
287 * Returns the current trace handled by the view
288 *
289 * @return the current trace
290 * @since 2.0
291 */
292 public ITmfTrace getTrace() {
293 return fTrace;
294 }
295
b544077e
BH
296 /**
297 * Returns the time range of the current selected window (base on default time scale).
abbdd66a 298 *
b544077e 299 * @return the time range of current selected window.
3bd46eef 300 * @since 2.0
b544077e 301 */
c392540b 302 public TmfTimeRange getTimeRange() {
f8177ba2
FC
303 return new TmfTimeRange(
304 new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE),
305 new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE));
c392540b
FC
306 }
307
95aa81ef
JCK
308 /**
309 * get the show lost events action
310 *
311 * @return The action object
46a59db7 312 * @since 2.2
95aa81ef
JCK
313 */
314 public Action getShowLostEventsAction() {
315 if (hideLostEventsAction == null) {
316 /* show lost events */
317 hideLostEventsAction = new Action(Messages.HistogramView_hideLostEvents, IAction.AS_CHECK_BOX) {
318 @Override
319 public void run() {
320 HistogramScaledData.hideLostEvents = hideLostEventsAction.isChecked();
321 long maxNbEvents = HistogramScaledData.hideLostEvents ? fFullTraceHistogram.fScaledData.fMaxValue : fFullTraceHistogram.fScaledData.fMaxCombinedValue;
322 fFullTraceHistogram.getMaxNbEventsText().setText(Long.toString(maxNbEvents));
323 fFullTraceHistogram.getMaxNbEventsText().getParent().layout();
324 fFullTraceHistogram.fCanvas.redraw();
325 maxNbEvents = HistogramScaledData.hideLostEvents ? fTimeRangeHistogram.fScaledData.fMaxValue : fTimeRangeHistogram.fScaledData.fMaxCombinedValue;
326 fTimeRangeHistogram.getMaxNbEventsText().setText(Long.toString(maxNbEvents));
327 fTimeRangeHistogram.getMaxNbEventsText().getParent().layout();
328 fTimeRangeHistogram.fCanvas.redraw();
329 }
330 };
331 hideLostEventsAction.setText(Messages.HistogramView_hideLostEvents);
332 hideLostEventsAction.setToolTipText(Messages.HistogramView_hideLostEvents);
333 hideLostEventsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LOST_EVENTS));
334 }
335 return hideLostEventsAction;
336 }
337
c392540b
FC
338 // ------------------------------------------------------------------------
339 // Operations
340 // ------------------------------------------------------------------------
341
b544077e 342 /**
0fcf3b09
PT
343 * Broadcast TmfSignal about new current selection time range.
344 * @param beginTime the begin time of current selection.
345 * @param endTime the end time of current selection.
b544077e 346 */
0fcf3b09
PT
347 void updateSelectionTime(long beginTime, long endTime) {
348 updateDisplayedSelectionTime(beginTime, endTime);
349 TmfTimestamp beginTs = new TmfTimestamp(beginTime, ITmfTimestamp.NANOSECOND_SCALE);
350 TmfTimestamp endTs = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE);
351 TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, beginTs, endTs);
352 fTimeSyncThrottle.queue(signal);
c392540b
FC
353 }
354
b544077e 355 /**
0fcf3b09 356 * Broadcast TmfSignal about new selection time range.
b544077e
BH
357 * @param startTime the new start time
358 * @param endTime the new end time
359 */
f8177ba2 360 void updateTimeRange(long startTime, long endTime) {
faa38350 361 if (fTrace != null) {
c392540b 362 // Build the new time range; keep the current time
f8177ba2
FC
363 TmfTimeRange timeRange = new TmfTimeRange(
364 new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE),
365 new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE));
c392540b
FC
366 fTimeSpanControl.setValue(endTime - startTime);
367
38df2c82
AM
368 updateDisplayedTimeRange(startTime, endTime);
369
c392540b 370 // Send the FW signal
0fcf3b09 371 TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange);
38df2c82 372 fTimeRangeSyncThrottle.queue(signal);
c392540b
FC
373 }
374 }
375
b544077e
BH
376 /**
377 * Broadcast TmfSignal about new selected time range.
378 * @param newDuration new duration (relative to current start time)
379 */
c392540b 380 public synchronized void updateTimeRange(long newDuration) {
faa38350 381 if (fTrace != null) {
6a13fa07 382 long delta = newDuration - fWindowSpan;
1c6a842a 383 long newStartTime = fWindowStartTime - (delta / 2);
6a13fa07 384 setNewRange(newStartTime, newDuration);
c392540b
FC
385 }
386 }
387
388 private void setNewRange(long startTime, long duration) {
41b5c37f
AM
389 long realStart = startTime;
390
391 if (realStart < fTraceStartTime) {
392 realStart = fTraceStartTime;
1b055dfa 393 }
c392540b 394
41b5c37f 395 long endTime = realStart + duration;
faa38350
PT
396 if (endTime > fTraceEndTime) {
397 endTime = fTraceEndTime;
1c6a842a 398 if ((endTime - duration) > fTraceStartTime) {
41b5c37f 399 realStart = endTime - duration;
1b055dfa 400 } else {
41b5c37f 401 realStart = fTraceStartTime;
6a13fa07 402 }
c392540b 403 }
41b5c37f 404 updateTimeRange(realStart, endTime);
833a21aa 405 }
c392540b
FC
406
407 // ------------------------------------------------------------------------
408 // Signal handlers
409 // ------------------------------------------------------------------------
410
b544077e 411 /**
faa38350 412 * Handles trace opened signal. Loads histogram if new trace time range is not
b544077e 413 * equal <code>TmfTimeRange.NULL_RANGE</code>
fec1ac0b 414 * @param signal the trace opened signal
faa38350 415 * @since 2.0
b544077e 416 */
1406f802 417 @TmfSignalHandler
faa38350 418 public void traceOpened(TmfTraceOpenedSignal signal) {
c392540b 419 assert (signal != null);
faa38350
PT
420 fTrace = signal.getTrace();
421 loadTrace();
ecfd1d41 422 }
550d787e 423
faa38350
PT
424 /**
425 * Handles trace selected signal. Loads histogram if new trace time range is not
426 * equal <code>TmfTimeRange.NULL_RANGE</code>
427 * @param signal the trace selected signal
428 * @since 2.0
429 */
430 @TmfSignalHandler
431 public void traceSelected(TmfTraceSelectedSignal signal) {
432 assert (signal != null);
433 if (fTrace != signal.getTrace()) {
434 fTrace = signal.getTrace();
435 loadTrace();
436 }
437 }
438
439 private void loadTrace() {
c392540b
FC
440 initializeHistograms();
441 fParent.redraw();
550d787e
FC
442 }
443
ea279a69 444 /**
faa38350
PT
445 * Handles trace closed signal. Clears the view and data model and cancels requests.
446 * @param signal the trace closed signal
ea279a69
FC
447 * @since 2.0
448 */
449 @TmfSignalHandler
faa38350
PT
450 public void traceClosed(TmfTraceClosedSignal signal) {
451
452 if (signal.getTrace() != fTrace) {
453 return;
454 }
ea279a69
FC
455
456 // Kill any running request
457 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
458 fTimeRangeRequest.cancel();
459 }
460 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
461 fFullTraceRequest.cancel();
462 }
463
464 // Initialize the internal data
faa38350
PT
465 fTrace = null;
466 fTraceStartTime = 0L;
467 fTraceEndTime = 0L;
f8177ba2
FC
468 fWindowStartTime = 0L;
469 fWindowEndTime = 0L;
d7ee91bb 470 fWindowSpan = 0L;
0fcf3b09
PT
471 fSelectionBeginTime = 0L;
472 fSelectionEndTime = 0L;
ea279a69
FC
473
474 // Clear the UI widgets
475 fFullTraceHistogram.clear();
476 fTimeRangeHistogram.clear();
da7bdcbc 477 fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
f8177ba2 478
da7bdcbc 479 fTimeSpanControl.setValue(Long.MIN_VALUE);
ea279a69
FC
480 }
481
b544077e 482 /**
faa38350 483 * Handles trace range updated signal. Extends histogram according to the new time range. If a
b544077e
BH
484 * HistogramRequest is already ongoing, it will be cancelled and a new request with the new range
485 * will be issued.
abbdd66a 486 *
faa38350
PT
487 * @param signal the trace range updated signal
488 * @since 2.0
b544077e 489 */
74237cc3 490 @TmfSignalHandler
faa38350 491 public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) {
74237cc3 492
faa38350 493 if (signal.getTrace() != fTrace) {
09d11238
PT
494 return;
495 }
496
74237cc3
FC
497 TmfTimeRange fullRange = signal.getRange();
498
faa38350
PT
499 fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
500 fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
74237cc3 501
faa38350
PT
502 fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
503 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
74237cc3 504
74237cc3
FC
505 sendFullRangeRequest(fullRange);
506 }
c392540b 507
b544077e 508 /**
faa38350
PT
509 * Handles the trace updated signal. Used to update time limits (start and end time)
510 * @param signal the trace updated signal
511 * @since 2.0
b544077e 512 */
a28d503d 513 @TmfSignalHandler
faa38350
PT
514 public void traceUpdated(TmfTraceUpdatedSignal signal) {
515 if (signal.getTrace() != fTrace) {
a28d503d
PT
516 return;
517 }
faa38350
PT
518 TmfTimeRange fullRange = signal.getTrace().getTimeRange();
519 fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
520 fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
a28d503d 521
faa38350
PT
522 fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
523 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
524
13ccc36b 525 fFullTraceHistogram.setTimeRange(fTimeRangeHistogram.getStartTime(), fWindowSpan);
15844a4e 526 fTimeRangeHistogram.setTimeRange(fTimeRangeHistogram.getStartTime(), fWindowSpan);
13ccc36b 527
faa38350
PT
528 if ((fFullTraceRequest != null) && fFullTraceRequest.getRange().getEndTime().compareTo(signal.getRange().getEndTime()) < 0) {
529 sendFullRangeRequest(fullRange);
530 }
531}
a28d503d 532
b544077e
BH
533 /**
534 * Handles the current time updated signal. Sets the current time in the time range
535 * histogram as well as the full histogram.
abbdd66a 536 *
b544077e
BH
537 * @param signal the signal to process
538 */
c392540b
FC
539 @TmfSignalHandler
540 public void currentTimeUpdated(TmfTimeSynchSignal signal) {
541 // Because this can't happen :-)
542 assert (signal != null);
543
0fcf3b09
PT
544 // Update the selected time range
545 ITmfTimestamp beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
546 ITmfTimestamp endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
547 updateDisplayedSelectionTime(beginTime.getValue(), endTime.getValue());
ecfd1d41 548 }
f05aabed 549
b544077e
BH
550 /**
551 * Updates the current time range in the time range histogram and full range histogram.
552 * @param signal the signal to process
553 */
c392540b
FC
554 @TmfSignalHandler
555 public void timeRangeUpdated(TmfRangeSynchSignal signal) {
556 // Because this can't happen :-)
557 assert (signal != null);
558
faa38350 559 if (fTrace != null) {
1c6a842a
PT
560 // Validate the time range
561 TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange());
562 if (range == null) {
563 return;
564 }
565
38df2c82
AM
566 updateDisplayedTimeRange(
567 range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(),
568 range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
c392540b 569
38df2c82 570 // Send the event request to populate the small histogram
c392540b 571 sendTimeRangeRequest(fWindowStartTime, fWindowEndTime);
f8177ba2 572
c392540b
FC
573 fTimeSpanControl.setValue(fWindowSpan);
574 }
b59134e1 575 }
c392540b
FC
576
577 // ------------------------------------------------------------------------
578 // Helper functions
579 // ------------------------------------------------------------------------
580
581 private void initializeHistograms() {
faa38350 582 TmfTimeRange fullRange = updateTraceTimeRange();
0fcf3b09
PT
583 long selectionBeginTime = fTraceManager.getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
584 long selectionEndTime = fTraceManager.getSelectionEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
248af329
AM
585 long startTime = fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
586 long duration = fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue() - startTime;
74237cc3 587
faa38350
PT
588 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
589 fTimeRangeRequest.cancel();
590 }
74237cc3 591 fTimeRangeHistogram.clear();
faa38350 592 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
d7ee91bb 593 fTimeRangeHistogram.setTimeRange(startTime, duration);
0fcf3b09 594 fTimeRangeHistogram.setSelection(selectionBeginTime, selectionEndTime);
c392540b 595
faa38350
PT
596 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
597 fFullTraceRequest.cancel();
598 }
74237cc3 599 fFullTraceHistogram.clear();
faa38350 600 fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
d7ee91bb 601 fFullTraceHistogram.setTimeRange(startTime, duration);
0fcf3b09 602 fFullTraceHistogram.setSelection(selectionBeginTime, selectionEndTime);
c392540b 603
d7ee91bb
PT
604 fWindowStartTime = startTime;
605 fWindowSpan = duration;
606 fWindowEndTime = startTime + duration;
6a13fa07 607
0fcf3b09
PT
608 fSelectionBeginTime = selectionBeginTime;
609 fSelectionEndTime = selectionEndTime;
610 fCurrentEventTimeControl.setValue(fSelectionBeginTime);
f8177ba2 611
d7ee91bb 612 fTimeSpanControl.setValue(duration);
6a13fa07 613
2af7df97 614 if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) {
d7ee91bb 615 sendTimeRangeRequest(startTime, startTime + duration);
2af7df97
FC
616 sendFullRangeRequest(fullRange);
617 }
74237cc3
FC
618 }
619
0fcf3b09
PT
620 private void updateDisplayedSelectionTime(long beginTime, long endTime) {
621 fSelectionBeginTime = beginTime;
622 fSelectionEndTime = endTime;
38df2c82 623
0fcf3b09
PT
624 fFullTraceHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime);
625 fTimeRangeHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime);
626 fCurrentEventTimeControl.setValue(fSelectionBeginTime);
38df2c82
AM
627 }
628
629 private void updateDisplayedTimeRange(long start, long end) {
630 fWindowStartTime = start;
631 fWindowEndTime = end;
632 fWindowSpan = fWindowEndTime - fWindowStartTime;
633 fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan);
634 }
635
faa38350
PT
636 private TmfTimeRange updateTraceTimeRange() {
637 fTraceStartTime = 0L;
638 fTraceEndTime = 0L;
74237cc3 639
faa38350 640 TmfTimeRange timeRange = fTrace.getTimeRange();
c6023803 641 if (!timeRange.equals(TmfTimeRange.NULL_RANGE)) {
faa38350
PT
642 fTraceStartTime = timeRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
643 fTraceEndTime = timeRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
74237cc3
FC
644 }
645 return timeRange;
b59134e1 646 }
c392540b
FC
647
648 private void sendTimeRangeRequest(long startTime, long endTime) {
1b055dfa 649 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
c392540b 650 fTimeRangeRequest.cancel();
088c1d4e 651 }
f8177ba2
FC
652 TmfTimestamp startTS = new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE);
653 TmfTimestamp endTS = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE);
c392540b
FC
654 TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS);
655
656 fTimeRangeHistogram.clear();
15844a4e 657 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
c392540b 658 fTimeRangeHistogram.setTimeRange(startTime, endTime - startTime);
4cf201de 659
faa38350 660 int cacheSize = fTrace.getCacheSize();
95aa81ef 661 fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(), timeRange, 0, TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND, false);
faa38350 662 fTrace.sendRequest(fTimeRangeRequest);
088c1d4e 663 }
c392540b 664
74237cc3 665 private void sendFullRangeRequest(TmfTimeRange fullRange) {
1b055dfa 666 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
c392540b
FC
667 fFullTraceRequest.cancel();
668 }
faa38350 669 int cacheSize = fTrace.getCacheSize();
fbd124dd 670 fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(), fullRange, (int) fFullTraceHistogram.fDataModel.getNbEvents(),
95aa81ef 671 TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.BACKGROUND, true);
faa38350 672 fTrace.sendRequest(fFullTraceRequest);
ed4b3b9f 673 }
c392540b 674
95aa81ef
JCK
675 private void contributeToActionBars() {
676 IActionBars bars = getViewSite().getActionBars();
677 bars.getToolBarManager().add(getShowLostEventsAction());
678 bars.getToolBarManager().add(new Separator());
679 }
680
6e512b93 681}
This page took 0.090908 seconds and 5 git commands to generate.