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