1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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 java
.util
.ArrayList
;
20 import java
.util
.Collections
;
21 import java
.util
.Comparator
;
22 import java
.util
.HashMap
;
23 import java
.util
.List
;
25 import java
.util
.concurrent
.CopyOnWriteArrayList
;
27 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
28 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
29 import org
.eclipse
.jdt
.annotation
.NonNull
;
30 import org
.eclipse
.jdt
.annotation
.Nullable
;
31 import org
.eclipse
.jface
.action
.Action
;
32 import org
.eclipse
.jface
.action
.IAction
;
33 import org
.eclipse
.jface
.action
.IStatusLineManager
;
34 import org
.eclipse
.jface
.action
.IToolBarManager
;
35 import org
.eclipse
.jface
.action
.Separator
;
36 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
37 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
38 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
39 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
40 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
41 import org
.eclipse
.jface
.viewers
.TreeViewer
;
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
;
47 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
48 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
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
;
53 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
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
;
58 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
59 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
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
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
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
;
80 import org
.eclipse
.ui
.IActionBars
;
83 * An abstract view all time graph views can inherit
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.
88 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
{
90 /** Constant indicating that all levels of the time graph should be expanded */
91 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
104 /** The timegraph wrapper */
105 private ITimeGraphWrapper fTimeGraphWrapper
;
107 /** The selected trace */
108 private ITmfTrace fTrace
;
110 /** The timegraph entry list */
111 private List
<TimeGraphEntry
> fEntryList
;
113 /** The trace to entry list hash map */
114 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
116 /** The trace to build thread hash map */
117 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
119 /** The start time */
120 private long fStartTime
;
123 private long fEndTime
;
125 /** The display width */
126 private final int fDisplayWidth
;
128 /** The zoom thread */
129 private ZoomThread fZoomThread
;
131 /** The next resource action */
132 private Action fNextResourceAction
;
134 /** The previous resource action */
135 private Action fPreviousResourceAction
;
137 /** A comparator class */
138 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
140 /** The redraw state used to prevent unnecessary queuing of display runnables */
141 private State fRedrawState
= State
.IDLE
;
143 /** The redraw synchronization object */
144 private final Object fSyncObj
= new Object();
146 /** The presentation provider for this view */
147 private final TimeGraphPresentationProvider fPresentation
;
149 /** The tree column label array, or null if combo is not used */
150 private String
[] fColumns
;
152 /** The tree label provider, or null if combo is not used */
153 private TreeLabelProvider fLabelProvider
= null;
155 /** The time graph content provider */
156 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
158 /** The relative weight of the sash, ignored if combo is not used */
159 private int[] fWeight
= { 1, 3 };
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
);
202 void performAlign(int offset
, int width
);
204 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
206 int getAvailableWidth(int requestedOffset
);
209 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
210 private TimeGraphViewer viewer
;
212 private TimeGraphViewerWrapper(Composite parent
, int style
) {
213 viewer
= new TimeGraphViewer(parent
, style
);
217 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
218 viewer
.setTimeGraphProvider(timeGraphProvider
);
222 public TimeGraphViewer
getTimeGraphViewer() {
227 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
228 viewer
.addSelectionListener(listener
);
232 public ISelectionProvider
getSelectionProvider() {
233 return viewer
.getSelectionProvider();
237 public void setFocus() {
242 public boolean isDisposed() {
243 return viewer
.getControl().isDisposed();
247 public void setInput(Object input
) {
248 viewer
.setInput(input
);
252 public Object
getInput() {
253 return viewer
.getInput();
257 public void refresh() {
262 public void redraw() {
263 viewer
.getControl().redraw();
267 public void update() {
268 viewer
.getControl().update();
272 public void setAutoExpandLevel(int level
) {
273 viewer
.setAutoExpandLevel(level
);
277 public void performAlign(int offset
, int width
) {
278 viewer
.performAlign(offset
, width
);
282 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
283 return viewer
.getTimeViewAlignmentInfo();
287 public int getAvailableWidth(int requestedOffset
) {
288 return viewer
.getAvailableWidth(requestedOffset
);
292 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
293 private TimeGraphCombo combo
;
295 private TimeGraphComboWrapper(Composite parent
, int style
) {
296 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
300 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
301 combo
.setTimeGraphProvider(timeGraphProvider
);
305 public TimeGraphViewer
getTimeGraphViewer() {
306 return combo
.getTimeGraphViewer();
310 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
311 combo
.addSelectionListener(listener
);
315 public ISelectionProvider
getSelectionProvider() {
316 return combo
.getTreeViewer();
320 public void setFocus() {
325 public boolean isDisposed() {
326 return combo
.isDisposed();
330 public void setInput(Object input
) {
331 combo
.setInput(input
);
335 public Object
getInput() {
336 return combo
.getInput();
340 public void refresh() {
345 public void redraw() {
350 public void update() {
355 public void setAutoExpandLevel(int level
) {
356 combo
.setAutoExpandLevel(level
);
359 TimeGraphCombo
getTimeGraphCombo() {
363 TreeViewer
getTreeViewer() {
364 return combo
.getTreeViewer();
367 IAction
getShowFilterAction() {
368 return combo
.getShowFilterAction();
372 public void performAlign(int offset
, int width
) {
373 combo
.performAlign(offset
, width
);
377 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
378 return combo
.getTimeViewAlignmentInfo();
382 public int getAvailableWidth(int requestedOffset
) {
383 return combo
.getAvailableWidth(requestedOffset
);
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
392 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
395 public void addListener(ILabelProviderListener listener
) {
399 public void dispose() {
403 public boolean isLabelProperty(Object element
, String property
) {
408 public void removeListener(ILabelProviderListener listener
) {
412 public Image
getColumnImage(Object element
, int columnIndex
) {
417 public String
getColumnText(Object element
, int columnIndex
) {
418 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
419 if (columnIndex
== 0) {
420 return entry
.getName();
426 public Image
getImage(Object element
) {
431 public String
getText(Object element
) {
432 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
433 return entry
.getName();
438 private class BuildThread
extends Thread
{
439 private final @NonNull ITmfTrace fBuildTrace
;
440 private final @NonNull ITmfTrace fParentTrace
;
441 private final @NonNull IProgressMonitor fMonitor
;
443 public BuildThread(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
, final String name
) {
444 super(name
+ " build"); //$NON-NLS-1$
446 fParentTrace
= parentTrace
;
447 fMonitor
= new NullProgressMonitor();
452 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
453 synchronized (fBuildThreadMap
) {
454 fBuildThreadMap
.remove(fBuildTrace
);
458 public void cancel() {
459 fMonitor
.setCanceled(true);
463 private class ZoomThread
extends Thread
{
464 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
465 private final long fZoomStartTime
;
466 private final long fZoomEndTime
;
467 private final long fResolution
;
468 private final @NonNull IProgressMonitor fMonitor
;
470 public ZoomThread(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, String name
) {
471 super(name
+ " zoom"); //$NON-NLS-1$
472 fZoomEntryList
= entryList
;
473 fZoomStartTime
= startTime
;
474 fZoomEndTime
= endTime
;
475 fResolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
476 fMonitor
= new NullProgressMonitor();
481 for (TimeGraphEntry entry
: fZoomEntryList
) {
482 if (fMonitor
.isCanceled()) {
488 zoom(entry
, fMonitor
);
490 /* Refresh the arrows when zooming */
491 List
<ILinkEvent
> events
= getLinkList(fZoomStartTime
, fZoomEndTime
, fResolution
, fMonitor
);
492 if (events
!= null) {
493 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
498 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
499 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
500 entry
.setZoomedEventList(null);
502 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, fResolution
, monitor
);
503 if (zoomedEventList
!= null) {
504 entry
.setZoomedEventList(zoomedEventList
);
508 for (ITimeGraphEntry child
: entry
.getChildren()) {
509 if (fMonitor
.isCanceled()) {
512 if (child
instanceof TimeGraphEntry
) {
513 zoom((TimeGraphEntry
) child
, monitor
);
518 public void cancel() {
519 fMonitor
.setCanceled(true);
523 // ------------------------------------------------------------------------
525 // ------------------------------------------------------------------------
528 * Constructs a time graph view that contains either a time graph viewer or
529 * a time graph combo.
531 * By default, the view uses a time graph viewer. To use a time graph combo,
532 * the subclass constructor must call {@link #setTreeColumns(String[])} and
533 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
538 * The presentation provider
540 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
542 fPresentation
= pres
;
543 fDisplayWidth
= Display
.getDefault().getBounds().width
;
546 // ------------------------------------------------------------------------
547 // Getters and setters
548 // ------------------------------------------------------------------------
551 * Getter for the time graph combo
553 * @return The time graph combo, or null if combo is not used
555 protected TimeGraphCombo
getTimeGraphCombo() {
556 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
557 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
563 * Getter for the time graph viewer
565 * @return The time graph viewer
567 protected TimeGraphViewer
getTimeGraphViewer() {
568 return fTimeGraphWrapper
.getTimeGraphViewer();
572 * Getter for the presentation provider
574 * @return The time graph presentation provider
576 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
577 return fPresentation
;
581 * Sets the tree column labels.
582 * This should be called from the constructor.
585 * The array of tree column labels
587 protected void setTreeColumns(final String
[] columns
) {
592 * Sets the tree label provider.
593 * This should be called from the constructor.
596 * The tree label provider
598 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
599 fLabelProvider
= tlp
;
603 * Sets the time graph content provider. This should be called from the
607 * The time graph content provider
610 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
611 fTimeGraphContentProvider
= tgcp
;
615 * Sets the relative weight of each part of the time graph combo.
616 * This should be called from the constructor.
619 * The array (length 2) of relative weights of each part of the combo
621 protected void setWeight(final int[] weights
) {
626 * Sets the filter column labels.
627 * This should be called from the constructor.
629 * @param filterColumns
630 * The array of filter column labels
632 protected void setFilterColumns(final String
[] filterColumns
) {
633 fFilterColumns
= filterColumns
;
637 * Sets the filter label provider.
638 * This should be called from the constructor.
640 * @param labelProvider
641 * The filter label provider
643 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
644 fFilterLabelProvider
= labelProvider
;
648 * Gets the display width
650 * @return the display width
652 protected int getDisplayWidth() {
653 return fDisplayWidth
;
657 * Gets the comparator for the entries
659 * @return The entry comparator
661 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
662 return fEntryComparator
;
666 * Sets the comparator class for the entries
669 * A comparator object
671 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
672 fEntryComparator
= comparator
;
676 * Gets the trace displayed in the view
680 protected ITmfTrace
getTrace() {
685 * Gets the start time
687 * @return The start time
689 protected long getStartTime() {
694 * Sets the start time
699 protected void setStartTime(long time
) {
706 * @return The end time
708 protected long getEndTime() {
718 protected void setEndTime(long time
) {
723 * Sets the auto-expand level to be used for the input of the view. The
724 * value 0 means that there is no auto-expand; 1 means that top-level
725 * elements are expanded, but not their children; 2 means that top-level
726 * elements are expanded, and their children, but not grand-children; and so
729 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
733 * non-negative level, or <code>ALL_LEVELS</code> to expand all
736 protected void setAutoExpandLevel(int level
) {
737 fAutoExpandLevel
= level
;
738 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
739 if (tgWrapper
!= null) {
740 tgWrapper
.setAutoExpandLevel(level
);
745 * Gets the entry list for a trace
750 * @return the entry list map
752 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
753 synchronized (fEntryListMap
) {
754 return fEntryListMap
.get(trace
);
759 * Adds a trace entry list to the entry list map
764 * the list of time graph entries
766 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
767 synchronized (fEntryListMap
) {
768 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
773 * Adds a list of entries to a trace's entry list
778 * the list of time graph entries to add
780 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
781 synchronized (fEntryListMap
) {
782 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
783 if (entryList
== null) {
784 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
786 entryList
.addAll(list
);
792 * Removes a list of entries from a trace's entry list
797 * the list of time graph entries to remove
799 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
800 synchronized (fEntryListMap
) {
801 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
802 if (entryList
!= null) {
803 entryList
.removeAll(list
);
809 * Text for the "next" button
811 * @return The "next" button text
813 protected String
getNextText() {
814 return Messages
.AbstractTimeGraphtView_NextText
;
818 * Tooltip for the "next" button
820 * @return Tooltip for the "next" button
822 protected String
getNextTooltip() {
823 return Messages
.AbstractTimeGraphView_NextTooltip
;
827 * Text for the "Previous" button
829 * @return The "Previous" button text
831 protected String
getPrevText() {
832 return Messages
.AbstractTimeGraphView_PreviousText
;
836 * Tooltip for the "previous" button
838 * @return Tooltip for the "previous" button
840 protected String
getPrevTooltip() {
841 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
844 // ------------------------------------------------------------------------
846 // ------------------------------------------------------------------------
849 public void createPartControl(Composite parent
) {
850 super.createPartControl(parent
);
851 if (fColumns
== null || fLabelProvider
== null) {
852 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
853 TimeGraphViewer viewer
= fTimeGraphWrapper
.getTimeGraphViewer();
854 viewer
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
856 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
857 fTimeGraphWrapper
= wrapper
;
858 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
859 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
860 combo
.setTreeLabelProvider(fLabelProvider
);
861 combo
.setTreeColumns(fColumns
);
862 combo
.setFilterContentProvider(fTimeGraphContentProvider
);
863 combo
.setFilterLabelProvider(fFilterLabelProvider
);
864 combo
.setFilterColumns(fFilterColumns
);
865 combo
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
868 fTimeGraphWrapper
.setTimeGraphProvider(fPresentation
);
869 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
871 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
873 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
874 final long startTime
= event
.getStartTime();
875 final long endTime
= event
.getEndTime();
876 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
877 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
878 startZoomThread(startTime
, endTime
);
882 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
884 public void timeSelected(TimeGraphTimeEvent event
) {
885 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
886 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
887 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
891 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
893 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
894 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
896 // View Action Handling
898 contributeToActionBars();
900 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
902 traceSelected(new TmfTraceSelectedSignal(this, trace
));
905 // make selection available to other views
906 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
910 public void setFocus() {
911 fTimeGraphWrapper
.setFocus();
914 // ------------------------------------------------------------------------
916 // ------------------------------------------------------------------------
919 * Handler for the trace opened signal.
922 * The incoming signal
925 public void traceOpened(TmfTraceOpenedSignal signal
) {
926 fTrace
= signal
.getTrace();
931 * Handler for the trace selected signal
934 * The incoming signal
937 public void traceSelected(final TmfTraceSelectedSignal signal
) {
938 if (signal
.getTrace() == fTrace
) {
941 fTrace
= signal
.getTrace();
947 * Trace is closed: clear the data structures and the view
950 * the signal received
953 public void traceClosed(final TmfTraceClosedSignal signal
) {
954 synchronized (fBuildThreadMap
) {
955 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
956 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
957 if (buildThread
!= null) {
958 buildThread
.cancel();
962 synchronized (fEntryListMap
) {
963 fEntryListMap
.remove(signal
.getTrace());
965 if (signal
.getTrace() == fTrace
) {
969 if (fZoomThread
!= null) {
970 fZoomThread
.cancel();
977 * Handler for the selection range signal.
980 * The signal that's received
984 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
985 if (signal
.getSource() == this || fTrace
== null) {
988 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
989 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
991 Display
.getDefault().asyncExec(new Runnable() {
994 if (fTimeGraphWrapper
.isDisposed()) {
997 if (beginTime
== endTime
) {
998 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1000 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
);
1002 startZoomThread(fTimeGraphWrapper
.getTimeGraphViewer().getTime0(), fTimeGraphWrapper
.getTimeGraphViewer().getTime1());
1004 synchingToTime(beginTime
);
1010 * Handler for the window range signal.
1013 * The signal that's received
1017 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1018 if (signal
.getSource() == this || fTrace
== null) {
1021 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1024 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1025 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1026 Display
.getDefault().asyncExec(new Runnable() {
1029 if (fTimeGraphWrapper
.isDisposed()) {
1032 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1033 startZoomThread(startTime
, endTime
);
1039 * @param signal the format of the timestamps was updated.
1042 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1043 fTimeGraphWrapper
.refresh();
1046 // ------------------------------------------------------------------------
1048 // ------------------------------------------------------------------------
1050 private void loadTrace() {
1051 synchronized (fEntryListMap
) {
1052 fEntryList
= fEntryListMap
.get(fTrace
);
1053 if (fEntryList
== null) {
1056 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1057 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1064 * Forces a rebuild of the entries list, even if entries already exist for this trace
1066 protected void rebuild() {
1067 setStartTime(Long
.MAX_VALUE
);
1068 setEndTime(Long
.MIN_VALUE
);
1070 ITmfTrace viewTrace
= fTrace
;
1071 if (viewTrace
== null) {
1074 synchronized (fBuildThreadMap
) {
1075 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1076 if (trace
== null) {
1079 BuildThread buildThread
= new BuildThread(trace
, viewTrace
, getName());
1080 fBuildThreadMap
.put(trace
, buildThread
);
1081 buildThread
.start();
1087 * Method called when synching to a given timestamp. Inheriting classes can
1088 * perform actions here to update the view at the given timestamp.
1091 * The currently selected time
1093 protected void synchingToTime(long time
) {
1098 * Return the list of traces whose data or analysis results will be used to
1099 * populate the view. By default, if the trace is an experiment, the traces
1100 * under it will be returned, otherwise, the trace itself is returned.
1102 * A build thread will be started for each trace returned by this method,
1103 * some of which may receive events in live streaming mode.
1106 * The trace associated with this view
1107 * @return List of traces with data to display
1109 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@NonNull ITmfTrace trace
) {
1110 return TmfTraceManager
.getTraceSet(trace
);
1114 * Build the entries list to show in this time graph
1116 * Called from the BuildThread
1119 * The trace being built
1120 * @param parentTrace
1121 * The parent of the trace set, or the trace itself
1123 * The progress monitor object
1125 protected abstract void buildEventList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1128 * Gets the list of event for an entry in a given timerange
1131 * The entry to get events for
1133 * Start of the time range
1135 * End of the time range
1139 * The progress monitor object
1140 * @return The list of events for the entry
1142 protected abstract @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1143 long startTime
, long endTime
, long resolution
,
1144 @NonNull IProgressMonitor monitor
);
1147 * Gets the list of links (displayed as arrows) for a trace in a given
1148 * timerange. Default implementation returns an empty list.
1151 * Start of the time range
1153 * End of the time range
1157 * The progress monitor object
1158 * @return The list of link events
1160 protected @Nullable List
<ILinkEvent
> getLinkList(long startTime
, long endTime
,
1161 long resolution
, @NonNull IProgressMonitor monitor
) {
1162 return new ArrayList
<>();
1167 * Refresh the display
1169 protected void refresh() {
1170 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1173 if (fTimeGraphWrapper
.isDisposed()) {
1176 boolean hasEntries
= false;
1177 synchronized (fEntryListMap
) {
1178 fEntryList
= fEntryListMap
.get(fTrace
);
1179 if (fEntryList
== null) {
1180 fEntryList
= new CopyOnWriteArrayList
<>();
1181 } else if (fEntryComparator
!= null) {
1182 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1183 Collections
.sort(list
, fEntryComparator
);
1185 fEntryList
.addAll(list
);
1187 hasEntries
= fEntryList
.size() != 0;
1189 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1190 fTimeGraphWrapper
.setInput(fEntryList
);
1192 fTimeGraphWrapper
.refresh();
1194 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(fStartTime
, fEndTime
);
1196 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1197 long selectionBeginTime
= fTrace
== null ?
0 : ctx
.getSelectionRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1198 long selectionEndTime
= fTrace
== null ?
0 : ctx
.getSelectionRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1199 long startTime
= fTrace
== null ?
0 : ctx
.getWindowRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1200 long endTime
= fTrace
== null ?
0 : ctx
.getWindowRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1201 startTime
= Math
.max(startTime
, fStartTime
);
1202 endTime
= Math
.min(endTime
, fEndTime
);
1203 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
);
1204 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1206 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1207 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1215 startZoomThread(startTime
, endTime
);
1223 protected void redraw() {
1224 synchronized (fSyncObj
) {
1225 if (fRedrawState
== State
.IDLE
) {
1226 fRedrawState
= State
.BUSY
;
1228 fRedrawState
= State
.PENDING
;
1232 Display
.getDefault().asyncExec(new Runnable() {
1235 if (fTimeGraphWrapper
.isDisposed()) {
1238 fTimeGraphWrapper
.redraw();
1239 fTimeGraphWrapper
.update();
1240 synchronized (fSyncObj
) {
1241 if (fRedrawState
== State
.PENDING
) {
1242 fRedrawState
= State
.IDLE
;
1245 fRedrawState
= State
.IDLE
;
1252 private void startZoomThread(long startTime
, long endTime
) {
1253 if (fZoomThread
!= null) {
1254 fZoomThread
.cancel();
1256 final List
<TimeGraphEntry
> entryList
= fEntryList
;
1257 if (entryList
== null) {
1260 fZoomThread
= new ZoomThread(entryList
, startTime
, endTime
, getName());
1261 fZoomThread
.start();
1264 private void makeActions() {
1265 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1266 fPreviousResourceAction
.setText(getPrevText());
1267 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1268 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1269 fNextResourceAction
.setText(getNextText());
1270 fNextResourceAction
.setToolTipText(getNextTooltip());
1273 private void contributeToActionBars() {
1274 IActionBars bars
= getViewSite().getActionBars();
1275 fillLocalToolBar(bars
.getToolBarManager());
1279 * Add actions to local tool bar manager
1281 * @param manager the tool bar manager
1283 protected void fillLocalToolBar(IToolBarManager manager
) {
1284 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
1285 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1286 manager
.add(((TimeGraphComboWrapper
) fTimeGraphWrapper
).getShowFilterAction());
1289 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1290 manager
.add(new Separator());
1291 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1292 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1293 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1294 manager
.add(fPreviousResourceAction
);
1295 manager
.add(fNextResourceAction
);
1296 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1297 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1298 manager
.add(new Separator());
1305 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
1306 if (fTimeGraphWrapper
== null) {
1309 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
1316 public int getAvailableWidth(int requestedOffset
) {
1317 if (fTimeGraphWrapper
== null) {
1320 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
1327 public void performAlign(int offset
, int width
) {
1328 if (fTimeGraphWrapper
!= null) {
1329 fTimeGraphWrapper
.performAlign(offset
, width
);