Commit | Line | Data |
---|---|---|
4999a196 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal |
4999a196 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 | * Patrick Tasse - Initial API and implementation | |
11 | * Bernd Hufmann - Updated signal handling | |
12 | * Geneviève Bastien - Move code to provide base classes for time graph view | |
c1cd9635 | 13 | * Marc-Andre Laperle - Add time zone preference |
bec1f1ac | 14 | * Geneviève Bastien - Add event links between entries |
4999a196 GB |
15 | *******************************************************************************/ |
16 | ||
2bdf0193 | 17 | package org.eclipse.tracecompass.tmf.ui.views.timegraph; |
4999a196 GB |
18 | |
19 | import java.util.ArrayList; | |
4999a196 GB |
20 | import java.util.Collections; |
21 | import java.util.Comparator; | |
22 | import java.util.HashMap; | |
23 | import java.util.List; | |
24 | import java.util.Map; | |
1cf25311 | 25 | import java.util.concurrent.CopyOnWriteArrayList; |
4999a196 GB |
26 | |
27 | import org.eclipse.core.runtime.IProgressMonitor; | |
28 | import org.eclipse.core.runtime.NullProgressMonitor; | |
dfa0ef96 | 29 | import org.eclipse.jdt.annotation.NonNull; |
d2120fb6 | 30 | import org.eclipse.jdt.annotation.Nullable; |
4999a196 | 31 | import org.eclipse.jface.action.Action; |
747adf5c | 32 | import org.eclipse.jface.action.IAction; |
0fcf3b09 | 33 | import org.eclipse.jface.action.IStatusLineManager; |
4999a196 GB |
34 | import org.eclipse.jface.action.IToolBarManager; |
35 | import org.eclipse.jface.action.Separator; | |
5d021ccf | 36 | import org.eclipse.jface.viewers.AbstractTreeViewer; |
40b7b614 | 37 | import org.eclipse.jface.viewers.ILabelProvider; |
4999a196 | 38 | import org.eclipse.jface.viewers.ILabelProviderListener; |
747adf5c | 39 | import org.eclipse.jface.viewers.ISelectionProvider; |
4999a196 | 40 | import org.eclipse.jface.viewers.ITableLabelProvider; |
cfcfd964 | 41 | import org.eclipse.jface.viewers.ITreeContentProvider; |
747adf5c | 42 | import org.eclipse.jface.viewers.TreeViewer; |
4923d7b9 | 43 | import org.eclipse.jface.viewers.ViewerFilter; |
4999a196 GB |
44 | import org.eclipse.swt.SWT; |
45 | import org.eclipse.swt.graphics.Image; | |
46 | import org.eclipse.swt.widgets.Composite; | |
47 | import org.eclipse.swt.widgets.Display; | |
48 | import org.eclipse.swt.widgets.TreeColumn; | |
97c71024 | 49 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
d2e4afa7 | 50 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
2bdf0193 AM |
51 | import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal; |
52 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; | |
53 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
54 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; | |
d2e4afa7 | 55 | import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; |
2bdf0193 AM |
56 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
57 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp; | |
58 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; | |
59 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
21852dfa | 60 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext; |
2bdf0193 AM |
61 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
62 | import org.eclipse.tracecompass.tmf.ui.TmfUiRefreshHandler; | |
d2e4afa7 MAL |
63 | import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo; |
64 | import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned; | |
2bdf0193 AM |
65 | import org.eclipse.tracecompass.tmf.ui.views.TmfView; |
66 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphContentProvider; | |
67 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2; | |
68 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; | |
69 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; | |
70 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; | |
71 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphCombo; | |
d8a230f8 | 72 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphContentProvider; |
2bdf0193 AM |
73 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; |
74 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; | |
75 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; | |
76 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer; | |
77 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent; | |
e790b877 | 78 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent; |
2bdf0193 AM |
79 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; |
80 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
81 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; | |
82 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; | |
4999a196 GB |
83 | import org.eclipse.ui.IActionBars; |
84 | ||
85 | /** | |
86 | * An abstract view all time graph views can inherit | |
87 | * | |
747adf5c PT |
88 | * This view contains either a time graph viewer, or a time graph combo which is |
89 | * divided between a tree viewer on the left and a time graph viewer on the right. | |
4999a196 | 90 | */ |
d2e4afa7 | 91 | public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeAligned { |
4999a196 | 92 | |
5d021ccf GB |
93 | /** Constant indicating that all levels of the time graph should be expanded */ |
94 | protected static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS; | |
95 | ||
4999a196 GB |
96 | /** |
97 | * Redraw state enum | |
98 | */ | |
99 | private enum State { | |
100 | IDLE, BUSY, PENDING | |
101 | } | |
102 | ||
103 | // ------------------------------------------------------------------------ | |
104 | // Fields | |
105 | // ------------------------------------------------------------------------ | |
106 | ||
747adf5c PT |
107 | /** The timegraph wrapper */ |
108 | private ITimeGraphWrapper fTimeGraphWrapper; | |
4999a196 GB |
109 | |
110 | /** The selected trace */ | |
111 | private ITmfTrace fTrace; | |
112 | ||
113 | /** The timegraph entry list */ | |
114 | private List<TimeGraphEntry> fEntryList; | |
115 | ||
116 | /** The trace to entry list hash map */ | |
507b1336 | 117 | private final Map<ITmfTrace, List<TimeGraphEntry>> fEntryListMap = new HashMap<>(); |
4999a196 | 118 | |
4923d7b9 PT |
119 | /** The trace to filters hash map */ |
120 | private final Map<ITmfTrace, ViewerFilter[]> fFiltersMap = new HashMap<>(); | |
121 | ||
1cf25311 | 122 | /** The trace to build thread hash map */ |
507b1336 | 123 | private final Map<ITmfTrace, BuildThread> fBuildThreadMap = new HashMap<>(); |
4999a196 GB |
124 | |
125 | /** The start time */ | |
335b04e6 | 126 | private long fStartTime = SWT.DEFAULT; |
4999a196 GB |
127 | |
128 | /** The end time */ | |
335b04e6 | 129 | private long fEndTime = SWT.DEFAULT; |
4999a196 GB |
130 | |
131 | /** The display width */ | |
132 | private final int fDisplayWidth; | |
133 | ||
134 | /** The zoom thread */ | |
135 | private ZoomThread fZoomThread; | |
136 | ||
137 | /** The next resource action */ | |
138 | private Action fNextResourceAction; | |
139 | ||
140 | /** The previous resource action */ | |
141 | private Action fPreviousResourceAction; | |
142 | ||
4999a196 GB |
143 | /** A comparator class */ |
144 | private Comparator<ITimeGraphEntry> fEntryComparator = null; | |
145 | ||
1cf25311 | 146 | /** The redraw state used to prevent unnecessary queuing of display runnables */ |
4999a196 GB |
147 | private State fRedrawState = State.IDLE; |
148 | ||
149 | /** The redraw synchronization object */ | |
150 | private final Object fSyncObj = new Object(); | |
151 | ||
152 | /** The presentation provider for this view */ | |
153 | private final TimeGraphPresentationProvider fPresentation; | |
154 | ||
747adf5c PT |
155 | /** The tree column label array, or null if combo is not used */ |
156 | private String[] fColumns; | |
157 | ||
158 | /** The tree label provider, or null if combo is not used */ | |
159 | private TreeLabelProvider fLabelProvider = null; | |
160 | ||
a12aae87 GB |
161 | /** The time graph content provider */ |
162 | private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider = new TimeGraphContentProvider(); | |
163 | ||
747adf5c | 164 | /** The relative weight of the sash, ignored if combo is not used */ |
59387be3 | 165 | private int[] fWeight = { 1, 3 }; |
747adf5c PT |
166 | |
167 | /** The filter column label array, or null if filter is not used */ | |
168 | private String[] fFilterColumns; | |
4999a196 | 169 | |
1cf25311 PT |
170 | /** The pack done flag */ |
171 | private boolean fPackDone = false; | |
172 | ||
a03b7ee4 PT |
173 | /** The filter label provider, or null if filter is not used */ |
174 | private TreeLabelProvider fFilterLabelProvider; | |
175 | ||
5d021ccf GB |
176 | private int fAutoExpandLevel = ALL_LEVELS; |
177 | ||
4999a196 | 178 | // ------------------------------------------------------------------------ |
747adf5c | 179 | // Classes |
4999a196 GB |
180 | // ------------------------------------------------------------------------ |
181 | ||
747adf5c | 182 | private interface ITimeGraphWrapper { |
4999a196 | 183 | |
cfcfd964 PT |
184 | void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider); |
185 | ||
186 | void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider); | |
4999a196 | 187 | |
747adf5c | 188 | TimeGraphViewer getTimeGraphViewer(); |
4999a196 | 189 | |
cfcfd964 | 190 | void addSelectionListener(ITimeGraphSelectionListener listener); |
4999a196 | 191 | |
747adf5c | 192 | ISelectionProvider getSelectionProvider(); |
4999a196 | 193 | |
747adf5c | 194 | void setFocus(); |
4999a196 | 195 | |
747adf5c | 196 | boolean isDisposed(); |
4999a196 | 197 | |
747adf5c | 198 | void refresh(); |
4999a196 | 199 | |
1cf25311 PT |
200 | void setInput(Object input); |
201 | ||
202 | Object getInput(); | |
4999a196 | 203 | |
4923d7b9 PT |
204 | void setFilters(ViewerFilter[] filters); |
205 | ||
206 | ViewerFilter[] getFilters(); | |
207 | ||
747adf5c | 208 | void redraw(); |
4999a196 | 209 | |
747adf5c | 210 | void update(); |
4999a196 | 211 | |
5d021ccf GB |
212 | void setAutoExpandLevel(int level); |
213 | ||
cfcfd964 PT |
214 | void setFilterColumns(String[] columnNames); |
215 | ||
216 | void setFilterContentProvider(ITreeContentProvider contentProvider); | |
217 | ||
218 | void setFilterLabelProvider(ITableLabelProvider labelProvider); | |
219 | ||
220 | IAction getShowFilterDialogAction(); | |
221 | ||
d2e4afa7 MAL |
222 | void performAlign(int offset, int width); |
223 | ||
224 | TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo(); | |
225 | ||
226 | int getAvailableWidth(int requestedOffset); | |
4999a196 GB |
227 | } |
228 | ||
747adf5c PT |
229 | private class TimeGraphViewerWrapper implements ITimeGraphWrapper { |
230 | private TimeGraphViewer viewer; | |
4999a196 | 231 | |
747adf5c PT |
232 | private TimeGraphViewerWrapper(Composite parent, int style) { |
233 | viewer = new TimeGraphViewer(parent, style); | |
4999a196 | 234 | } |
4999a196 | 235 | |
747adf5c | 236 | @Override |
cfcfd964 PT |
237 | public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) { |
238 | viewer.setTimeGraphContentProvider(timeGraphContentProvider); | |
239 | } | |
240 | ||
241 | @Override | |
242 | public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider) { | |
243 | viewer.setTimeGraphProvider(timeGraphPresentationProvider); | |
747adf5c | 244 | } |
4999a196 | 245 | |
747adf5c PT |
246 | @Override |
247 | public TimeGraphViewer getTimeGraphViewer() { | |
248 | return viewer; | |
249 | } | |
4999a196 | 250 | |
747adf5c PT |
251 | @Override |
252 | public void addSelectionListener(ITimeGraphSelectionListener listener) { | |
253 | viewer.addSelectionListener(listener); | |
254 | } | |
4999a196 | 255 | |
747adf5c PT |
256 | @Override |
257 | public ISelectionProvider getSelectionProvider() { | |
258 | return viewer.getSelectionProvider(); | |
259 | } | |
260 | ||
261 | @Override | |
262 | public void setFocus() { | |
263 | viewer.setFocus(); | |
264 | } | |
265 | ||
266 | @Override | |
267 | public boolean isDisposed() { | |
268 | return viewer.getControl().isDisposed(); | |
269 | } | |
270 | ||
271 | @Override | |
1cf25311 | 272 | public void setInput(Object input) { |
747adf5c PT |
273 | viewer.setInput(input); |
274 | } | |
275 | ||
1cf25311 PT |
276 | @Override |
277 | public Object getInput() { | |
278 | return viewer.getInput(); | |
279 | } | |
280 | ||
cfcfd964 PT |
281 | @Override |
282 | public void setFilterColumns(String[] columnNames) { | |
283 | viewer.setFilterColumns(columnNames); | |
284 | } | |
285 | ||
286 | @Override | |
287 | public void setFilterContentProvider(ITreeContentProvider contentProvider) { | |
288 | viewer.setFilterContentProvider(contentProvider); | |
289 | } | |
290 | ||
291 | @Override | |
292 | public void setFilterLabelProvider(ITableLabelProvider labelProvider) { | |
293 | viewer.setFilterLabelProvider(labelProvider); | |
294 | } | |
295 | ||
4923d7b9 PT |
296 | @Override |
297 | public void setFilters(ViewerFilter[] filters) { | |
298 | viewer.setFilters(filters); | |
299 | } | |
300 | ||
301 | @Override | |
302 | public ViewerFilter[] getFilters() { | |
303 | return viewer.getFilters(); | |
304 | } | |
305 | ||
cfcfd964 PT |
306 | @Override |
307 | public IAction getShowFilterDialogAction() { | |
308 | return viewer.getShowFilterDialogAction(); | |
309 | } | |
310 | ||
747adf5c PT |
311 | @Override |
312 | public void refresh() { | |
313 | viewer.refresh(); | |
314 | } | |
315 | ||
316 | @Override | |
317 | public void redraw() { | |
318 | viewer.getControl().redraw(); | |
319 | } | |
320 | ||
321 | @Override | |
322 | public void update() { | |
323 | viewer.getControl().update(); | |
324 | } | |
5d021ccf GB |
325 | |
326 | @Override | |
327 | public void setAutoExpandLevel(int level) { | |
328 | viewer.setAutoExpandLevel(level); | |
329 | } | |
d2e4afa7 MAL |
330 | |
331 | @Override | |
332 | public void performAlign(int offset, int width) { | |
333 | viewer.performAlign(offset, width); | |
334 | } | |
335 | ||
336 | @Override | |
337 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { | |
338 | return viewer.getTimeViewAlignmentInfo(); | |
339 | } | |
340 | ||
341 | @Override | |
342 | public int getAvailableWidth(int requestedOffset) { | |
343 | return viewer.getAvailableWidth(requestedOffset); | |
344 | } | |
4999a196 GB |
345 | } |
346 | ||
747adf5c PT |
347 | private class TimeGraphComboWrapper implements ITimeGraphWrapper { |
348 | private TimeGraphCombo combo; | |
349 | ||
350 | private TimeGraphComboWrapper(Composite parent, int style) { | |
351 | combo = new TimeGraphCombo(parent, style, fWeight); | |
352 | } | |
353 | ||
354 | @Override | |
cfcfd964 PT |
355 | public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) { |
356 | combo.setTimeGraphContentProvider(timeGraphContentProvider); | |
357 | } | |
358 | ||
359 | @Override | |
360 | public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider) { | |
361 | combo.setTimeGraphProvider(timeGraphPresentationProvider); | |
747adf5c PT |
362 | } |
363 | ||
364 | @Override | |
365 | public TimeGraphViewer getTimeGraphViewer() { | |
366 | return combo.getTimeGraphViewer(); | |
367 | } | |
368 | ||
369 | @Override | |
370 | public void addSelectionListener(ITimeGraphSelectionListener listener) { | |
371 | combo.addSelectionListener(listener); | |
372 | } | |
373 | ||
374 | @Override | |
375 | public ISelectionProvider getSelectionProvider() { | |
376 | return combo.getTreeViewer(); | |
377 | } | |
378 | ||
379 | @Override | |
380 | public void setFocus() { | |
381 | combo.setFocus(); | |
382 | } | |
383 | ||
384 | @Override | |
385 | public boolean isDisposed() { | |
386 | return combo.isDisposed(); | |
387 | } | |
388 | ||
389 | @Override | |
1cf25311 | 390 | public void setInput(Object input) { |
747adf5c PT |
391 | combo.setInput(input); |
392 | } | |
393 | ||
1cf25311 PT |
394 | @Override |
395 | public Object getInput() { | |
396 | return combo.getInput(); | |
397 | } | |
398 | ||
cfcfd964 PT |
399 | @Override |
400 | public void setFilterColumns(String[] columnNames) { | |
401 | combo.setFilterColumns(columnNames); | |
402 | } | |
403 | ||
404 | @Override | |
405 | public void setFilterContentProvider(ITreeContentProvider contentProvider) { | |
406 | combo.setFilterContentProvider(contentProvider); | |
407 | } | |
408 | ||
409 | @Override | |
410 | public void setFilterLabelProvider(ITableLabelProvider labelProvider) { | |
411 | combo.setFilterLabelProvider(labelProvider); | |
412 | } | |
413 | ||
4923d7b9 PT |
414 | @Override |
415 | public void setFilters(ViewerFilter[] filters) { | |
416 | combo.setFilters(filters); | |
417 | } | |
418 | ||
419 | @Override | |
420 | public ViewerFilter[] getFilters() { | |
421 | return combo.getFilters(); | |
422 | } | |
423 | ||
cfcfd964 PT |
424 | @Override |
425 | public IAction getShowFilterDialogAction() { | |
426 | return combo.getShowFilterDialogAction(); | |
427 | } | |
428 | ||
747adf5c PT |
429 | @Override |
430 | public void refresh() { | |
431 | combo.refresh(); | |
432 | } | |
433 | ||
434 | @Override | |
435 | public void redraw() { | |
436 | combo.redraw(); | |
437 | } | |
438 | ||
439 | @Override | |
440 | public void update() { | |
441 | combo.update(); | |
442 | } | |
443 | ||
5d021ccf GB |
444 | @Override |
445 | public void setAutoExpandLevel(int level) { | |
446 | combo.setAutoExpandLevel(level); | |
447 | } | |
448 | ||
747adf5c PT |
449 | TimeGraphCombo getTimeGraphCombo() { |
450 | return combo; | |
451 | } | |
452 | ||
453 | TreeViewer getTreeViewer() { | |
454 | return combo.getTreeViewer(); | |
455 | } | |
456 | ||
d2e4afa7 MAL |
457 | @Override |
458 | public void performAlign(int offset, int width) { | |
459 | combo.performAlign(offset, width); | |
460 | } | |
461 | ||
462 | @Override | |
463 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { | |
464 | return combo.getTimeViewAlignmentInfo(); | |
465 | } | |
466 | ||
467 | @Override | |
468 | public int getAvailableWidth(int requestedOffset) { | |
469 | return combo.getAvailableWidth(requestedOffset); | |
470 | } | |
747adf5c | 471 | } |
4999a196 | 472 | |
4999a196 | 473 | /** |
747adf5c PT |
474 | * Base class to provide the labels for the tree viewer. Views extending |
475 | * this class typically need to override the getColumnText method if they | |
476 | * have more than one column to display | |
4999a196 | 477 | */ |
40b7b614 | 478 | protected static class TreeLabelProvider implements ITableLabelProvider, ILabelProvider { |
4999a196 GB |
479 | |
480 | @Override | |
481 | public void addListener(ILabelProviderListener listener) { | |
482 | } | |
483 | ||
484 | @Override | |
485 | public void dispose() { | |
486 | } | |
487 | ||
488 | @Override | |
489 | public boolean isLabelProperty(Object element, String property) { | |
490 | return false; | |
491 | } | |
492 | ||
493 | @Override | |
494 | public void removeListener(ILabelProviderListener listener) { | |
495 | } | |
496 | ||
497 | @Override | |
498 | public Image getColumnImage(Object element, int columnIndex) { | |
499 | return null; | |
500 | } | |
501 | ||
502 | @Override | |
503 | public String getColumnText(Object element, int columnIndex) { | |
504 | TimeGraphEntry entry = (TimeGraphEntry) element; | |
505 | if (columnIndex == 0) { | |
506 | return entry.getName(); | |
507 | } | |
76fccfb0 | 508 | return new String(); |
4999a196 GB |
509 | } |
510 | ||
40b7b614 GP |
511 | @Override |
512 | public Image getImage(Object element) { | |
513 | return null; | |
514 | } | |
515 | ||
40b7b614 GP |
516 | @Override |
517 | public String getText(Object element) { | |
518 | TimeGraphEntry entry = (TimeGraphEntry) element; | |
519 | return entry.getName(); | |
520 | } | |
521 | ||
4999a196 GB |
522 | } |
523 | ||
524 | private class BuildThread extends Thread { | |
dfa0ef96 GB |
525 | private final @NonNull ITmfTrace fBuildTrace; |
526 | private final @NonNull ITmfTrace fParentTrace; | |
527 | private final @NonNull IProgressMonitor fMonitor; | |
4999a196 | 528 | |
dfa0ef96 | 529 | public BuildThread(final @NonNull ITmfTrace trace, final @NonNull ITmfTrace parentTrace, final String name) { |
4999a196 GB |
530 | super(name + " build"); //$NON-NLS-1$ |
531 | fBuildTrace = trace; | |
1cf25311 | 532 | fParentTrace = parentTrace; |
4999a196 GB |
533 | fMonitor = new NullProgressMonitor(); |
534 | } | |
535 | ||
536 | @Override | |
537 | public void run() { | |
1cf25311 | 538 | buildEventList(fBuildTrace, fParentTrace, fMonitor); |
4999a196 | 539 | synchronized (fBuildThreadMap) { |
1cf25311 | 540 | fBuildThreadMap.remove(fBuildTrace); |
4999a196 GB |
541 | } |
542 | } | |
543 | ||
544 | public void cancel() { | |
545 | fMonitor.setCanceled(true); | |
546 | } | |
547 | } | |
548 | ||
6ae6c5bd PT |
549 | /** |
550 | * Zoom thread | |
3de2428b | 551 | * @since 2.0 |
6ae6c5bd PT |
552 | */ |
553 | protected abstract class ZoomThread extends Thread { | |
4999a196 GB |
554 | private final long fZoomStartTime; |
555 | private final long fZoomEndTime; | |
556 | private final long fResolution; | |
dfa0ef96 | 557 | private final @NonNull IProgressMonitor fMonitor; |
4999a196 | 558 | |
6ae6c5bd PT |
559 | /** |
560 | * Constructor | |
561 | * | |
562 | * @param startTime | |
563 | * the start time | |
564 | * @param endTime | |
565 | * the end time | |
566 | * @param resolution | |
567 | * the resolution | |
568 | */ | |
569 | public ZoomThread(long startTime, long endTime, long resolution) { | |
570 | super(AbstractTimeGraphView.this.getName() + " zoom"); //$NON-NLS-1$ | |
4999a196 GB |
571 | fZoomStartTime = startTime; |
572 | fZoomEndTime = endTime; | |
6ae6c5bd | 573 | fResolution = resolution; |
4999a196 GB |
574 | fMonitor = new NullProgressMonitor(); |
575 | } | |
576 | ||
6ae6c5bd PT |
577 | /** |
578 | * @return the zoom start time | |
579 | */ | |
580 | public long getZoomStartTime() { | |
581 | return fZoomStartTime; | |
582 | } | |
583 | ||
584 | /** | |
585 | * @return the zoom end time | |
586 | */ | |
587 | public long getZoomEndTime() { | |
588 | return fZoomEndTime; | |
589 | } | |
590 | ||
591 | /** | |
592 | * @return the resolution | |
593 | */ | |
594 | public long getResolution() { | |
595 | return fResolution; | |
596 | } | |
597 | ||
598 | /** | |
599 | * @return the monitor | |
600 | */ | |
601 | public @NonNull IProgressMonitor getMonitor() { | |
602 | return fMonitor; | |
603 | } | |
604 | ||
605 | /** | |
606 | * Cancel the zoom thread | |
607 | */ | |
608 | public void cancel() { | |
609 | fMonitor.setCanceled(true); | |
610 | } | |
611 | } | |
612 | ||
613 | private class ZoomThreadByEntry extends ZoomThread { | |
614 | private final @NonNull List<TimeGraphEntry> fZoomEntryList; | |
615 | ||
616 | public ZoomThreadByEntry(@NonNull List<TimeGraphEntry> entryList, long startTime, long endTime, long resolution) { | |
617 | super(startTime, endTime, resolution); | |
618 | fZoomEntryList = entryList; | |
619 | } | |
620 | ||
4999a196 GB |
621 | @Override |
622 | public void run() { | |
4999a196 | 623 | for (TimeGraphEntry entry : fZoomEntryList) { |
6ae6c5bd | 624 | if (getMonitor().isCanceled()) { |
79ec0b89 | 625 | return; |
4999a196 | 626 | } |
dfa0ef96 GB |
627 | if (entry == null) { |
628 | break; | |
629 | } | |
6ae6c5bd | 630 | zoom(entry, getMonitor()); |
4999a196 | 631 | } |
bec1f1ac | 632 | /* Refresh the arrows when zooming */ |
6ae6c5bd | 633 | List<ILinkEvent> events = getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()); |
79ec0b89 | 634 | if (events != null) { |
747adf5c | 635 | fTimeGraphWrapper.getTimeGraphViewer().setLinks(events); |
79ec0b89 PT |
636 | redraw(); |
637 | } | |
e790b877 PT |
638 | /* Refresh the markers when zooming */ |
639 | List<IMarkerEvent> markers = getMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()); | |
640 | if (markers != null) { | |
641 | fTimeGraphWrapper.getTimeGraphViewer().getTimeGraphControl().setMarkers(markers); | |
642 | redraw(); | |
643 | } | |
4999a196 GB |
644 | } |
645 | ||
dfa0ef96 | 646 | private void zoom(@NonNull TimeGraphEntry entry, @NonNull IProgressMonitor monitor) { |
6ae6c5bd | 647 | if (getZoomStartTime() <= fStartTime && getZoomEndTime() >= fEndTime) { |
4999a196 GB |
648 | entry.setZoomedEventList(null); |
649 | } else { | |
6ae6c5bd | 650 | List<ITimeEvent> zoomedEventList = getEventList(entry, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor); |
4999a196 GB |
651 | if (zoomedEventList != null) { |
652 | entry.setZoomedEventList(zoomedEventList); | |
653 | } | |
654 | } | |
655 | redraw(); | |
a3188982 | 656 | for (ITimeGraphEntry child : entry.getChildren()) { |
6ae6c5bd | 657 | if (monitor.isCanceled()) { |
4999a196 GB |
658 | return; |
659 | } | |
a3188982 PT |
660 | if (child instanceof TimeGraphEntry) { |
661 | zoom((TimeGraphEntry) child, monitor); | |
662 | } | |
4999a196 GB |
663 | } |
664 | } | |
665 | ||
4999a196 GB |
666 | } |
667 | ||
668 | // ------------------------------------------------------------------------ | |
669 | // Constructors | |
670 | // ------------------------------------------------------------------------ | |
671 | ||
672 | /** | |
747adf5c PT |
673 | * Constructs a time graph view that contains either a time graph viewer or |
674 | * a time graph combo. | |
675 | * | |
676 | * By default, the view uses a time graph viewer. To use a time graph combo, | |
677 | * the subclass constructor must call {@link #setTreeColumns(String[])} and | |
678 | * {@link #setTreeLabelProvider(TreeLabelProvider)}. | |
4999a196 GB |
679 | * |
680 | * @param id | |
681 | * The id of the view | |
4999a196 GB |
682 | * @param pres |
683 | * The presentation provider | |
684 | */ | |
747adf5c | 685 | public AbstractTimeGraphView(String id, TimeGraphPresentationProvider pres) { |
4999a196 | 686 | super(id); |
4999a196 GB |
687 | fPresentation = pres; |
688 | fDisplayWidth = Display.getDefault().getBounds().width; | |
689 | } | |
690 | ||
691 | // ------------------------------------------------------------------------ | |
747adf5c | 692 | // Getters and setters |
4999a196 GB |
693 | // ------------------------------------------------------------------------ |
694 | ||
747adf5c PT |
695 | /** |
696 | * Getter for the time graph combo | |
697 | * | |
698 | * @return The time graph combo, or null if combo is not used | |
699 | */ | |
700 | protected TimeGraphCombo getTimeGraphCombo() { | |
701 | if (fTimeGraphWrapper instanceof TimeGraphComboWrapper) { | |
702 | return ((TimeGraphComboWrapper) fTimeGraphWrapper).getTimeGraphCombo(); | |
703 | } | |
704 | return null; | |
705 | } | |
4999a196 | 706 | |
747adf5c PT |
707 | /** |
708 | * Getter for the time graph viewer | |
709 | * | |
710 | * @return The time graph viewer | |
711 | */ | |
712 | protected TimeGraphViewer getTimeGraphViewer() { | |
713 | return fTimeGraphWrapper.getTimeGraphViewer(); | |
714 | } | |
715 | ||
50c2da9e GB |
716 | /** |
717 | * Getter for the presentation provider | |
718 | * | |
719 | * @return The time graph presentation provider | |
50c2da9e GB |
720 | */ |
721 | protected ITimeGraphPresentationProvider2 getPresentationProvider() { | |
722 | return fPresentation; | |
723 | } | |
724 | ||
747adf5c PT |
725 | /** |
726 | * Sets the tree column labels. | |
727 | * This should be called from the constructor. | |
728 | * | |
729 | * @param columns | |
730 | * The array of tree column labels | |
731 | */ | |
732 | protected void setTreeColumns(final String[] columns) { | |
733 | fColumns = columns; | |
734 | } | |
735 | ||
736 | /** | |
737 | * Sets the tree label provider. | |
738 | * This should be called from the constructor. | |
739 | * | |
740 | * @param tlp | |
741 | * The tree label provider | |
742 | */ | |
743 | protected void setTreeLabelProvider(final TreeLabelProvider tlp) { | |
744 | fLabelProvider = tlp; | |
745 | } | |
746 | ||
a12aae87 GB |
747 | /** |
748 | * Sets the time graph content provider. This should be called from the | |
749 | * constructor. | |
750 | * | |
751 | * @param tgcp | |
752 | * The time graph content provider | |
753 | * @since 1.0 | |
754 | */ | |
755 | protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp) { | |
756 | fTimeGraphContentProvider = tgcp; | |
757 | } | |
758 | ||
747adf5c PT |
759 | /** |
760 | * Sets the relative weight of each part of the time graph combo. | |
761 | * This should be called from the constructor. | |
762 | * | |
763 | * @param weights | |
764 | * The array (length 2) of relative weights of each part of the combo | |
765 | */ | |
766 | protected void setWeight(final int[] weights) { | |
767 | fWeight = weights; | |
768 | } | |
4999a196 | 769 | |
747adf5c PT |
770 | /** |
771 | * Sets the filter column labels. | |
772 | * This should be called from the constructor. | |
773 | * | |
774 | * @param filterColumns | |
775 | * The array of filter column labels | |
776 | */ | |
777 | protected void setFilterColumns(final String[] filterColumns) { | |
778 | fFilterColumns = filterColumns; | |
779 | } | |
4999a196 | 780 | |
a03b7ee4 PT |
781 | /** |
782 | * Sets the filter label provider. | |
783 | * This should be called from the constructor. | |
784 | * | |
785 | * @param labelProvider | |
786 | * The filter label provider | |
a03b7ee4 PT |
787 | */ |
788 | protected void setFilterLabelProvider(final TreeLabelProvider labelProvider) { | |
789 | fFilterLabelProvider = labelProvider; | |
790 | } | |
791 | ||
747adf5c PT |
792 | /** |
793 | * Gets the display width | |
794 | * | |
795 | * @return the display width | |
796 | */ | |
797 | protected int getDisplayWidth() { | |
798 | return fDisplayWidth; | |
799 | } | |
4999a196 | 800 | |
747adf5c PT |
801 | /** |
802 | * Gets the comparator for the entries | |
803 | * | |
804 | * @return The entry comparator | |
805 | */ | |
806 | protected Comparator<ITimeGraphEntry> getEntryComparator() { | |
807 | return fEntryComparator; | |
808 | } | |
4999a196 | 809 | |
747adf5c PT |
810 | /** |
811 | * Sets the comparator class for the entries | |
812 | * | |
813 | * @param comparator | |
814 | * A comparator object | |
815 | */ | |
816 | protected void setEntryComparator(final Comparator<ITimeGraphEntry> comparator) { | |
817 | fEntryComparator = comparator; | |
818 | } | |
4999a196 | 819 | |
747adf5c PT |
820 | /** |
821 | * Gets the trace displayed in the view | |
822 | * | |
823 | * @return The trace | |
824 | */ | |
825 | protected ITmfTrace getTrace() { | |
826 | return fTrace; | |
827 | } | |
4999a196 | 828 | |
747adf5c PT |
829 | /** |
830 | * Gets the start time | |
831 | * | |
832 | * @return The start time | |
833 | */ | |
834 | protected long getStartTime() { | |
835 | return fStartTime; | |
836 | } | |
4999a196 | 837 | |
747adf5c PT |
838 | /** |
839 | * Sets the start time | |
840 | * | |
841 | * @param time | |
842 | * The start time | |
843 | */ | |
844 | protected void setStartTime(long time) { | |
845 | fStartTime = time; | |
846 | } | |
847 | ||
848 | /** | |
849 | * Gets the end time | |
850 | * | |
851 | * @return The end time | |
852 | */ | |
853 | protected long getEndTime() { | |
854 | return fEndTime; | |
855 | } | |
856 | ||
857 | /** | |
858 | * Sets the end time | |
859 | * | |
860 | * @param time | |
861 | * The end time | |
862 | */ | |
863 | protected void setEndTime(long time) { | |
864 | fEndTime = time; | |
865 | } | |
866 | ||
5d021ccf GB |
867 | /** |
868 | * Sets the auto-expand level to be used for the input of the view. The | |
869 | * value 0 means that there is no auto-expand; 1 means that top-level | |
870 | * elements are expanded, but not their children; 2 means that top-level | |
871 | * elements are expanded, and their children, but not grand-children; and so | |
872 | * on. | |
873 | * <p> | |
874 | * The value {@link #ALL_LEVELS} means that all subtrees should be expanded. | |
875 | * </p> | |
876 | * | |
877 | * @param level | |
878 | * non-negative level, or <code>ALL_LEVELS</code> to expand all | |
879 | * levels of the tree | |
880 | */ | |
881 | protected void setAutoExpandLevel(int level) { | |
882 | fAutoExpandLevel = level; | |
883 | ITimeGraphWrapper tgWrapper = fTimeGraphWrapper; | |
884 | if (tgWrapper != null) { | |
885 | tgWrapper.setAutoExpandLevel(level); | |
886 | } | |
887 | } | |
888 | ||
747adf5c | 889 | /** |
1cf25311 PT |
890 | * Gets the entry list for a trace |
891 | * | |
892 | * @param trace | |
893 | * the trace | |
747adf5c PT |
894 | * |
895 | * @return the entry list map | |
896 | */ | |
1cf25311 PT |
897 | protected List<TimeGraphEntry> getEntryList(ITmfTrace trace) { |
898 | synchronized (fEntryListMap) { | |
899 | return fEntryListMap.get(trace); | |
900 | } | |
747adf5c PT |
901 | } |
902 | ||
903 | /** | |
1cf25311 | 904 | * Adds a trace entry list to the entry list map |
747adf5c PT |
905 | * |
906 | * @param trace | |
907 | * the trace to add | |
908 | * @param list | |
1cf25311 | 909 | * the list of time graph entries |
747adf5c PT |
910 | */ |
911 | protected void putEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { | |
1cf25311 PT |
912 | synchronized (fEntryListMap) { |
913 | fEntryListMap.put(trace, new CopyOnWriteArrayList<>(list)); | |
914 | } | |
915 | } | |
916 | ||
917 | /** | |
918 | * Adds a list of entries to a trace's entry list | |
919 | * | |
920 | * @param trace | |
921 | * the trace | |
922 | * @param list | |
923 | * the list of time graph entries to add | |
1cf25311 PT |
924 | */ |
925 | protected void addToEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { | |
926 | synchronized (fEntryListMap) { | |
927 | List<TimeGraphEntry> entryList = fEntryListMap.get(trace); | |
928 | if (entryList == null) { | |
929 | fEntryListMap.put(trace, new CopyOnWriteArrayList<>(list)); | |
930 | } else { | |
931 | entryList.addAll(list); | |
932 | } | |
933 | } | |
934 | } | |
935 | ||
936 | /** | |
937 | * Removes a list of entries from a trace's entry list | |
938 | * | |
939 | * @param trace | |
940 | * the trace | |
941 | * @param list | |
942 | * the list of time graph entries to remove | |
1cf25311 PT |
943 | */ |
944 | protected void removeFromEntryList(ITmfTrace trace, List<TimeGraphEntry> list) { | |
945 | synchronized (fEntryListMap) { | |
946 | List<TimeGraphEntry> entryList = fEntryListMap.get(trace); | |
947 | if (entryList != null) { | |
948 | entryList.removeAll(list); | |
949 | } | |
747adf5c PT |
950 | } |
951 | } | |
4999a196 | 952 | |
747adf5c PT |
953 | /** |
954 | * Text for the "next" button | |
955 | * | |
956 | * @return The "next" button text | |
957 | */ | |
958 | protected String getNextText() { | |
959 | return Messages.AbstractTimeGraphtView_NextText; | |
960 | } | |
4999a196 | 961 | |
747adf5c PT |
962 | /** |
963 | * Tooltip for the "next" button | |
964 | * | |
965 | * @return Tooltip for the "next" button | |
966 | */ | |
967 | protected String getNextTooltip() { | |
968 | return Messages.AbstractTimeGraphView_NextTooltip; | |
969 | } | |
4999a196 | 970 | |
747adf5c PT |
971 | /** |
972 | * Text for the "Previous" button | |
973 | * | |
974 | * @return The "Previous" button text | |
975 | */ | |
976 | protected String getPrevText() { | |
977 | return Messages.AbstractTimeGraphView_PreviousText; | |
978 | } | |
4999a196 | 979 | |
747adf5c PT |
980 | /** |
981 | * Tooltip for the "previous" button | |
982 | * | |
983 | * @return Tooltip for the "previous" button | |
984 | */ | |
985 | protected String getPrevTooltip() { | |
986 | return Messages.AbstractTimeGraphView_PreviousTooltip; | |
987 | } | |
4999a196 | 988 | |
747adf5c PT |
989 | // ------------------------------------------------------------------------ |
990 | // ViewPart | |
991 | // ------------------------------------------------------------------------ | |
4999a196 | 992 | |
747adf5c PT |
993 | @Override |
994 | public void createPartControl(Composite parent) { | |
d2e4afa7 | 995 | super.createPartControl(parent); |
747adf5c PT |
996 | if (fColumns == null || fLabelProvider == null) { |
997 | fTimeGraphWrapper = new TimeGraphViewerWrapper(parent, SWT.NONE); | |
998 | } else { | |
999 | TimeGraphComboWrapper wrapper = new TimeGraphComboWrapper(parent, SWT.NONE); | |
1000 | fTimeGraphWrapper = wrapper; | |
1001 | TimeGraphCombo combo = wrapper.getTimeGraphCombo(); | |
a12aae87 | 1002 | combo.setTreeContentProvider(fTimeGraphContentProvider); |
747adf5c PT |
1003 | combo.setTreeLabelProvider(fLabelProvider); |
1004 | combo.setTreeColumns(fColumns); | |
747adf5c | 1005 | } |
cfcfd964 PT |
1006 | fTimeGraphWrapper.setTimeGraphContentProvider(fTimeGraphContentProvider); |
1007 | fTimeGraphWrapper.setFilterContentProvider(fTimeGraphContentProvider); | |
1008 | fTimeGraphWrapper.setFilterLabelProvider(fFilterLabelProvider); | |
1009 | fTimeGraphWrapper.setFilterColumns(fFilterColumns); | |
4999a196 | 1010 | |
cfcfd964 | 1011 | fTimeGraphWrapper.setTimeGraphPresentationProvider(fPresentation); |
5d021ccf | 1012 | fTimeGraphWrapper.setAutoExpandLevel(fAutoExpandLevel); |
4999a196 | 1013 | |
747adf5c | 1014 | fTimeGraphWrapper.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() { |
4999a196 GB |
1015 | @Override |
1016 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { | |
1017 | final long startTime = event.getStartTime(); | |
1018 | final long endTime = event.getEndTime(); | |
f566d40a | 1019 | TmfTimeRange range = new TmfTimeRange(new TmfNanoTimestamp(startTime), new TmfNanoTimestamp(endTime)); |
97c71024 | 1020 | broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView.this, range)); |
4999a196 GB |
1021 | startZoomThread(startTime, endTime); |
1022 | } | |
1023 | }); | |
1024 | ||
747adf5c | 1025 | fTimeGraphWrapper.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() { |
4999a196 GB |
1026 | @Override |
1027 | public void timeSelected(TimeGraphTimeEvent event) { | |
f566d40a PT |
1028 | TmfNanoTimestamp startTime = new TmfNanoTimestamp(event.getBeginTime()); |
1029 | TmfNanoTimestamp endTime = new TmfNanoTimestamp(event.getEndTime()); | |
97c71024 | 1030 | broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView.this, startTime, endTime)); |
4999a196 GB |
1031 | } |
1032 | }); | |
1033 | ||
747adf5c | 1034 | fTimeGraphWrapper.getTimeGraphViewer().setTimeFormat(TimeFormat.CALENDAR); |
4999a196 | 1035 | |
0fcf3b09 | 1036 | IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager(); |
747adf5c | 1037 | fTimeGraphWrapper.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager); |
0fcf3b09 | 1038 | |
4999a196 GB |
1039 | // View Action Handling |
1040 | makeActions(); | |
1041 | contributeToActionBars(); | |
1042 | ||
21852dfa | 1043 | ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); |
4999a196 GB |
1044 | if (trace != null) { |
1045 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
1046 | } | |
1047 | ||
1048 | // make selection available to other views | |
747adf5c | 1049 | getSite().setSelectionProvider(fTimeGraphWrapper.getSelectionProvider()); |
4999a196 GB |
1050 | } |
1051 | ||
1052 | @Override | |
1053 | public void setFocus() { | |
747adf5c | 1054 | fTimeGraphWrapper.setFocus(); |
4999a196 GB |
1055 | } |
1056 | ||
1057 | // ------------------------------------------------------------------------ | |
1058 | // Signal handlers | |
1059 | // ------------------------------------------------------------------------ | |
1060 | ||
1061 | /** | |
1062 | * Handler for the trace opened signal. | |
1063 | * | |
1064 | * @param signal | |
1065 | * The incoming signal | |
4999a196 GB |
1066 | */ |
1067 | @TmfSignalHandler | |
1068 | public void traceOpened(TmfTraceOpenedSignal signal) { | |
4923d7b9 | 1069 | loadTrace(signal.getTrace()); |
4999a196 GB |
1070 | } |
1071 | ||
1072 | /** | |
1073 | * Handler for the trace selected signal | |
1074 | * | |
1075 | * @param signal | |
1076 | * The incoming signal | |
1077 | */ | |
1078 | @TmfSignalHandler | |
1079 | public void traceSelected(final TmfTraceSelectedSignal signal) { | |
1080 | if (signal.getTrace() == fTrace) { | |
1081 | return; | |
1082 | } | |
4923d7b9 | 1083 | loadTrace(signal.getTrace()); |
4999a196 GB |
1084 | } |
1085 | ||
1086 | /** | |
1087 | * Trace is closed: clear the data structures and the view | |
1088 | * | |
1089 | * @param signal | |
1090 | * the signal received | |
1091 | */ | |
1092 | @TmfSignalHandler | |
1093 | public void traceClosed(final TmfTraceClosedSignal signal) { | |
1094 | synchronized (fBuildThreadMap) { | |
41cc4f90 | 1095 | for (ITmfTrace trace : getTracesToBuild(signal.getTrace())) { |
1cf25311 PT |
1096 | BuildThread buildThread = fBuildThreadMap.remove(trace); |
1097 | if (buildThread != null) { | |
1098 | buildThread.cancel(); | |
1099 | } | |
4999a196 GB |
1100 | } |
1101 | } | |
1102 | synchronized (fEntryListMap) { | |
1103 | fEntryListMap.remove(signal.getTrace()); | |
1104 | } | |
4923d7b9 | 1105 | fFiltersMap.remove(signal.getTrace()); |
4999a196 GB |
1106 | if (signal.getTrace() == fTrace) { |
1107 | fTrace = null; | |
335b04e6 PT |
1108 | fStartTime = SWT.DEFAULT; |
1109 | fEndTime = SWT.DEFAULT; | |
4999a196 GB |
1110 | if (fZoomThread != null) { |
1111 | fZoomThread.cancel(); | |
6ae6c5bd | 1112 | fZoomThread = null; |
4999a196 GB |
1113 | } |
1114 | refresh(); | |
1115 | } | |
1116 | } | |
1117 | ||
1118 | /** | |
97c71024 | 1119 | * Handler for the selection range signal. |
4999a196 GB |
1120 | * |
1121 | * @param signal | |
1122 | * The signal that's received | |
97c71024 | 1123 | * @since 1.0 |
4999a196 GB |
1124 | */ |
1125 | @TmfSignalHandler | |
97c71024 | 1126 | public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) { |
4999a196 GB |
1127 | if (signal.getSource() == this || fTrace == null) { |
1128 | return; | |
1129 | } | |
0fcf3b09 PT |
1130 | final long beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
1131 | final long endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
4999a196 GB |
1132 | |
1133 | Display.getDefault().asyncExec(new Runnable() { | |
1134 | @Override | |
1135 | public void run() { | |
747adf5c | 1136 | if (fTimeGraphWrapper.isDisposed()) { |
4999a196 GB |
1137 | return; |
1138 | } | |
0fcf3b09 | 1139 | if (beginTime == endTime) { |
747adf5c | 1140 | fTimeGraphWrapper.getTimeGraphViewer().setSelectedTime(beginTime, true); |
0fcf3b09 | 1141 | } else { |
747adf5c | 1142 | fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(beginTime, endTime); |
0fcf3b09 | 1143 | } |
53ffb5b2 | 1144 | synchingToTime(fTimeGraphWrapper.getTimeGraphViewer().getTime0()); |
4999a196 GB |
1145 | } |
1146 | }); | |
1147 | } | |
1148 | ||
1149 | /** | |
97c71024 | 1150 | * Handler for the window range signal. |
4999a196 GB |
1151 | * |
1152 | * @param signal | |
1153 | * The signal that's received | |
97c71024 | 1154 | * @since 1.0 |
4999a196 GB |
1155 | */ |
1156 | @TmfSignalHandler | |
97c71024 | 1157 | public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) { |
4999a196 GB |
1158 | if (signal.getSource() == this || fTrace == null) { |
1159 | return; | |
1160 | } | |
1161 | if (signal.getCurrentRange().getIntersection(fTrace.getTimeRange()) == null) { | |
1162 | return; | |
1163 | } | |
1164 | final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
1165 | final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
4999a196 GB |
1166 | Display.getDefault().asyncExec(new Runnable() { |
1167 | @Override | |
1168 | public void run() { | |
747adf5c | 1169 | if (fTimeGraphWrapper.isDisposed()) { |
4999a196 GB |
1170 | return; |
1171 | } | |
747adf5c | 1172 | fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime); |
4999a196 GB |
1173 | startZoomThread(startTime, endTime); |
1174 | } | |
1175 | }); | |
1176 | } | |
1177 | ||
c1cd9635 MAL |
1178 | /** |
1179 | * @param signal the format of the timestamps was updated. | |
1180 | */ | |
1181 | @TmfSignalHandler | |
1182 | public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal){ | |
747adf5c | 1183 | fTimeGraphWrapper.refresh(); |
c1cd9635 MAL |
1184 | } |
1185 | ||
4999a196 GB |
1186 | // ------------------------------------------------------------------------ |
1187 | // Internal | |
1188 | // ------------------------------------------------------------------------ | |
1189 | ||
4923d7b9 | 1190 | private void loadTrace(final ITmfTrace trace) { |
6ae6c5bd PT |
1191 | if (fZoomThread != null) { |
1192 | fZoomThread.cancel(); | |
1193 | fZoomThread = null; | |
1194 | } | |
4923d7b9 PT |
1195 | if (fTrace != null) { |
1196 | /* save the filters of the previous trace */ | |
1197 | fFiltersMap.put(fTrace, fTimeGraphWrapper.getFilters()); | |
1198 | } | |
1199 | fTrace = trace; | |
4999a196 GB |
1200 | synchronized (fEntryListMap) { |
1201 | fEntryList = fEntryListMap.get(fTrace); | |
1202 | if (fEntryList == null) { | |
50c2da9e | 1203 | rebuild(); |
4999a196 GB |
1204 | } else { |
1205 | fStartTime = fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
1206 | fEndTime = fTrace.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
1207 | refresh(); | |
1208 | } | |
1209 | } | |
1210 | } | |
1211 | ||
50c2da9e GB |
1212 | /** |
1213 | * Forces a rebuild of the entries list, even if entries already exist for this trace | |
50c2da9e GB |
1214 | */ |
1215 | protected void rebuild() { | |
1216 | setStartTime(Long.MAX_VALUE); | |
1217 | setEndTime(Long.MIN_VALUE); | |
6b8d11bd | 1218 | refresh(); |
dfa0ef96 GB |
1219 | ITmfTrace viewTrace = fTrace; |
1220 | if (viewTrace == null) { | |
1221 | return; | |
1222 | } | |
50c2da9e | 1223 | synchronized (fBuildThreadMap) { |
dfa0ef96 GB |
1224 | for (ITmfTrace trace : getTracesToBuild(viewTrace)) { |
1225 | if (trace == null) { | |
1226 | break; | |
1227 | } | |
1228 | BuildThread buildThread = new BuildThread(trace, viewTrace, getName()); | |
50c2da9e GB |
1229 | fBuildThreadMap.put(trace, buildThread); |
1230 | buildThread.start(); | |
1231 | } | |
1232 | } | |
1233 | } | |
1234 | ||
4999a196 GB |
1235 | /** |
1236 | * Method called when synching to a given timestamp. Inheriting classes can | |
1237 | * perform actions here to update the view at the given timestamp. | |
1238 | * | |
1239 | * @param time | |
1240 | * The currently selected time | |
1241 | */ | |
1242 | protected void synchingToTime(long time) { | |
1243 | ||
1244 | } | |
1245 | ||
41cc4f90 GB |
1246 | /** |
1247 | * Return the list of traces whose data or analysis results will be used to | |
1248 | * populate the view. By default, if the trace is an experiment, the traces | |
1249 | * under it will be returned, otherwise, the trace itself is returned. | |
1250 | * | |
1251 | * A build thread will be started for each trace returned by this method, | |
1252 | * some of which may receive events in live streaming mode. | |
1253 | * | |
1254 | * @param trace | |
1255 | * The trace associated with this view | |
1256 | * @return List of traces with data to display | |
41cc4f90 | 1257 | */ |
dfa0ef96 | 1258 | protected @NonNull Iterable<ITmfTrace> getTracesToBuild(@NonNull ITmfTrace trace) { |
c14c0757 | 1259 | return TmfTraceManager.getTraceSet(trace); |
41cc4f90 GB |
1260 | } |
1261 | ||
4999a196 GB |
1262 | /** |
1263 | * Build the entries list to show in this time graph | |
1264 | * | |
1265 | * Called from the BuildThread | |
1266 | * | |
1267 | * @param trace | |
1268 | * The trace being built | |
1cf25311 PT |
1269 | * @param parentTrace |
1270 | * The parent of the trace set, or the trace itself | |
4999a196 GB |
1271 | * @param monitor |
1272 | * The progress monitor object | |
1273 | */ | |
dfa0ef96 | 1274 | protected abstract void buildEventList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor); |
4999a196 GB |
1275 | |
1276 | /** | |
1277 | * Gets the list of event for an entry in a given timerange | |
1278 | * | |
1279 | * @param entry | |
1280 | * The entry to get events for | |
1281 | * @param startTime | |
1282 | * Start of the time range | |
1283 | * @param endTime | |
1284 | * End of the time range | |
1285 | * @param resolution | |
1286 | * The resolution | |
1287 | * @param monitor | |
1288 | * The progress monitor object | |
1289 | * @return The list of events for the entry | |
1290 | */ | |
dfa0ef96 | 1291 | protected abstract @Nullable List<ITimeEvent> getEventList(@NonNull TimeGraphEntry entry, |
4999a196 | 1292 | long startTime, long endTime, long resolution, |
dfa0ef96 | 1293 | @NonNull IProgressMonitor monitor); |
4999a196 | 1294 | |
bec1f1ac GB |
1295 | /** |
1296 | * Gets the list of links (displayed as arrows) for a trace in a given | |
1297 | * timerange. Default implementation returns an empty list. | |
1298 | * | |
1299 | * @param startTime | |
1300 | * Start of the time range | |
1301 | * @param endTime | |
1302 | * End of the time range | |
1303 | * @param resolution | |
1304 | * The resolution | |
1305 | * @param monitor | |
1306 | * The progress monitor object | |
1307 | * @return The list of link events | |
bec1f1ac | 1308 | */ |
dfa0ef96 GB |
1309 | protected @Nullable List<ILinkEvent> getLinkList(long startTime, long endTime, |
1310 | long resolution, @NonNull IProgressMonitor monitor) { | |
507b1336 | 1311 | return new ArrayList<>(); |
bec1f1ac GB |
1312 | } |
1313 | ||
e790b877 PT |
1314 | /** |
1315 | * Gets the list of markers for a trace in a given time range. Default | |
1316 | * implementation returns an empty list. | |
1317 | * | |
1318 | * @param startTime | |
1319 | * Start of the time range | |
1320 | * @param endTime | |
1321 | * End of the time range | |
1322 | * @param resolution | |
1323 | * The resolution | |
1324 | * @param monitor | |
1325 | * The progress monitor object | |
1326 | * @return The list of marker events | |
1327 | * @since 2.0 | |
1328 | */ | |
1329 | protected @Nullable List<IMarkerEvent> getMarkerList(long startTime, long endTime, | |
1330 | long resolution, @NonNull IProgressMonitor monitor) { | |
1331 | return new ArrayList<>(); | |
1332 | } | |
bec1f1ac | 1333 | |
4999a196 GB |
1334 | /** |
1335 | * Refresh the display | |
1336 | */ | |
1337 | protected void refresh() { | |
6ae6c5bd | 1338 | final boolean zoomThread = Thread.currentThread() instanceof ZoomThread; |
08593856 | 1339 | TmfUiRefreshHandler.getInstance().queueUpdate(this, new Runnable() { |
4999a196 GB |
1340 | @Override |
1341 | public void run() { | |
747adf5c | 1342 | if (fTimeGraphWrapper.isDisposed()) { |
4999a196 GB |
1343 | return; |
1344 | } | |
1cf25311 | 1345 | boolean hasEntries = false; |
4999a196 GB |
1346 | synchronized (fEntryListMap) { |
1347 | fEntryList = fEntryListMap.get(fTrace); | |
1348 | if (fEntryList == null) { | |
1cf25311 PT |
1349 | fEntryList = new CopyOnWriteArrayList<>(); |
1350 | } else if (fEntryComparator != null) { | |
1351 | List<TimeGraphEntry> list = new ArrayList<>(fEntryList); | |
1352 | Collections.sort(list, fEntryComparator); | |
1353 | fEntryList.clear(); | |
1354 | fEntryList.addAll(list); | |
4999a196 | 1355 | } |
1cf25311 | 1356 | hasEntries = fEntryList.size() != 0; |
4999a196 | 1357 | } |
1cf25311 PT |
1358 | if (fEntryList != fTimeGraphWrapper.getInput()) { |
1359 | fTimeGraphWrapper.setInput(fEntryList); | |
4923d7b9 PT |
1360 | /* restore the previously saved filters, if any */ |
1361 | fTimeGraphWrapper.setFilters(fFiltersMap.get(fTrace)); | |
6ae6c5bd | 1362 | fTimeGraphWrapper.getTimeGraphViewer().setLinks(null); |
1cf25311 PT |
1363 | } else { |
1364 | fTimeGraphWrapper.refresh(); | |
4999a196 | 1365 | } |
335b04e6 PT |
1366 | long startBound = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : fStartTime); |
1367 | long endBound = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : fEndTime); | |
1368 | fTimeGraphWrapper.getTimeGraphViewer().setTimeBounds(startBound, endBound); | |
4999a196 | 1369 | |
21852dfa | 1370 | TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext(); |
335b04e6 PT |
1371 | long selectionBeginTime = fTrace == null ? SWT.DEFAULT : ctx.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
1372 | long selectionEndTime = fTrace == null ? SWT.DEFAULT : ctx.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
1373 | long startTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
1374 | long endTime = fTrace == null ? SWT.DEFAULT : ctx.getWindowRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
1375 | startTime = (fStartTime == Long.MAX_VALUE ? SWT.DEFAULT : Math.max(startTime, fStartTime)); | |
1376 | endTime = (fEndTime == Long.MIN_VALUE ? SWT.DEFAULT : Math.min(endTime, fEndTime)); | |
747adf5c PT |
1377 | fTimeGraphWrapper.getTimeGraphViewer().setSelectionRange(selectionBeginTime, selectionEndTime); |
1378 | fTimeGraphWrapper.getTimeGraphViewer().setStartFinishTime(startTime, endTime); | |
4999a196 | 1379 | |
1cf25311 | 1380 | if (fTimeGraphWrapper instanceof TimeGraphComboWrapper && !fPackDone) { |
747adf5c PT |
1381 | for (TreeColumn column : ((TimeGraphComboWrapper) fTimeGraphWrapper).getTreeViewer().getTree().getColumns()) { |
1382 | column.pack(); | |
1383 | } | |
1cf25311 PT |
1384 | if (hasEntries) { |
1385 | fPackDone = true; | |
1386 | } | |
4999a196 GB |
1387 | } |
1388 | ||
6ae6c5bd PT |
1389 | if (!zoomThread) { |
1390 | startZoomThread(startTime, endTime); | |
1391 | } | |
4999a196 GB |
1392 | } |
1393 | }); | |
1394 | } | |
1395 | ||
1396 | /** | |
1397 | * Redraw the canvas | |
1398 | */ | |
1399 | protected void redraw() { | |
1400 | synchronized (fSyncObj) { | |
1401 | if (fRedrawState == State.IDLE) { | |
1402 | fRedrawState = State.BUSY; | |
1403 | } else { | |
1404 | fRedrawState = State.PENDING; | |
1405 | return; | |
1406 | } | |
1407 | } | |
1408 | Display.getDefault().asyncExec(new Runnable() { | |
1409 | @Override | |
1410 | public void run() { | |
747adf5c | 1411 | if (fTimeGraphWrapper.isDisposed()) { |
4999a196 GB |
1412 | return; |
1413 | } | |
747adf5c PT |
1414 | fTimeGraphWrapper.redraw(); |
1415 | fTimeGraphWrapper.update(); | |
4999a196 GB |
1416 | synchronized (fSyncObj) { |
1417 | if (fRedrawState == State.PENDING) { | |
1418 | fRedrawState = State.IDLE; | |
1419 | redraw(); | |
1420 | } else { | |
1421 | fRedrawState = State.IDLE; | |
1422 | } | |
1423 | } | |
1424 | } | |
1425 | }); | |
1426 | } | |
1427 | ||
1428 | private void startZoomThread(long startTime, long endTime) { | |
6ae6c5bd | 1429 | boolean restart = false; |
4999a196 GB |
1430 | if (fZoomThread != null) { |
1431 | fZoomThread.cancel(); | |
6ae6c5bd PT |
1432 | if (fZoomThread.fZoomStartTime == startTime && fZoomThread.fZoomEndTime == endTime) { |
1433 | restart = true; | |
1434 | } | |
1435 | } | |
1436 | long resolution = Math.max(1, (endTime - startTime) / fDisplayWidth); | |
1437 | fZoomThread = createZoomThread(startTime, endTime, resolution, restart); | |
1438 | if (fZoomThread != null) { | |
1439 | fZoomThread.start(); | |
4999a196 | 1440 | } |
6ae6c5bd PT |
1441 | } |
1442 | ||
1443 | /** | |
1444 | * Create a zoom thread. | |
1445 | * | |
1446 | * @param startTime | |
1447 | * the zoom start time | |
1448 | * @param endTime | |
1449 | * the zoom end time | |
1450 | * @param resolution | |
1451 | * the resolution | |
1452 | * @param restart | |
1453 | * true if restarting zoom for the same time range | |
1454 | * @return a zoom thread | |
3de2428b | 1455 | * @since 2.0 |
6ae6c5bd PT |
1456 | */ |
1457 | protected @Nullable ZoomThread createZoomThread(long startTime, long endTime, long resolution, boolean restart) { | |
dfa0ef96 GB |
1458 | final List<TimeGraphEntry> entryList = fEntryList; |
1459 | if (entryList == null) { | |
6ae6c5bd | 1460 | return null; |
dfa0ef96 | 1461 | } |
6ae6c5bd | 1462 | return new ZoomThreadByEntry(entryList, startTime, endTime, resolution); |
4999a196 GB |
1463 | } |
1464 | ||
1465 | private void makeActions() { | |
747adf5c | 1466 | fPreviousResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getPreviousItemAction(); |
4999a196 GB |
1467 | fPreviousResourceAction.setText(getPrevText()); |
1468 | fPreviousResourceAction.setToolTipText(getPrevTooltip()); | |
747adf5c | 1469 | fNextResourceAction = fTimeGraphWrapper.getTimeGraphViewer().getNextItemAction(); |
4999a196 GB |
1470 | fNextResourceAction.setText(getNextText()); |
1471 | fNextResourceAction.setToolTipText(getNextTooltip()); | |
1472 | } | |
1473 | ||
1474 | private void contributeToActionBars() { | |
1475 | IActionBars bars = getViewSite().getActionBars(); | |
1476 | fillLocalToolBar(bars.getToolBarManager()); | |
1477 | } | |
1478 | ||
79ec0b89 PT |
1479 | /** |
1480 | * Add actions to local tool bar manager | |
1481 | * | |
1482 | * @param manager the tool bar manager | |
1483 | */ | |
1484 | protected void fillLocalToolBar(IToolBarManager manager) { | |
cfcfd964 PT |
1485 | if (fFilterColumns != null && fFilterLabelProvider != null && fFilterColumns.length > 0) { |
1486 | manager.add(fTimeGraphWrapper.getShowFilterDialogAction()); | |
4999a196 | 1487 | } |
747adf5c | 1488 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getShowLegendAction()); |
4999a196 | 1489 | manager.add(new Separator()); |
747adf5c PT |
1490 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getResetScaleAction()); |
1491 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getPreviousEventAction()); | |
1492 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getNextEventAction()); | |
4999a196 GB |
1493 | manager.add(fPreviousResourceAction); |
1494 | manager.add(fNextResourceAction); | |
747adf5c PT |
1495 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomInAction()); |
1496 | manager.add(fTimeGraphWrapper.getTimeGraphViewer().getZoomOutAction()); | |
4999a196 GB |
1497 | manager.add(new Separator()); |
1498 | } | |
d2e4afa7 MAL |
1499 | |
1500 | /** | |
1501 | * @since 1.0 | |
1502 | */ | |
1503 | @Override | |
1504 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { | |
1505 | if (fTimeGraphWrapper == null) { | |
1506 | return null; | |
1507 | } | |
1508 | return fTimeGraphWrapper.getTimeViewAlignmentInfo(); | |
1509 | } | |
1510 | ||
1511 | /** | |
1512 | * @since 1.0 | |
1513 | */ | |
1514 | @Override | |
1515 | public int getAvailableWidth(int requestedOffset) { | |
1516 | if (fTimeGraphWrapper == null) { | |
1517 | return 0; | |
1518 | } | |
1519 | return fTimeGraphWrapper.getAvailableWidth(requestedOffset); | |
1520 | } | |
1521 | ||
1522 | /** | |
1523 | * @since 1.0 | |
1524 | */ | |
1525 | @Override | |
1526 | public void performAlign(int offset, int width) { | |
1527 | if (fTimeGraphWrapper != null) { | |
1528 | fTimeGraphWrapper.performAlign(offset, width); | |
1529 | } | |
1530 | } | |
4999a196 | 1531 | } |