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