1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
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
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
13 * Marc-Andre Laperle - Add time zone preference
14 * Geneviève Bastien - Add event links between entries
15 *******************************************************************************/
17 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
;
19 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Arrays
;
23 import java
.util
.Collections
;
24 import java
.util
.Comparator
;
25 import java
.util
.HashMap
;
26 import java
.util
.List
;
28 import java
.util
.concurrent
.CopyOnWriteArrayList
;
30 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
31 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
32 import org
.eclipse
.jdt
.annotation
.NonNull
;
33 import org
.eclipse
.jdt
.annotation
.Nullable
;
34 import org
.eclipse
.jface
.action
.Action
;
35 import org
.eclipse
.jface
.action
.IAction
;
36 import org
.eclipse
.jface
.action
.IStatusLineManager
;
37 import org
.eclipse
.jface
.action
.IToolBarManager
;
38 import org
.eclipse
.jface
.action
.Separator
;
39 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
40 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
41 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
42 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
43 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
44 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
45 import org
.eclipse
.jface
.viewers
.TreeViewer
;
46 import org
.eclipse
.jface
.viewers
.Viewer
;
47 import org
.eclipse
.swt
.SWT
;
48 import org
.eclipse
.swt
.graphics
.Image
;
49 import org
.eclipse
.swt
.widgets
.Composite
;
50 import org
.eclipse
.swt
.widgets
.Display
;
51 import org
.eclipse
.swt
.widgets
.TreeColumn
;
52 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfRangeSynchSignal
;
53 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
54 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
55 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
56 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
57 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
58 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
59 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
60 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
61 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
62 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
63 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
81 import org
.eclipse
.ui
.IActionBars
;
84 * An abstract view all time graph views can inherit
86 * This view contains either a time graph viewer, or a time graph combo which is
87 * divided between a tree viewer on the left and a time graph viewer on the right.
91 public abstract class AbstractTimeGraphView
extends TmfView
{
93 /** Constant indicating that all levels of the time graph should be expanded */
94 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
103 // ------------------------------------------------------------------------
105 // ------------------------------------------------------------------------
107 /** The timegraph wrapper */
108 private ITimeGraphWrapper fTimeGraphWrapper
;
110 /** The selected trace */
111 private ITmfTrace fTrace
;
113 /** The timegraph entry list */
114 private List
<TimeGraphEntry
> fEntryList
;
116 /** The trace to entry list hash map */
117 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
119 /** The trace to build thread hash map */
120 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
122 /** The start time */
123 private long fStartTime
;
126 private long fEndTime
;
128 /** The display width */
129 private final int fDisplayWidth
;
131 /** The zoom thread */
132 private ZoomThread fZoomThread
;
134 /** The next resource action */
135 private Action fNextResourceAction
;
137 /** The previous resource action */
138 private Action fPreviousResourceAction
;
140 /** A comparator class */
141 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
143 /** The redraw state used to prevent unnecessary queuing of display runnables */
144 private State fRedrawState
= State
.IDLE
;
146 /** The redraw synchronization object */
147 private final Object fSyncObj
= new Object();
149 /** The presentation provider for this view */
150 private final TimeGraphPresentationProvider fPresentation
;
152 /** The tree column label array, or null if combo is not used */
153 private String
[] fColumns
;
155 /** The tree label provider, or null if combo is not used */
156 private TreeLabelProvider fLabelProvider
= null;
158 /** The relative weight of the sash, ignored if combo is not used */
159 private int[] fWeight
= { 1, 1 };
161 /** The filter column label array, or null if filter is not used */
162 private String
[] fFilterColumns
;
164 /** The pack done flag */
165 private boolean fPackDone
= false;
167 /** The filter label provider, or null if filter is not used */
168 private TreeLabelProvider fFilterLabelProvider
;
170 private int fAutoExpandLevel
= ALL_LEVELS
;
172 // ------------------------------------------------------------------------
174 // ------------------------------------------------------------------------
176 private interface ITimeGraphWrapper
{
178 void setTimeGraphProvider(TimeGraphPresentationProvider fPresentation
);
180 TimeGraphViewer
getTimeGraphViewer();
182 void addSelectionListener(ITimeGraphSelectionListener iTimeGraphSelectionListener
);
184 ISelectionProvider
getSelectionProvider();
188 boolean isDisposed();
192 void setInput(Object input
);
200 void setAutoExpandLevel(int level
);
204 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
205 private TimeGraphViewer viewer
;
207 private TimeGraphViewerWrapper(Composite parent
, int style
) {
208 viewer
= new TimeGraphViewer(parent
, style
);
212 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
213 viewer
.setTimeGraphProvider(timeGraphProvider
);
217 public TimeGraphViewer
getTimeGraphViewer() {
222 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
223 viewer
.addSelectionListener(listener
);
227 public ISelectionProvider
getSelectionProvider() {
228 return viewer
.getSelectionProvider();
232 public void setFocus() {
237 public boolean isDisposed() {
238 return viewer
.getControl().isDisposed();
242 public void setInput(Object input
) {
243 viewer
.setInput(input
);
247 public Object
getInput() {
248 return viewer
.getInput();
252 public void refresh() {
257 public void redraw() {
258 viewer
.getControl().redraw();
262 public void update() {
263 viewer
.getControl().update();
267 public void setAutoExpandLevel(int level
) {
268 viewer
.setAutoExpandLevel(level
);
272 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
273 private TimeGraphCombo combo
;
275 private TimeGraphComboWrapper(Composite parent
, int style
) {
276 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
280 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
281 combo
.setTimeGraphProvider(timeGraphProvider
);
285 public TimeGraphViewer
getTimeGraphViewer() {
286 return combo
.getTimeGraphViewer();
290 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
291 combo
.addSelectionListener(listener
);
295 public ISelectionProvider
getSelectionProvider() {
296 return combo
.getTreeViewer();
300 public void setFocus() {
305 public boolean isDisposed() {
306 return combo
.isDisposed();
310 public void setInput(Object input
) {
311 combo
.setInput(input
);
315 public Object
getInput() {
316 return combo
.getInput();
320 public void refresh() {
325 public void redraw() {
330 public void update() {
335 public void setAutoExpandLevel(int level
) {
336 combo
.setAutoExpandLevel(level
);
339 TimeGraphCombo
getTimeGraphCombo() {
343 TreeViewer
getTreeViewer() {
344 return combo
.getTreeViewer();
347 IAction
getShowFilterAction() {
348 return combo
.getShowFilterAction();
352 private class TreeContentProvider
implements ITreeContentProvider
{
355 public void dispose() {
359 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
363 public ITimeGraphEntry
[] getElements(Object inputElement
) {
364 if (inputElement
!= null) {
366 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
367 } catch (ClassCastException e
) {
370 return new ITimeGraphEntry
[0];
374 public Object
[] getChildren(Object parentElement
) {
375 ITimeGraphEntry entry
= (ITimeGraphEntry
) parentElement
;
376 List
<?
extends ITimeGraphEntry
> children
= entry
.getChildren();
377 return children
.toArray(new ITimeGraphEntry
[children
.size()]);
381 public Object
getParent(Object element
) {
382 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
383 return entry
.getParent();
387 public boolean hasChildren(Object element
) {
388 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
389 return entry
.hasChildren();
394 private class TimeGraphContentProvider
implements ITimeGraphContentProvider
{
397 public ITimeGraphEntry
[] getElements(Object inputElement
) {
398 if (inputElement
!= null) {
400 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
401 } catch (ClassCastException e
) {
404 return new ITimeGraphEntry
[0];
410 * Base class to provide the labels for the tree viewer. Views extending
411 * this class typically need to override the getColumnText method if they
412 * have more than one column to display
414 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
417 public void addListener(ILabelProviderListener listener
) {
421 public void dispose() {
425 public boolean isLabelProperty(Object element
, String property
) {
430 public void removeListener(ILabelProviderListener listener
) {
434 public Image
getColumnImage(Object element
, int columnIndex
) {
439 public String
getColumnText(Object element
, int columnIndex
) {
440 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
441 if (columnIndex
== 0) {
442 return entry
.getName();
451 public Image
getImage(Object element
) {
459 public String
getText(Object element
) {
460 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
461 return entry
.getName();
466 private class BuildThread
extends Thread
{
467 private final @NonNull ITmfTrace fBuildTrace
;
468 private final @NonNull ITmfTrace fParentTrace
;
469 private final @NonNull IProgressMonitor fMonitor
;
471 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
472 super(name
+ " build"); //$NON-NLS-1$
474 fParentTrace
= parentTrace
;
475 fMonitor
= new NullProgressMonitor();
480 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
481 synchronized (fBuildThreadMap
) {
482 fBuildThreadMap
.remove(fBuildTrace
);
486 public void cancel() {
487 fMonitor
.setCanceled(true);
491 private class ZoomThread
extends Thread
{
492 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
493 private final long fZoomStartTime
;
494 private final long fZoomEndTime
;
495 private final long fResolution
;
496 private final @NonNull IProgressMonitor fMonitor
;
498 public ZoomThread(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, String name
) {
499 super(name
+ " zoom"); //$NON-NLS-1$
500 fZoomEntryList
= entryList
;
501 fZoomStartTime
= startTime
;
502 fZoomEndTime
= endTime
;
503 fResolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
504 fMonitor
= new NullProgressMonitor();
509 for (TimeGraphEntry entry
: fZoomEntryList
) {
510 if (fMonitor
.isCanceled()) {
516 zoom(entry
, fMonitor
);
518 /* Refresh the arrows when zooming */
519 List
<ILinkEvent
> events
= getLinkList(fZoomStartTime
, fZoomEndTime
, fResolution
, fMonitor
);
520 if (events
!= null) {
521 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
526 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
527 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
528 entry
.setZoomedEventList(null);
530 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, fResolution
, monitor
);
531 if (zoomedEventList
!= null) {
532 entry
.setZoomedEventList(zoomedEventList
);
536 for (ITimeGraphEntry child
: entry
.getChildren()) {
537 if (fMonitor
.isCanceled()) {
540 if (child
instanceof TimeGraphEntry
) {
541 zoom((TimeGraphEntry
) child
, monitor
);
546 public void cancel() {
547 fMonitor
.setCanceled(true);
551 // ------------------------------------------------------------------------
553 // ------------------------------------------------------------------------
556 * Constructs a time graph view that contains either a time graph viewer or
557 * a time graph combo.
559 * By default, the view uses a time graph viewer. To use a time graph combo,
560 * the subclass constructor must call {@link #setTreeColumns(String[])} and
561 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
566 * The presentation provider
568 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
570 fPresentation
= pres
;
571 fDisplayWidth
= Display
.getDefault().getBounds().width
;
574 // ------------------------------------------------------------------------
575 // Getters and setters
576 // ------------------------------------------------------------------------
579 * Getter for the time graph combo
581 * @return The time graph combo, or null if combo is not used
583 protected TimeGraphCombo
getTimeGraphCombo() {
584 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
585 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
591 * Getter for the time graph viewer
593 * @return The time graph viewer
595 protected TimeGraphViewer
getTimeGraphViewer() {
596 return fTimeGraphWrapper
.getTimeGraphViewer();
600 * Getter for the presentation provider
602 * @return The time graph presentation provider
605 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
606 return fPresentation
;
610 * Sets the tree column labels.
611 * This should be called from the constructor.
614 * The array of tree column labels
616 protected void setTreeColumns(final String
[] columns
) {
621 * Sets the tree label provider.
622 * This should be called from the constructor.
625 * The tree label provider
627 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
628 fLabelProvider
= tlp
;
632 * Sets the relative weight of each part of the time graph combo.
633 * This should be called from the constructor.
636 * The array (length 2) of relative weights of each part of the combo
638 protected void setWeight(final int[] weights
) {
643 * Sets the filter column labels.
644 * This should be called from the constructor.
646 * @param filterColumns
647 * The array of filter column labels
649 protected void setFilterColumns(final String
[] filterColumns
) {
650 fFilterColumns
= filterColumns
;
654 * Sets the filter label provider.
655 * This should be called from the constructor.
657 * @param labelProvider
658 * The filter label provider
662 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
663 fFilterLabelProvider
= labelProvider
;
667 * Gets the display width
669 * @return the display width
671 protected int getDisplayWidth() {
672 return fDisplayWidth
;
676 * Gets the comparator for the entries
678 * @return The entry comparator
680 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
681 return fEntryComparator
;
685 * Sets the comparator class for the entries
688 * A comparator object
690 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
691 fEntryComparator
= comparator
;
695 * Gets the trace displayed in the view
699 protected ITmfTrace
getTrace() {
704 * Gets the start time
706 * @return The start time
708 protected long getStartTime() {
713 * Sets the start time
718 protected void setStartTime(long time
) {
725 * @return The end time
727 protected long getEndTime() {
737 protected void setEndTime(long time
) {
742 * Sets the auto-expand level to be used for the input of the view. The
743 * value 0 means that there is no auto-expand; 1 means that top-level
744 * elements are expanded, but not their children; 2 means that top-level
745 * elements are expanded, and their children, but not grand-children; and so
748 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
752 * non-negative level, or <code>ALL_LEVELS</code> to expand all
755 protected void setAutoExpandLevel(int level
) {
756 fAutoExpandLevel
= level
;
757 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
758 if (tgWrapper
!= null) {
759 tgWrapper
.setAutoExpandLevel(level
);
764 * Gets the entry list for a trace
769 * @return the entry list map
772 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
773 synchronized (fEntryListMap
) {
774 return fEntryListMap
.get(trace
);
779 * Adds a trace entry list to the entry list map
784 * the list of time graph entries
786 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
787 synchronized (fEntryListMap
) {
788 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
793 * Adds a list of entries to a trace's entry list
798 * the list of time graph entries to add
801 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
802 synchronized (fEntryListMap
) {
803 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
804 if (entryList
== null) {
805 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
807 entryList
.addAll(list
);
813 * Removes a list of entries from a trace's entry list
818 * the list of time graph entries to remove
821 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
822 synchronized (fEntryListMap
) {
823 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
824 if (entryList
!= null) {
825 entryList
.removeAll(list
);
831 * Text for the "next" button
833 * @return The "next" button text
835 protected String
getNextText() {
836 return Messages
.AbstractTimeGraphtView_NextText
;
840 * Tooltip for the "next" button
842 * @return Tooltip for the "next" button
844 protected String
getNextTooltip() {
845 return Messages
.AbstractTimeGraphView_NextTooltip
;
849 * Text for the "Previous" button
851 * @return The "Previous" button text
853 protected String
getPrevText() {
854 return Messages
.AbstractTimeGraphView_PreviousText
;
858 * Tooltip for the "previous" button
860 * @return Tooltip for the "previous" button
862 protected String
getPrevTooltip() {
863 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
866 // ------------------------------------------------------------------------
868 // ------------------------------------------------------------------------
871 public void createPartControl(Composite parent
) {
872 if (fColumns
== null || fLabelProvider
== null) {
873 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
874 TimeGraphViewer viewer
= fTimeGraphWrapper
.getTimeGraphViewer();
875 viewer
.setTimeGraphContentProvider(new TimeGraphContentProvider());
877 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
878 fTimeGraphWrapper
= wrapper
;
879 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
880 combo
.setTreeContentProvider(new TreeContentProvider());
881 combo
.setTreeLabelProvider(fLabelProvider
);
882 combo
.setTreeColumns(fColumns
);
883 combo
.setFilterContentProvider(new TreeContentProvider());
884 combo
.setFilterLabelProvider(fFilterLabelProvider
);
885 combo
.setFilterColumns(fFilterColumns
);
886 combo
.setTimeGraphContentProvider(new TimeGraphContentProvider());
889 fTimeGraphWrapper
.setTimeGraphProvider(fPresentation
);
890 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
892 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
894 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
895 final long startTime
= event
.getStartTime();
896 final long endTime
= event
.getEndTime();
897 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
898 broadcast(new TmfRangeSynchSignal(AbstractTimeGraphView
.this, range
));
899 startZoomThread(startTime
, endTime
);
903 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
905 public void timeSelected(TimeGraphTimeEvent event
) {
906 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
907 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
908 broadcast(new TmfTimeSynchSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
912 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
914 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
915 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
917 // View Action Handling
919 contributeToActionBars();
921 ITmfTrace trace
= getActiveTrace();
923 traceSelected(new TmfTraceSelectedSignal(this, trace
));
926 // make selection available to other views
927 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
931 public void setFocus() {
932 fTimeGraphWrapper
.setFocus();
935 // ------------------------------------------------------------------------
937 // ------------------------------------------------------------------------
940 * Handler for the trace opened signal.
943 * The incoming signal
947 public void traceOpened(TmfTraceOpenedSignal signal
) {
948 fTrace
= signal
.getTrace();
953 * Handler for the trace selected signal
956 * The incoming signal
959 public void traceSelected(final TmfTraceSelectedSignal signal
) {
960 if (signal
.getTrace() == fTrace
) {
963 fTrace
= signal
.getTrace();
969 * Trace is closed: clear the data structures and the view
972 * the signal received
975 public void traceClosed(final TmfTraceClosedSignal signal
) {
976 synchronized (fBuildThreadMap
) {
977 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
978 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
979 if (buildThread
!= null) {
980 buildThread
.cancel();
984 synchronized (fEntryListMap
) {
985 fEntryListMap
.remove(signal
.getTrace());
987 if (signal
.getTrace() == fTrace
) {
991 if (fZoomThread
!= null) {
992 fZoomThread
.cancel();
999 * Handler for the time synch signal
1002 * The signal that's received
1005 public void synchToTime(final TmfTimeSynchSignal signal
) {
1006 if (signal
.getSource() == this || fTrace
== null) {
1009 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1010 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1012 Display
.getDefault().asyncExec(new Runnable() {
1015 if (fTimeGraphWrapper
.isDisposed()) {
1018 if (beginTime
== endTime
) {
1019 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1021 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
);
1023 startZoomThread(fTimeGraphWrapper
.getTimeGraphViewer().getTime0(), fTimeGraphWrapper
.getTimeGraphViewer().getTime1());
1025 synchingToTime(beginTime
);
1031 * Handler for the range synch signal
1034 * The signal that's received
1037 public void synchToRange(final TmfRangeSynchSignal signal
) {
1038 if (signal
.getSource() == this || fTrace
== null) {
1041 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1044 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1045 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1046 Display
.getDefault().asyncExec(new Runnable() {
1049 if (fTimeGraphWrapper
.isDisposed()) {
1052 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1053 startZoomThread(startTime
, endTime
);
1059 * @param signal the format of the timestamps was updated.
1063 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1064 fTimeGraphWrapper
.refresh();
1067 // ------------------------------------------------------------------------
1069 // ------------------------------------------------------------------------
1071 private void loadTrace() {
1072 synchronized (fEntryListMap
) {
1073 fEntryList
= fEntryListMap
.get(fTrace
);
1074 if (fEntryList
== null) {
1077 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1078 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1085 * Forces a rebuild of the entries list, even if entries already exist for this trace
1088 protected void rebuild() {
1089 setStartTime(Long
.MAX_VALUE
);
1090 setEndTime(Long
.MIN_VALUE
);
1092 ITmfTrace viewTrace
= fTrace
;
1093 if (viewTrace
== null) {
1096 synchronized (fBuildThreadMap
) {
1097 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1098 if (trace
== null) {
1101 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1102 fBuildThreadMap
.put(trace
, buildThread
);
1103 buildThread
.start();
1109 * Method called when synching to a given timestamp. Inheriting classes can
1110 * perform actions here to update the view at the given timestamp.
1113 * The currently selected time
1115 protected void synchingToTime(long time
) {
1120 * Return the list of traces whose data or analysis results will be used to
1121 * populate the view. By default, if the trace is an experiment, the traces
1122 * under it will be returned, otherwise, the trace itself is returned.
1124 * A build thread will be started for each trace returned by this method,
1125 * some of which may receive events in live streaming mode.
1128 * The trace associated with this view
1129 * @return List of traces with data to display
1132 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1133 return checkNotNull(Arrays
.asList(TmfTraceManager
.getTraceSet(trace
)));
1137 * Build the entries list to show in this time graph
1139 * Called from the BuildThread
1142 * The trace being built
1143 * @param parentTrace
1144 * The parent of the trace set, or the trace itself
1146 * The progress monitor object
1149 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1152 * Gets the list of event for an entry in a given timerange
1155 * The entry to get events for
1157 * Start of the time range
1159 * End of the time range
1163 * The progress monitor object
1164 * @return The list of events for the entry
1166 protected abstract @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1167 long startTime
, long endTime
, long resolution
,
1168 @NonNull IProgressMonitor monitor
);
1171 * Gets the list of links (displayed as arrows) for a trace in a given
1172 * timerange. Default implementation returns an empty list.
1175 * Start of the time range
1177 * End of the time range
1181 * The progress monitor object
1182 * @return The list of link events
1185 protected @Nullable List
<ILinkEvent
> getLinkList(long startTime
, long endTime
,
1186 long resolution
, @NonNull IProgressMonitor monitor
) {
1187 return new ArrayList
<>();
1192 * Refresh the display
1194 protected void refresh() {
1195 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1198 if (fTimeGraphWrapper
.isDisposed()) {
1201 boolean hasEntries
= false;
1202 synchronized (fEntryListMap
) {
1203 fEntryList
= fEntryListMap
.get(fTrace
);
1204 if (fEntryList
== null) {
1205 fEntryList
= new CopyOnWriteArrayList
<>();
1206 } else if (fEntryComparator
!= null) {
1207 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1208 Collections
.sort(list
, fEntryComparator
);
1210 fEntryList
.addAll(list
);
1212 hasEntries
= fEntryList
.size() != 0;
1214 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1215 fTimeGraphWrapper
.setInput(fEntryList
);
1217 fTimeGraphWrapper
.refresh();
1219 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(fStartTime
, fEndTime
);
1221 long selectionBeginTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1222 long selectionEndTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1223 long startTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1224 long endTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1225 startTime
= Math
.max(startTime
, fStartTime
);
1226 endTime
= Math
.min(endTime
, fEndTime
);
1227 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
);
1228 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1230 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1231 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1239 startZoomThread(startTime
, endTime
);
1247 protected void redraw() {
1248 synchronized (fSyncObj
) {
1249 if (fRedrawState
== State
.IDLE
) {
1250 fRedrawState
= State
.BUSY
;
1252 fRedrawState
= State
.PENDING
;
1256 Display
.getDefault().asyncExec(new Runnable() {
1259 if (fTimeGraphWrapper
.isDisposed()) {
1262 fTimeGraphWrapper
.redraw();
1263 fTimeGraphWrapper
.update();
1264 synchronized (fSyncObj
) {
1265 if (fRedrawState
== State
.PENDING
) {
1266 fRedrawState
= State
.IDLE
;
1269 fRedrawState
= State
.IDLE
;
1276 private void startZoomThread(long startTime
, long endTime
) {
1277 if (fZoomThread
!= null) {
1278 fZoomThread
.cancel();
1280 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1281 if (entryList
== null) {
1284 fZoomThread
= new ZoomThread(entryList
, startTime
, endTime
, getName());
1285 fZoomThread
.start();
1288 private void makeActions() {
1289 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1290 fPreviousResourceAction
.setText(getPrevText());
1291 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1292 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1293 fNextResourceAction
.setText(getNextText());
1294 fNextResourceAction
.setToolTipText(getNextTooltip());
1297 private void contributeToActionBars() {
1298 IActionBars bars
= getViewSite().getActionBars();
1299 fillLocalToolBar(bars
.getToolBarManager());
1303 * Add actions to local tool bar manager
1305 * @param manager the tool bar manager
1307 protected void fillLocalToolBar(IToolBarManager manager
) {
1308 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
1309 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1310 manager
.add(((TimeGraphComboWrapper
) fTimeGraphWrapper
).getShowFilterAction());
1313 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1314 manager
.add(new Separator());
1315 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1316 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1317 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1318 manager
.add(fPreviousResourceAction
);
1319 manager
.add(fNextResourceAction
);
1320 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1321 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1322 manager
.add(new Separator());