Commit | Line | Data |
---|---|---|
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 |
2fc582d2 | 17 | * Xavier Raynaud - Support multi-trace coloring |
6e512b93 | 18 | *******************************************************************************/ |
3e9fdb8b | 19 | |
e0752744 | 20 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
6e512b93 | 21 | |
95aa81ef JCK |
22 | import org.eclipse.jface.action.Action; |
23 | import org.eclipse.jface.action.IAction; | |
24 | import org.eclipse.jface.action.Separator; | |
25 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; | |
26 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; | |
2740e05c | 27 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; |
fd3f1eff | 28 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType; |
6c13869b FC |
29 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; |
30 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
38df2c82 | 31 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler; |
6c13869b | 32 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; |
faa38350 PT |
33 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; |
34 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
35 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; | |
36 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; | |
37 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; | |
3bd46eef AM |
38 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
39 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
40 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
faa38350 | 41 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
2fc582d2 | 42 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
b59134e1 WB |
43 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
44 | import org.eclipse.swt.SWT; | |
2fc582d2 | 45 | import org.eclipse.swt.custom.CLabel; |
720d67cb PT |
46 | import org.eclipse.swt.events.MouseAdapter; |
47 | import org.eclipse.swt.events.MouseEvent; | |
65cdf787 | 48 | import org.eclipse.swt.events.MouseWheelListener; |
720d67cb PT |
49 | import org.eclipse.swt.events.PaintEvent; |
50 | import org.eclipse.swt.events.PaintListener; | |
2fc582d2 | 51 | import org.eclipse.swt.graphics.GC; |
720d67cb PT |
52 | import org.eclipse.swt.graphics.Image; |
53 | import org.eclipse.swt.graphics.Rectangle; | |
b59134e1 | 54 | import org.eclipse.swt.layout.GridData; |
252ae4bd | 55 | import org.eclipse.swt.layout.GridLayout; |
2fc582d2 | 56 | import org.eclipse.swt.layout.RowLayout; |
6e512b93 | 57 | import org.eclipse.swt.widgets.Composite; |
2fc582d2 | 58 | import org.eclipse.swt.widgets.Control; |
80c930fa | 59 | import org.eclipse.swt.widgets.Display; |
720d67cb | 60 | import org.eclipse.swt.widgets.Label; |
95aa81ef | 61 | import org.eclipse.ui.IActionBars; |
6e512b93 | 62 | |
544fe9b7 | 63 | /** |
faa38350 | 64 | * The purpose of this view is to provide graphical time distribution statistics about the trace events. |
544fe9b7 | 65 | * <p> |
c392540b FC |
66 | * The view is composed of two histograms and two controls: |
67 | * <ul> | |
faa38350 | 68 | * <li>an event distribution histogram for the whole trace; |
c392540b FC |
69 | * <li>an event distribution histogram for current time window (window span); |
70 | * <li>the timestamp of the currently selected event; | |
71 | * <li>the window span (size of the time window of the smaller histogram). | |
72 | * </ul> | |
73 | * The histograms x-axis show their respective time range. | |
abbdd66a | 74 | * |
f8177ba2 | 75 | * @version 2.0 |
2af7df97 | 76 | * @author Francois Chouinard |
544fe9b7 | 77 | */ |
c392540b FC |
78 | public class HistogramView extends TmfView { |
79 | ||
80 | // ------------------------------------------------------------------------ | |
81 | // Constants | |
82 | // ------------------------------------------------------------------------ | |
83 | ||
b544077e BH |
84 | /** |
85 | * The view ID as defined in plugin.xml | |
86 | */ | |
e0752744 | 87 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$ |
c392540b | 88 | |
720d67cb PT |
89 | private static final Image LINK_IMG = Activator.getDefault().getImageFromPath("/icons/etool16/link.gif"); //$NON-NLS-1$ |
90 | ||
c392540b FC |
91 | // ------------------------------------------------------------------------ |
92 | // Attributes | |
93 | // ------------------------------------------------------------------------ | |
94 | ||
95 | // Parent widget | |
96 | private Composite fParent; | |
97 | ||
faa38350 PT |
98 | // The current trace |
99 | private ITmfTrace fTrace; | |
c392540b | 100 | |
f8177ba2 | 101 | // Current timestamp/time window - everything in the TIME_SCALE |
faa38350 PT |
102 | private long fTraceStartTime; |
103 | private long fTraceEndTime; | |
c392540b FC |
104 | private long fWindowStartTime; |
105 | private long fWindowEndTime; | |
d7ee91bb | 106 | private long fWindowSpan; |
0fcf3b09 PT |
107 | private long fSelectionBeginTime; |
108 | private long fSelectionEndTime; | |
c392540b FC |
109 | |
110 | // Time controls | |
720d67cb PT |
111 | private HistogramTextControl fSelectionStartControl; |
112 | private HistogramTextControl fSelectionEndControl; | |
c392540b FC |
113 | private HistogramTextControl fTimeSpanControl; |
114 | ||
720d67cb PT |
115 | // Link |
116 | private Label fLinkButton; | |
117 | private boolean fLinkState; | |
118 | ||
c392540b FC |
119 | // Histogram/request for the full trace range |
120 | private static FullTraceHistogram fFullTraceHistogram; | |
121 | private HistogramRequest fFullTraceRequest; | |
122 | ||
123 | // Histogram/request for the selected time range | |
124 | private static TimeRangeHistogram fTimeRangeHistogram; | |
125 | private HistogramRequest fTimeRangeRequest; | |
126 | ||
2fc582d2 XR |
127 | // Legend area |
128 | private Composite fLegendArea; | |
129 | private Image[] fLegendImages; | |
130 | ||
38df2c82 AM |
131 | // Throttlers for the time sync and time-range sync signals |
132 | private final TmfSignalThrottler fTimeSyncThrottle; | |
133 | private final TmfSignalThrottler fTimeRangeSyncThrottle; | |
134 | ||
95aa81ef JCK |
135 | // Action for toggle showing the lost events |
136 | private Action hideLostEventsAction; | |
2fc582d2 XR |
137 | // Action for toggle showing the traces |
138 | private Action showTraceAction; | |
95aa81ef | 139 | |
c392540b FC |
140 | // ------------------------------------------------------------------------ |
141 | // Constructor | |
142 | // ------------------------------------------------------------------------ | |
143 | ||
b544077e BH |
144 | /** |
145 | * Default constructor | |
146 | */ | |
c392540b FC |
147 | public HistogramView() { |
148 | super(ID); | |
38df2c82 AM |
149 | fTimeSyncThrottle = new TmfSignalThrottler(this, 200); |
150 | fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200); | |
c392540b FC |
151 | } |
152 | ||
6a13fa07 | 153 | @Override |
c392540b | 154 | public void dispose() { |
1b055dfa | 155 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
4dc47e28 FC |
156 | fTimeRangeRequest.cancel(); |
157 | } | |
1b055dfa | 158 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
4dc47e28 FC |
159 | fFullTraceRequest.cancel(); |
160 | } | |
6a13fa07 FC |
161 | fFullTraceHistogram.dispose(); |
162 | fTimeRangeHistogram.dispose(); | |
720d67cb PT |
163 | fSelectionStartControl.dispose(); |
164 | fSelectionEndControl.dispose(); | |
f8177ba2 | 165 | fTimeSpanControl.dispose(); |
4dc47e28 | 166 | super.dispose(); |
c392540b FC |
167 | } |
168 | ||
169 | // ------------------------------------------------------------------------ | |
170 | // TmfView | |
171 | // ------------------------------------------------------------------------ | |
172 | ||
173 | @Override | |
c392540b FC |
174 | public void createPartControl(Composite parent) { |
175 | ||
176 | fParent = parent; | |
177 | ||
178 | // Control labels | |
720d67cb PT |
179 | final String selectionStartLabel = Messages.HistogramView_selectionStartLabel; |
180 | final String selectionEndLabel = Messages.HistogramView_selectionEndLabel; | |
c392540b FC |
181 | final String windowSpanLabel = Messages.HistogramView_windowSpanLabel; |
182 | ||
183 | // -------------------------------------------------------------------- | |
184 | // Set the HistogramView layout | |
185 | // -------------------------------------------------------------------- | |
186 | ||
187 | Composite viewComposite = new Composite(fParent, SWT.FILL); | |
188 | GridLayout gridLayout = new GridLayout(); | |
189 | gridLayout.numColumns = 2; | |
190 | gridLayout.horizontalSpacing = 5; | |
191 | gridLayout.verticalSpacing = 0; | |
192 | gridLayout.marginHeight = 0; | |
193 | gridLayout.marginWidth = 0; | |
194 | viewComposite.setLayout(gridLayout); | |
195 | ||
c392540b FC |
196 | // -------------------------------------------------------------------- |
197 | // Time controls | |
198 | // -------------------------------------------------------------------- | |
199 | ||
720d67cb | 200 | Composite controlsComposite = new Composite(viewComposite, SWT.NONE); |
c392540b FC |
201 | gridLayout = new GridLayout(); |
202 | gridLayout.numColumns = 2; | |
203 | gridLayout.marginHeight = 0; | |
204 | gridLayout.marginWidth = 0; | |
205 | gridLayout.horizontalSpacing = 5; | |
720d67cb | 206 | gridLayout.verticalSpacing = 1; |
f8177ba2 | 207 | gridLayout.makeColumnsEqualWidth = false; |
c392540b | 208 | controlsComposite.setLayout(gridLayout); |
720d67cb PT |
209 | GridData gridData = new GridData(SWT.FILL, SWT.CENTER, false, false); |
210 | controlsComposite.setLayoutData(gridData); | |
211 | ||
212 | Composite selectionGroup = new Composite(controlsComposite, SWT.BORDER); | |
213 | gridLayout = new GridLayout(); | |
214 | gridLayout.marginHeight = 0; | |
215 | gridLayout.marginWidth = 0; | |
216 | gridLayout.horizontalSpacing = 0; | |
217 | gridLayout.verticalSpacing = 0; | |
218 | selectionGroup.setLayout(gridLayout); | |
c392540b | 219 | |
720d67cb | 220 | // Selection start control |
c392540b | 221 | gridData = new GridData(); |
720d67cb PT |
222 | gridData.horizontalAlignment = SWT.FILL; |
223 | gridData.verticalAlignment = SWT.CENTER; | |
224 | fSelectionStartControl = new HistogramSelectionStartControl(this, selectionGroup, selectionStartLabel, 0L); | |
225 | fSelectionStartControl.setLayoutData(gridData); | |
226 | fSelectionStartControl.setValue(Long.MIN_VALUE); | |
227 | ||
228 | // Selection end control | |
229 | gridData = new GridData(); | |
230 | gridData.horizontalAlignment = SWT.FILL; | |
c392540b | 231 | gridData.verticalAlignment = SWT.CENTER; |
720d67cb PT |
232 | fSelectionEndControl = new HistogramSelectionEndControl(this, selectionGroup, selectionEndLabel, 0L); |
233 | fSelectionEndControl.setLayoutData(gridData); | |
234 | fSelectionEndControl.setValue(Long.MIN_VALUE); | |
235 | ||
236 | // Link button | |
237 | gridData = new GridData(); | |
238 | fLinkButton = new Label(controlsComposite, SWT.NONE); | |
239 | fLinkButton.setImage(LINK_IMG); | |
240 | fLinkButton.setLayoutData(gridData); | |
241 | addLinkButtonListeners(); | |
c392540b FC |
242 | |
243 | // Window span time control | |
244 | gridData = new GridData(); | |
720d67cb | 245 | gridData.horizontalAlignment = SWT.FILL; |
c392540b | 246 | gridData.verticalAlignment = SWT.CENTER; |
f8177ba2 | 247 | fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L); |
c392540b | 248 | fTimeSpanControl.setLayoutData(gridData); |
da7bdcbc | 249 | fTimeSpanControl.setValue(Long.MIN_VALUE); |
c392540b FC |
250 | |
251 | // -------------------------------------------------------------------- | |
252 | // Time range histogram | |
253 | // -------------------------------------------------------------------- | |
254 | ||
720d67cb | 255 | Composite timeRangeComposite = new Composite(viewComposite, SWT.NONE); |
c392540b FC |
256 | gridLayout = new GridLayout(); |
257 | gridLayout.numColumns = 1; | |
258 | gridLayout.marginHeight = 0; | |
259 | gridLayout.marginWidth = 0; | |
260 | gridLayout.marginTop = 5; | |
261 | gridLayout.horizontalSpacing = 0; | |
262 | gridLayout.verticalSpacing = 0; | |
263 | gridLayout.marginLeft = 5; | |
264 | gridLayout.marginRight = 5; | |
265 | timeRangeComposite.setLayout(gridLayout); | |
266 | ||
267 | // Use remaining horizontal space | |
268 | gridData = new GridData(); | |
269 | gridData.horizontalAlignment = SWT.FILL; | |
270 | gridData.verticalAlignment = SWT.FILL; | |
271 | gridData.grabExcessHorizontalSpace = true; | |
3a790c10 | 272 | gridData.grabExcessVerticalSpace = true; |
c392540b FC |
273 | timeRangeComposite.setLayoutData(gridData); |
274 | ||
275 | // Histogram | |
276 | fTimeRangeHistogram = new TimeRangeHistogram(this, timeRangeComposite); | |
277 | ||
278 | // -------------------------------------------------------------------- | |
279 | // Full range histogram | |
280 | // -------------------------------------------------------------------- | |
281 | ||
282 | Composite fullRangeComposite = new Composite(viewComposite, SWT.FILL); | |
283 | gridLayout = new GridLayout(); | |
284 | gridLayout.numColumns = 1; | |
285 | gridLayout.marginHeight = 0; | |
286 | gridLayout.marginWidth = 0; | |
287 | gridLayout.marginTop = 5; | |
288 | gridLayout.horizontalSpacing = 0; | |
289 | gridLayout.verticalSpacing = 0; | |
290 | gridLayout.marginLeft = 5; | |
291 | gridLayout.marginRight = 5; | |
292 | fullRangeComposite.setLayout(gridLayout); | |
293 | ||
294 | // Use remaining horizontal space | |
295 | gridData = new GridData(); | |
296 | gridData.horizontalAlignment = SWT.FILL; | |
297 | gridData.verticalAlignment = SWT.FILL; | |
298 | gridData.horizontalSpan = 2; | |
299 | gridData.grabExcessHorizontalSpace = true; | |
3a790c10 | 300 | gridData.grabExcessVerticalSpace = true; |
c392540b FC |
301 | fullRangeComposite.setLayoutData(gridData); |
302 | ||
303 | // Histogram | |
304 | fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite); | |
305 | ||
2fc582d2 XR |
306 | fLegendArea = new Composite(viewComposite, SWT.FILL); |
307 | fLegendArea.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1)); | |
308 | fLegendArea.setLayout(new RowLayout()); | |
309 | ||
65cdf787 PT |
310 | // Add mouse wheel listener to time span control |
311 | MouseWheelListener listener = fFullTraceHistogram.getZoom(); | |
312 | fTimeSpanControl.addMouseWheelListener(listener); | |
313 | ||
95aa81ef JCK |
314 | |
315 | // View Action Handling | |
316 | contributeToActionBars(); | |
317 | ||
3ac5721a AM |
318 | ITmfTrace trace = getActiveTrace(); |
319 | if (trace != null) { | |
320 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
1b055dfa | 321 | } |
ecfd1d41 | 322 | } |
c392540b FC |
323 | |
324 | @Override | |
c392540b | 325 | public void setFocus() { |
faa38350 | 326 | fFullTraceHistogram.fCanvas.setFocus(); |
833a21aa | 327 | } |
c392540b | 328 | |
f8177ba2 FC |
329 | void refresh() { |
330 | fParent.layout(true); | |
331 | } | |
332 | ||
c392540b FC |
333 | // ------------------------------------------------------------------------ |
334 | // Accessors | |
335 | // ------------------------------------------------------------------------ | |
336 | ||
faa38350 PT |
337 | /** |
338 | * Returns the current trace handled by the view | |
339 | * | |
340 | * @return the current trace | |
341 | * @since 2.0 | |
342 | */ | |
343 | public ITmfTrace getTrace() { | |
344 | return fTrace; | |
345 | } | |
346 | ||
b544077e BH |
347 | /** |
348 | * Returns the time range of the current selected window (base on default time scale). | |
abbdd66a | 349 | * |
b544077e | 350 | * @return the time range of current selected window. |
3bd46eef | 351 | * @since 2.0 |
b544077e | 352 | */ |
c392540b | 353 | public TmfTimeRange getTimeRange() { |
f8177ba2 FC |
354 | return new TmfTimeRange( |
355 | new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE), | |
356 | new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE)); | |
c392540b FC |
357 | } |
358 | ||
95aa81ef JCK |
359 | /** |
360 | * get the show lost events action | |
361 | * | |
362 | * @return The action object | |
46a59db7 | 363 | * @since 2.2 |
95aa81ef JCK |
364 | */ |
365 | public Action getShowLostEventsAction() { | |
366 | if (hideLostEventsAction == null) { | |
367 | /* show lost events */ | |
368 | hideLostEventsAction = new Action(Messages.HistogramView_hideLostEvents, IAction.AS_CHECK_BOX) { | |
369 | @Override | |
370 | public void run() { | |
371 | HistogramScaledData.hideLostEvents = hideLostEventsAction.isChecked(); | |
372 | long maxNbEvents = HistogramScaledData.hideLostEvents ? fFullTraceHistogram.fScaledData.fMaxValue : fFullTraceHistogram.fScaledData.fMaxCombinedValue; | |
3311a6ca | 373 | fFullTraceHistogram.setMaxNbEvents(maxNbEvents); |
95aa81ef | 374 | maxNbEvents = HistogramScaledData.hideLostEvents ? fTimeRangeHistogram.fScaledData.fMaxValue : fTimeRangeHistogram.fScaledData.fMaxCombinedValue; |
3311a6ca | 375 | fTimeRangeHistogram.setMaxNbEvents(maxNbEvents); |
95aa81ef JCK |
376 | } |
377 | }; | |
378 | hideLostEventsAction.setText(Messages.HistogramView_hideLostEvents); | |
379 | hideLostEventsAction.setToolTipText(Messages.HistogramView_hideLostEvents); | |
380 | hideLostEventsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LOST_EVENTS)); | |
381 | } | |
382 | return hideLostEventsAction; | |
383 | } | |
384 | ||
2fc582d2 XR |
385 | /** |
386 | * get the show trace action | |
387 | * | |
388 | * @return The action object | |
389 | * @since 3.0 | |
390 | */ | |
391 | public Action getShowTraceAction() { | |
392 | if (showTraceAction == null) { | |
393 | /* show lost events */ | |
394 | showTraceAction = new Action(Messages.HistogramView_showTraces, IAction.AS_CHECK_BOX) { | |
395 | @Override | |
396 | public void run() { | |
397 | Histogram.showTraces = showTraceAction.isChecked(); | |
398 | fFullTraceHistogram.fCanvas.redraw(); | |
399 | fTimeRangeHistogram.fCanvas.redraw(); | |
400 | updateLegendArea(); | |
401 | } | |
402 | }; | |
403 | showTraceAction.setChecked(true); | |
404 | showTraceAction.setText(Messages.HistogramView_showTraces); | |
405 | showTraceAction.setToolTipText(Messages.HistogramView_showTraces); | |
406 | showTraceAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_HIST_TRACES)); | |
407 | } | |
408 | return showTraceAction; | |
409 | } | |
410 | ||
c392540b FC |
411 | // ------------------------------------------------------------------------ |
412 | // Operations | |
413 | // ------------------------------------------------------------------------ | |
414 | ||
b544077e | 415 | /** |
0fcf3b09 PT |
416 | * Broadcast TmfSignal about new current selection time range. |
417 | * @param beginTime the begin time of current selection. | |
418 | * @param endTime the end time of current selection. | |
b544077e | 419 | */ |
0fcf3b09 PT |
420 | void updateSelectionTime(long beginTime, long endTime) { |
421 | updateDisplayedSelectionTime(beginTime, endTime); | |
422 | TmfTimestamp beginTs = new TmfTimestamp(beginTime, ITmfTimestamp.NANOSECOND_SCALE); | |
423 | TmfTimestamp endTs = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE); | |
424 | TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, beginTs, endTs); | |
425 | fTimeSyncThrottle.queue(signal); | |
c392540b FC |
426 | } |
427 | ||
720d67cb PT |
428 | /** |
429 | * Get selection begin time | |
430 | * @return the begin time of current selection | |
431 | */ | |
432 | long getSelectionBegin() { | |
433 | return fSelectionBeginTime; | |
434 | } | |
435 | ||
436 | /** | |
437 | * Get selection end time | |
438 | * @return the end time of current selection | |
439 | */ | |
440 | long getSelectionEnd() { | |
441 | return fSelectionEndTime; | |
442 | } | |
443 | ||
444 | /** | |
445 | * Get the link state | |
446 | * @return true if begin and end selection time should be linked | |
447 | */ | |
448 | boolean getLinkState() { | |
449 | return fLinkState; | |
450 | } | |
451 | ||
b544077e | 452 | /** |
0fcf3b09 | 453 | * Broadcast TmfSignal about new selection time range. |
b544077e BH |
454 | * @param startTime the new start time |
455 | * @param endTime the new end time | |
456 | */ | |
f8177ba2 | 457 | void updateTimeRange(long startTime, long endTime) { |
faa38350 | 458 | if (fTrace != null) { |
c392540b | 459 | // Build the new time range; keep the current time |
f8177ba2 FC |
460 | TmfTimeRange timeRange = new TmfTimeRange( |
461 | new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE), | |
462 | new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE)); | |
c392540b FC |
463 | fTimeSpanControl.setValue(endTime - startTime); |
464 | ||
38df2c82 AM |
465 | updateDisplayedTimeRange(startTime, endTime); |
466 | ||
c392540b | 467 | // Send the FW signal |
0fcf3b09 | 468 | TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange); |
38df2c82 | 469 | fTimeRangeSyncThrottle.queue(signal); |
c392540b FC |
470 | } |
471 | } | |
472 | ||
b544077e BH |
473 | /** |
474 | * Broadcast TmfSignal about new selected time range. | |
475 | * @param newDuration new duration (relative to current start time) | |
476 | */ | |
c392540b | 477 | public synchronized void updateTimeRange(long newDuration) { |
faa38350 | 478 | if (fTrace != null) { |
6a13fa07 | 479 | long delta = newDuration - fWindowSpan; |
1c6a842a | 480 | long newStartTime = fWindowStartTime - (delta / 2); |
6a13fa07 | 481 | setNewRange(newStartTime, newDuration); |
c392540b FC |
482 | } |
483 | } | |
484 | ||
485 | private void setNewRange(long startTime, long duration) { | |
41b5c37f AM |
486 | long realStart = startTime; |
487 | ||
488 | if (realStart < fTraceStartTime) { | |
489 | realStart = fTraceStartTime; | |
1b055dfa | 490 | } |
c392540b | 491 | |
41b5c37f | 492 | long endTime = realStart + duration; |
faa38350 PT |
493 | if (endTime > fTraceEndTime) { |
494 | endTime = fTraceEndTime; | |
1c6a842a | 495 | if ((endTime - duration) > fTraceStartTime) { |
41b5c37f | 496 | realStart = endTime - duration; |
1b055dfa | 497 | } else { |
41b5c37f | 498 | realStart = fTraceStartTime; |
6a13fa07 | 499 | } |
c392540b | 500 | } |
41b5c37f | 501 | updateTimeRange(realStart, endTime); |
833a21aa | 502 | } |
c392540b FC |
503 | |
504 | // ------------------------------------------------------------------------ | |
505 | // Signal handlers | |
506 | // ------------------------------------------------------------------------ | |
507 | ||
b544077e | 508 | /** |
faa38350 | 509 | * Handles trace opened signal. Loads histogram if new trace time range is not |
b544077e | 510 | * equal <code>TmfTimeRange.NULL_RANGE</code> |
fec1ac0b | 511 | * @param signal the trace opened signal |
faa38350 | 512 | * @since 2.0 |
b544077e | 513 | */ |
1406f802 | 514 | @TmfSignalHandler |
faa38350 | 515 | public void traceOpened(TmfTraceOpenedSignal signal) { |
c392540b | 516 | assert (signal != null); |
faa38350 PT |
517 | fTrace = signal.getTrace(); |
518 | loadTrace(); | |
ecfd1d41 | 519 | } |
550d787e | 520 | |
faa38350 PT |
521 | /** |
522 | * Handles trace selected signal. Loads histogram if new trace time range is not | |
523 | * equal <code>TmfTimeRange.NULL_RANGE</code> | |
524 | * @param signal the trace selected signal | |
525 | * @since 2.0 | |
526 | */ | |
527 | @TmfSignalHandler | |
528 | public void traceSelected(TmfTraceSelectedSignal signal) { | |
529 | assert (signal != null); | |
530 | if (fTrace != signal.getTrace()) { | |
531 | fTrace = signal.getTrace(); | |
532 | loadTrace(); | |
533 | } | |
534 | } | |
535 | ||
536 | private void loadTrace() { | |
c392540b FC |
537 | initializeHistograms(); |
538 | fParent.redraw(); | |
550d787e FC |
539 | } |
540 | ||
ea279a69 | 541 | /** |
faa38350 PT |
542 | * Handles trace closed signal. Clears the view and data model and cancels requests. |
543 | * @param signal the trace closed signal | |
ea279a69 FC |
544 | * @since 2.0 |
545 | */ | |
546 | @TmfSignalHandler | |
faa38350 PT |
547 | public void traceClosed(TmfTraceClosedSignal signal) { |
548 | ||
549 | if (signal.getTrace() != fTrace) { | |
550 | return; | |
551 | } | |
ea279a69 FC |
552 | |
553 | // Kill any running request | |
554 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { | |
555 | fTimeRangeRequest.cancel(); | |
556 | } | |
557 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { | |
558 | fFullTraceRequest.cancel(); | |
559 | } | |
560 | ||
561 | // Initialize the internal data | |
faa38350 PT |
562 | fTrace = null; |
563 | fTraceStartTime = 0L; | |
564 | fTraceEndTime = 0L; | |
f8177ba2 FC |
565 | fWindowStartTime = 0L; |
566 | fWindowEndTime = 0L; | |
d7ee91bb | 567 | fWindowSpan = 0L; |
0fcf3b09 PT |
568 | fSelectionBeginTime = 0L; |
569 | fSelectionEndTime = 0L; | |
ea279a69 FC |
570 | |
571 | // Clear the UI widgets | |
572 | fFullTraceHistogram.clear(); | |
573 | fTimeRangeHistogram.clear(); | |
720d67cb PT |
574 | fSelectionStartControl.setValue(Long.MIN_VALUE); |
575 | fSelectionEndControl.setValue(Long.MIN_VALUE); | |
f8177ba2 | 576 | |
da7bdcbc | 577 | fTimeSpanControl.setValue(Long.MIN_VALUE); |
2fc582d2 XR |
578 | |
579 | for (Control c: fLegendArea.getChildren()) { | |
580 | c.dispose(); | |
581 | } | |
582 | if (fLegendImages != null) { | |
583 | for (Image i: fLegendImages) { | |
584 | i.dispose(); | |
585 | } | |
586 | } | |
587 | fLegendImages = null; | |
588 | fLegendArea.layout(); | |
589 | fLegendArea.getParent().layout(); | |
ea279a69 FC |
590 | } |
591 | ||
b544077e | 592 | /** |
faa38350 | 593 | * Handles trace range updated signal. Extends histogram according to the new time range. If a |
b544077e BH |
594 | * HistogramRequest is already ongoing, it will be cancelled and a new request with the new range |
595 | * will be issued. | |
abbdd66a | 596 | * |
faa38350 PT |
597 | * @param signal the trace range updated signal |
598 | * @since 2.0 | |
b544077e | 599 | */ |
74237cc3 | 600 | @TmfSignalHandler |
faa38350 | 601 | public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) { |
74237cc3 | 602 | |
faa38350 | 603 | if (signal.getTrace() != fTrace) { |
09d11238 PT |
604 | return; |
605 | } | |
606 | ||
74237cc3 FC |
607 | TmfTimeRange fullRange = signal.getRange(); |
608 | ||
faa38350 PT |
609 | fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
610 | fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
74237cc3 | 611 | |
faa38350 PT |
612 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
613 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); | |
74237cc3 | 614 | |
74237cc3 FC |
615 | sendFullRangeRequest(fullRange); |
616 | } | |
c392540b | 617 | |
b544077e | 618 | /** |
faa38350 PT |
619 | * Handles the trace updated signal. Used to update time limits (start and end time) |
620 | * @param signal the trace updated signal | |
621 | * @since 2.0 | |
b544077e | 622 | */ |
a28d503d | 623 | @TmfSignalHandler |
faa38350 PT |
624 | public void traceUpdated(TmfTraceUpdatedSignal signal) { |
625 | if (signal.getTrace() != fTrace) { | |
a28d503d PT |
626 | return; |
627 | } | |
faa38350 PT |
628 | TmfTimeRange fullRange = signal.getTrace().getTimeRange(); |
629 | fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
630 | fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
a28d503d | 631 | |
faa38350 PT |
632 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
633 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); | |
634 | ||
635 | if ((fFullTraceRequest != null) && fFullTraceRequest.getRange().getEndTime().compareTo(signal.getRange().getEndTime()) < 0) { | |
636 | sendFullRangeRequest(fullRange); | |
637 | } | |
638 | } | |
a28d503d | 639 | |
b544077e BH |
640 | /** |
641 | * Handles the current time updated signal. Sets the current time in the time range | |
642 | * histogram as well as the full histogram. | |
abbdd66a | 643 | * |
b544077e BH |
644 | * @param signal the signal to process |
645 | */ | |
c392540b | 646 | @TmfSignalHandler |
80c930fa PT |
647 | public void currentTimeUpdated(final TmfTimeSynchSignal signal) { |
648 | if (Display.getCurrent() == null) { | |
649 | // Make sure the signal is handled in the UI thread | |
650 | Display.getDefault().asyncExec(new Runnable() { | |
651 | @Override | |
652 | public void run() { | |
653 | if (fParent.isDisposed()) { | |
654 | return; | |
655 | } | |
656 | currentTimeUpdated(signal); | |
657 | } | |
658 | }); | |
659 | return; | |
660 | } | |
c392540b | 661 | |
0fcf3b09 PT |
662 | // Update the selected time range |
663 | ITmfTimestamp beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); | |
664 | ITmfTimestamp endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); | |
665 | updateDisplayedSelectionTime(beginTime.getValue(), endTime.getValue()); | |
ecfd1d41 | 666 | } |
f05aabed | 667 | |
b544077e BH |
668 | /** |
669 | * Updates the current time range in the time range histogram and full range histogram. | |
670 | * @param signal the signal to process | |
671 | */ | |
c392540b | 672 | @TmfSignalHandler |
80c930fa PT |
673 | public void timeRangeUpdated(final TmfRangeSynchSignal signal) { |
674 | if (Display.getCurrent() == null) { | |
675 | // Make sure the signal is handled in the UI thread | |
676 | Display.getDefault().asyncExec(new Runnable() { | |
677 | @Override | |
678 | public void run() { | |
679 | if (fParent.isDisposed()) { | |
680 | return; | |
681 | } | |
682 | timeRangeUpdated(signal); | |
683 | } | |
684 | }); | |
685 | return; | |
686 | } | |
c392540b | 687 | |
faa38350 | 688 | if (fTrace != null) { |
1c6a842a PT |
689 | // Validate the time range |
690 | TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange()); | |
691 | if (range == null) { | |
692 | return; | |
693 | } | |
694 | ||
38df2c82 AM |
695 | updateDisplayedTimeRange( |
696 | range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(), | |
697 | range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue()); | |
c392540b | 698 | |
38df2c82 | 699 | // Send the event request to populate the small histogram |
c392540b | 700 | sendTimeRangeRequest(fWindowStartTime, fWindowEndTime); |
f8177ba2 | 701 | |
c392540b FC |
702 | fTimeSpanControl.setValue(fWindowSpan); |
703 | } | |
b59134e1 | 704 | } |
c392540b FC |
705 | |
706 | // ------------------------------------------------------------------------ | |
707 | // Helper functions | |
708 | // ------------------------------------------------------------------------ | |
709 | ||
710 | private void initializeHistograms() { | |
faa38350 | 711 | TmfTimeRange fullRange = updateTraceTimeRange(); |
0fcf3b09 PT |
712 | long selectionBeginTime = fTraceManager.getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
713 | long selectionEndTime = fTraceManager.getSelectionEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
248af329 AM |
714 | long startTime = fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
715 | long duration = fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue() - startTime; | |
74237cc3 | 716 | |
faa38350 PT |
717 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
718 | fTimeRangeRequest.cancel(); | |
719 | } | |
74237cc3 | 720 | fTimeRangeHistogram.clear(); |
faa38350 | 721 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
d7ee91bb | 722 | fTimeRangeHistogram.setTimeRange(startTime, duration); |
0fcf3b09 | 723 | fTimeRangeHistogram.setSelection(selectionBeginTime, selectionEndTime); |
2fc582d2 | 724 | fTimeRangeHistogram.fDataModel.setTrace(fTrace); |
c392540b | 725 | |
faa38350 PT |
726 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
727 | fFullTraceRequest.cancel(); | |
728 | } | |
74237cc3 | 729 | fFullTraceHistogram.clear(); |
faa38350 | 730 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
d7ee91bb | 731 | fFullTraceHistogram.setTimeRange(startTime, duration); |
0fcf3b09 | 732 | fFullTraceHistogram.setSelection(selectionBeginTime, selectionEndTime); |
2fc582d2 | 733 | fFullTraceHistogram.fDataModel.setTrace(fTrace); |
c392540b | 734 | |
d7ee91bb PT |
735 | fWindowStartTime = startTime; |
736 | fWindowSpan = duration; | |
737 | fWindowEndTime = startTime + duration; | |
6a13fa07 | 738 | |
0fcf3b09 PT |
739 | fSelectionBeginTime = selectionBeginTime; |
740 | fSelectionEndTime = selectionEndTime; | |
720d67cb PT |
741 | fSelectionStartControl.setValue(fSelectionBeginTime); |
742 | fSelectionEndControl.setValue(fSelectionEndTime); | |
f8177ba2 | 743 | |
d7ee91bb | 744 | fTimeSpanControl.setValue(duration); |
6a13fa07 | 745 | |
2fc582d2 XR |
746 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace); |
747 | if (traces != null) { | |
748 | this.showTraceAction.setEnabled(traces.length < fFullTraceHistogram.getMaxNbTraces()); | |
749 | } | |
750 | updateLegendArea(); | |
751 | ||
2af7df97 | 752 | if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) { |
d7ee91bb | 753 | sendTimeRangeRequest(startTime, startTime + duration); |
2af7df97 FC |
754 | sendFullRangeRequest(fullRange); |
755 | } | |
74237cc3 FC |
756 | } |
757 | ||
2fc582d2 XR |
758 | private void updateLegendArea() { |
759 | for (Control c: fLegendArea.getChildren()) { | |
760 | c.dispose(); | |
761 | } | |
762 | if (fLegendImages != null) { | |
763 | for (Image i: fLegendImages) { | |
764 | i.dispose(); | |
765 | } | |
766 | } | |
767 | fLegendImages = null; | |
768 | if (fFullTraceHistogram.showTraces()) { | |
769 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace); | |
770 | fLegendImages = new Image[traces.length]; | |
771 | int traceIndex = 0; | |
772 | for (ITmfTrace trace : traces) { | |
773 | fLegendImages[traceIndex] = new Image(fLegendArea.getDisplay(), 16, 16); | |
774 | GC gc = new GC(fLegendImages[traceIndex]); | |
775 | gc.setBackground(fFullTraceHistogram.getTraceColor(traceIndex)); | |
776 | gc.fillRectangle(0, 0, 15, 15); | |
777 | gc.setForeground(fLegendArea.getDisplay().getSystemColor(SWT.COLOR_BLACK)); | |
778 | gc.drawRectangle(0, 0, 15, 15); | |
779 | gc.dispose(); | |
780 | ||
781 | CLabel label = new CLabel(fLegendArea, SWT.NONE); | |
782 | label.setText(trace.getName()); | |
783 | label.setImage(fLegendImages[traceIndex]); | |
784 | traceIndex++; | |
785 | } | |
786 | } | |
787 | fLegendArea.layout(); | |
788 | fLegendArea.getParent().layout(); | |
789 | } | |
790 | ||
0fcf3b09 PT |
791 | private void updateDisplayedSelectionTime(long beginTime, long endTime) { |
792 | fSelectionBeginTime = beginTime; | |
793 | fSelectionEndTime = endTime; | |
38df2c82 | 794 | |
0fcf3b09 PT |
795 | fFullTraceHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime); |
796 | fTimeRangeHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime); | |
720d67cb PT |
797 | fSelectionStartControl.setValue(fSelectionBeginTime); |
798 | fSelectionEndControl.setValue(fSelectionEndTime); | |
38df2c82 AM |
799 | } |
800 | ||
801 | private void updateDisplayedTimeRange(long start, long end) { | |
802 | fWindowStartTime = start; | |
803 | fWindowEndTime = end; | |
804 | fWindowSpan = fWindowEndTime - fWindowStartTime; | |
805 | fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan); | |
806 | } | |
807 | ||
faa38350 PT |
808 | private TmfTimeRange updateTraceTimeRange() { |
809 | fTraceStartTime = 0L; | |
810 | fTraceEndTime = 0L; | |
74237cc3 | 811 | |
faa38350 | 812 | TmfTimeRange timeRange = fTrace.getTimeRange(); |
c6023803 | 813 | if (!timeRange.equals(TmfTimeRange.NULL_RANGE)) { |
faa38350 PT |
814 | fTraceStartTime = timeRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
815 | fTraceEndTime = timeRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
74237cc3 FC |
816 | } |
817 | return timeRange; | |
b59134e1 | 818 | } |
c392540b FC |
819 | |
820 | private void sendTimeRangeRequest(long startTime, long endTime) { | |
1b055dfa | 821 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
c392540b | 822 | fTimeRangeRequest.cancel(); |
088c1d4e | 823 | } |
f8177ba2 FC |
824 | TmfTimestamp startTS = new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE); |
825 | TmfTimestamp endTS = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE); | |
c392540b FC |
826 | TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS); |
827 | ||
828 | fTimeRangeHistogram.clear(); | |
15844a4e | 829 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
c392540b | 830 | fTimeRangeHistogram.setTimeRange(startTime, endTime - startTime); |
4cf201de | 831 | |
faa38350 | 832 | int cacheSize = fTrace.getCacheSize(); |
2740e05c AM |
833 | fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(), |
834 | timeRange, 0, ITmfEventRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND, false); | |
faa38350 | 835 | fTrace.sendRequest(fTimeRangeRequest); |
088c1d4e | 836 | } |
c392540b | 837 | |
74237cc3 | 838 | private void sendFullRangeRequest(TmfTimeRange fullRange) { |
1b055dfa | 839 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
c392540b FC |
840 | fFullTraceRequest.cancel(); |
841 | } | |
faa38350 | 842 | int cacheSize = fTrace.getCacheSize(); |
2740e05c AM |
843 | fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(), |
844 | fullRange, | |
845 | (int) fFullTraceHistogram.fDataModel.getNbEvents(), | |
846 | ITmfEventRequest.ALL_DATA, | |
847 | cacheSize, | |
848 | ExecutionType.BACKGROUND, true); | |
faa38350 | 849 | fTrace.sendRequest(fFullTraceRequest); |
ed4b3b9f | 850 | } |
c392540b | 851 | |
95aa81ef JCK |
852 | private void contributeToActionBars() { |
853 | IActionBars bars = getViewSite().getActionBars(); | |
854 | bars.getToolBarManager().add(getShowLostEventsAction()); | |
2fc582d2 | 855 | bars.getToolBarManager().add(getShowTraceAction()); |
95aa81ef JCK |
856 | bars.getToolBarManager().add(new Separator()); |
857 | } | |
858 | ||
720d67cb PT |
859 | private void addLinkButtonListeners() { |
860 | fLinkButton.addMouseListener(new MouseAdapter() { | |
861 | @Override | |
862 | public void mouseDown(MouseEvent e) { | |
863 | fSelectionEndControl.setEnabled(fLinkState); | |
864 | fLinkState = !fLinkState; | |
865 | fLinkButton.redraw(); | |
866 | } | |
867 | }); | |
868 | ||
869 | fLinkButton.addPaintListener(new PaintListener() { | |
870 | @Override | |
871 | public void paintControl(PaintEvent e) { | |
872 | if (fLinkState) { | |
873 | Rectangle r = fLinkButton.getBounds(); | |
874 | r.x = -1; | |
875 | r.y = -1; | |
876 | e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); | |
877 | e.gc.drawRectangle(r); | |
878 | r.x = 0; | |
879 | r.y = 0; | |
880 | e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_DARK_GRAY)); | |
881 | e.gc.drawRectangle(r); | |
882 | } | |
883 | } | |
884 | }); | |
885 | } | |
6e512b93 | 886 | } |