1 /*******************************************************************************
2 * Copyright (c) 2012, 2016 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
.Collections
;
23 import java
.util
.Comparator
;
24 import java
.util
.HashMap
;
25 import java
.util
.LinkedHashSet
;
26 import java
.util
.List
;
29 import java
.util
.concurrent
.CopyOnWriteArrayList
;
30 import java
.util
.concurrent
.atomic
.AtomicInteger
;
31 import java
.util
.logging
.Logger
;
32 import java
.util
.regex
.Matcher
;
33 import java
.util
.regex
.Pattern
;
35 import org
.eclipse
.core
.resources
.IFile
;
36 import org
.eclipse
.core
.resources
.IMarker
;
37 import org
.eclipse
.core
.resources
.IMarkerDelta
;
38 import org
.eclipse
.core
.resources
.IResource
;
39 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
40 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
41 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
42 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
43 import org
.eclipse
.core
.runtime
.CoreException
;
44 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
45 import org
.eclipse
.core
.runtime
.IStatus
;
46 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
47 import org
.eclipse
.core
.runtime
.Status
;
48 import org
.eclipse
.core
.runtime
.jobs
.Job
;
49 import org
.eclipse
.jdt
.annotation
.NonNull
;
50 import org
.eclipse
.jdt
.annotation
.Nullable
;
51 import org
.eclipse
.jface
.action
.Action
;
52 import org
.eclipse
.jface
.action
.GroupMarker
;
53 import org
.eclipse
.jface
.action
.IAction
;
54 import org
.eclipse
.jface
.action
.IMenuListener
;
55 import org
.eclipse
.jface
.action
.IMenuManager
;
56 import org
.eclipse
.jface
.action
.IStatusLineManager
;
57 import org
.eclipse
.jface
.action
.IToolBarManager
;
58 import org
.eclipse
.jface
.action
.MenuManager
;
59 import org
.eclipse
.jface
.action
.Separator
;
60 import org
.eclipse
.jface
.commands
.ActionHandler
;
61 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
62 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
63 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
64 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
65 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
66 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
67 import org
.eclipse
.jface
.viewers
.TreeSelection
;
68 import org
.eclipse
.jface
.viewers
.TreeViewer
;
69 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
70 import org
.eclipse
.osgi
.util
.NLS
;
71 import org
.eclipse
.swt
.SWT
;
72 import org
.eclipse
.swt
.events
.MenuDetectEvent
;
73 import org
.eclipse
.swt
.events
.MenuDetectListener
;
74 import org
.eclipse
.swt
.events
.SelectionAdapter
;
75 import org
.eclipse
.swt
.events
.SelectionEvent
;
76 import org
.eclipse
.swt
.graphics
.Image
;
77 import org
.eclipse
.swt
.graphics
.Point
;
78 import org
.eclipse
.swt
.graphics
.RGBA
;
79 import org
.eclipse
.swt
.widgets
.Composite
;
80 import org
.eclipse
.swt
.widgets
.Display
;
81 import org
.eclipse
.swt
.widgets
.Menu
;
82 import org
.eclipse
.swt
.widgets
.Shell
;
83 import org
.eclipse
.swt
.widgets
.Tree
;
84 import org
.eclipse
.swt
.widgets
.TreeColumn
;
85 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
86 import org
.eclipse
.tracecompass
.common
.core
.log
.TraceCompassLog
;
87 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
88 import org
.eclipse
.tracecompass
.tmf
.core
.resources
.ITmfMarker
;
89 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfMarkerEventSourceUpdatedSignal
;
90 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
91 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
92 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
93 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
94 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
95 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
96 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
97 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
98 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
99 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
100 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
101 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceAdapterManager
;
102 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
103 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
104 import org
.eclipse
.tracecompass
.tmf
.ui
.TmfUiRefreshHandler
;
105 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
106 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
107 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
108 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphBookmarkListener
;
109 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
110 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
111 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
112 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
113 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
114 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphBookmarkEvent
;
115 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
116 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
117 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
118 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
119 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
120 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
121 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
122 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
123 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEventSource
;
124 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
125 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
126 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.MarkerEvent
;
127 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
128 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
129 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
130 import org
.eclipse
.ui
.IActionBars
;
131 import org
.eclipse
.ui
.IPartListener
;
132 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
133 import org
.eclipse
.ui
.IWorkbenchPart
;
134 import org
.eclipse
.ui
.PlatformUI
;
135 import org
.eclipse
.ui
.actions
.ActionFactory
;
136 import org
.eclipse
.ui
.handlers
.IHandlerActivation
;
137 import org
.eclipse
.ui
.handlers
.IHandlerService
;
140 * An abstract view all time graph views can inherit
142 * This view contains either a time graph viewer, or a time graph combo which is
143 * divided between a tree viewer on the left and a time graph viewer on the right.
145 public abstract class AbstractTimeGraphView
extends TmfView
implements ITmfTimeAligned
, IResourceChangeListener
{
147 /** Constant indicating that all levels of the time graph should be expanded */
148 protected static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
150 private static final Pattern RGBA_PATTERN
= Pattern
.compile("RGBA \\{(\\d+), (\\d+), (\\d+), (\\d+)\\}"); //$NON-NLS-1$
152 private static final Logger LOGGER
= TraceCompassLog
.getLogger(AbstractTimeGraphView
.class);
153 private static final String LOG_STRING_WITH_PARAM
= "[TimeGraphView:%s] viewId=%s, %s"; //$NON-NLS-1$
154 private static final String LOG_STRING
= "[TimeGraphView:%s] viewId=%s"; //$NON-NLS-1$
163 // ------------------------------------------------------------------------
165 // ------------------------------------------------------------------------
167 /** The timegraph wrapper */
168 private ITimeGraphWrapper fTimeGraphWrapper
;
170 private AtomicInteger fDirty
= new AtomicInteger();
172 private final Object fZoomThreadResultLock
= new Object();
174 /** The selected trace */
175 private ITmfTrace fTrace
;
177 /** The selected trace editor file*/
178 private IFile fEditorFile
;
180 /** The timegraph entry list */
181 private List
<TimeGraphEntry
> fEntryList
;
183 /** The trace to entry list hash map */
184 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
186 /** The trace to filters hash map */
187 private final Map
<ITmfTrace
, @NonNull ViewerFilter
[]> fFiltersMap
= new HashMap
<>();
189 /** The trace to view context hash map */
190 private final Map
<ITmfTrace
, ViewContext
> fViewContext
= new HashMap
<>();
192 /** The trace to marker event sources hash map */
193 private final Map
<ITmfTrace
, List
<IMarkerEventSource
>> fMarkerEventSourcesMap
= new HashMap
<>();
195 /** The trace to build thread hash map */
196 private final Map
<ITmfTrace
, Job
> fBuildJobMap
= new HashMap
<>();
198 /** The start time */
199 private long fStartTime
= SWT
.DEFAULT
;
202 private long fEndTime
= SWT
.DEFAULT
;
204 /** The display width */
205 private final int fDisplayWidth
;
207 /** The zoom thread */
208 private ZoomThread fZoomThread
;
210 /** The next resource action */
211 private Action fNextResourceAction
;
213 /** The previous resource action */
214 private Action fPreviousResourceAction
;
216 /** A comparator class */
217 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
219 /** The redraw state used to prevent unnecessary queuing of display runnables */
220 private State fRedrawState
= State
.IDLE
;
222 /** The redraw synchronization object */
223 private final Object fSyncObj
= new Object();
225 /** The presentation provider for this view */
226 private final TimeGraphPresentationProvider fPresentation
;
228 /** The tree column label array, or null if combo is not used */
229 private String
[] fColumns
;
231 private Comparator
<ITimeGraphEntry
>[] fColumnComparators
;
233 /** The tree label provider, or null if combo is not used */
234 private TreeLabelProvider fLabelProvider
= null;
236 /** The time graph content provider */
237 private @NonNull ITimeGraphContentProvider fTimeGraphContentProvider
= new TimeGraphContentProvider();
239 /** The relative weight of the sash, ignored if combo is not used */
240 private int[] fWeight
= { 1, 3 };
242 /** The filter column label array, or null if filter is not used */
243 private String
[] fFilterColumns
;
245 /** The pack done flag */
246 private boolean fPackDone
= false;
248 /** The filter content provider, or null if filter is not used */
249 private ITreeContentProvider fFilterContentProvider
;
251 /** The filter label provider, or null if filter is not used */
252 private TreeLabelProvider fFilterLabelProvider
;
254 private int fAutoExpandLevel
= ALL_LEVELS
;
256 /** The default column index for sorting */
257 private int fInitialSortColumn
= 0;
259 /** The default column index for sorting */
260 private int fCurrentSortColumn
= 0;
262 /** The current sort direction */
263 private int fSortDirection
= SWT
.DOWN
;
265 /** Flag to indicate to reveal selection */
266 private volatile boolean fIsRevealSelection
= false;
269 * Menu Manager for context-sensitive menu for time graph entries.
270 * This will be used on the tree viewer in case of the time graph combo
271 * or the on the namespace in case of a single time graph viewer.
273 private final @NonNull MenuManager fEntryMenuManager
= new MenuManager();
275 /** Time Graph View part listener */
276 private TimeGraphPartListener fPartListener
;
278 /** Action for the find command. There is only one for all Time Graph views */
279 private static final ShowFindDialogAction FIND_ACTION
= new ShowFindDialogAction();
281 /** The find action handler */
282 private ActionHandler fFindActionHandler
;
284 /** The find handler activation */
285 private IHandlerActivation fFindHandlerActivation
;
287 /** The find target to use */
288 private final FindTarget fFindTarget
;
290 // ------------------------------------------------------------------------
292 // ------------------------------------------------------------------------
294 private interface ITimeGraphWrapper
{
296 void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
);
298 void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
);
300 TimeGraphViewer
getTimeGraphViewer();
302 void addSelectionListener(ITimeGraphSelectionListener listener
);
304 ISelectionProvider
getSelectionProvider();
308 boolean isDisposed();
312 void setInput(Object input
);
316 void setFilters(@NonNull ViewerFilter
[] filters
);
318 @NonNull ViewerFilter
[] getFilters();
324 void setAutoExpandLevel(int level
);
326 boolean getExpandedState(ITimeGraphEntry entry
);
328 void setExpandedState(ITimeGraphEntry entry
, boolean expanded
);
330 void setFilterColumns(String
[] columnNames
);
332 void setFilterContentProvider(ITreeContentProvider contentProvider
);
334 void setFilterLabelProvider(ITableLabelProvider labelProvider
);
336 IAction
getShowFilterDialogAction();
338 void performAlign(int offset
, int width
);
340 TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo();
342 int getAvailableWidth(int requestedOffset
);
344 ITimeGraphEntry
getSelection();
346 void setSelection(ITimeGraphEntry selection
);
348 void selectAndReveal(@NonNull ITimeGraphEntry selection
);
352 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
353 private TimeGraphViewer viewer
;
355 private TimeGraphViewerWrapper(Composite parent
, int style
) {
356 viewer
= new TimeGraphViewer(parent
, style
);
360 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
361 viewer
.setTimeGraphContentProvider(timeGraphContentProvider
);
365 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
366 viewer
.setTimeGraphProvider(timeGraphPresentationProvider
);
370 public TimeGraphViewer
getTimeGraphViewer() {
375 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
376 viewer
.addSelectionListener(listener
);
380 public ISelectionProvider
getSelectionProvider() {
381 return viewer
.getSelectionProvider();
385 public void setFocus() {
390 public boolean isDisposed() {
391 return viewer
.getControl().isDisposed();
395 public void setInput(Object input
) {
396 viewer
.setInput(input
);
400 public Object
getInput() {
401 return viewer
.getInput();
405 public void setFilterColumns(String
[] columnNames
) {
406 viewer
.setFilterColumns(columnNames
);
410 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
411 viewer
.setFilterContentProvider(contentProvider
);
415 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
416 viewer
.setFilterLabelProvider(labelProvider
);
420 public void setFilters(@NonNull ViewerFilter
[] filters
) {
421 viewer
.setFilters(filters
);
425 public @NonNull ViewerFilter
[] getFilters() {
426 return viewer
.getFilters();
430 public IAction
getShowFilterDialogAction() {
431 return viewer
.getShowFilterDialogAction();
435 public void refresh() {
440 public void redraw() {
441 viewer
.getControl().redraw();
445 public void update() {
446 viewer
.getControl().update();
450 public void setAutoExpandLevel(int level
) {
451 viewer
.setAutoExpandLevel(level
);
455 public boolean getExpandedState(ITimeGraphEntry entry
) {
456 return viewer
.getExpandedState(entry
);
460 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
461 viewer
.setExpandedState(entry
, expanded
);
465 public void performAlign(int offset
, int width
) {
466 viewer
.performAlign(offset
, width
);
470 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
471 return viewer
.getTimeViewAlignmentInfo();
475 public int getAvailableWidth(int requestedOffset
) {
476 return viewer
.getAvailableWidth(requestedOffset
);
480 public ITimeGraphEntry
getSelection() {
481 return viewer
.getSelection();
485 public void setSelection(ITimeGraphEntry selection
) {
486 viewer
.setSelection(selection
);
490 public void selectAndReveal(@NonNull ITimeGraphEntry selection
) {
491 viewer
.selectAndReveal(selection
);
495 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
496 private TimeGraphCombo combo
;
498 private TimeGraphComboWrapper(Composite parent
, int style
) {
499 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
503 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider
) {
504 combo
.setTimeGraphContentProvider(timeGraphContentProvider
);
508 public void setTimeGraphPresentationProvider(TimeGraphPresentationProvider timeGraphPresentationProvider
) {
509 combo
.setTimeGraphProvider(timeGraphPresentationProvider
);
513 public TimeGraphViewer
getTimeGraphViewer() {
514 return combo
.getTimeGraphViewer();
518 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
519 combo
.addSelectionListener(listener
);
523 public ISelectionProvider
getSelectionProvider() {
524 return combo
.getTreeViewer();
528 public void setFocus() {
533 public boolean isDisposed() {
534 return combo
.isDisposed();
538 public void setInput(Object input
) {
539 combo
.setInput(input
);
543 public Object
getInput() {
544 return combo
.getInput();
548 public void setFilterColumns(String
[] columnNames
) {
549 combo
.setFilterColumns(columnNames
);
553 public void setFilterContentProvider(ITreeContentProvider contentProvider
) {
554 combo
.setFilterContentProvider(contentProvider
);
558 public void setFilterLabelProvider(ITableLabelProvider labelProvider
) {
559 combo
.setFilterLabelProvider(labelProvider
);
563 public void setFilters(@NonNull ViewerFilter
[] filters
) {
564 combo
.setFilters(filters
);
568 public @NonNull ViewerFilter
[] getFilters() {
569 return combo
.getFilters();
573 public IAction
getShowFilterDialogAction() {
574 return combo
.getShowFilterDialogAction();
578 public void refresh() {
583 public void redraw() {
588 public void update() {
593 public void setAutoExpandLevel(int level
) {
594 combo
.setAutoExpandLevel(level
);
598 public boolean getExpandedState(ITimeGraphEntry entry
) {
599 return combo
.getExpandedState(entry
);
603 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
604 combo
.setExpandedState(entry
, expanded
);
607 TimeGraphCombo
getTimeGraphCombo() {
611 TreeViewer
getTreeViewer() {
612 return combo
.getTreeViewer();
616 public void performAlign(int offset
, int width
) {
617 combo
.performAlign(offset
, width
);
621 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
622 return combo
.getTimeViewAlignmentInfo();
626 public int getAvailableWidth(int requestedOffset
) {
627 return combo
.getAvailableWidth(requestedOffset
);
631 public ITimeGraphEntry
getSelection() {
632 return combo
.getTimeGraphViewer().getSelection();
636 public void setSelection(ITimeGraphEntry selection
) {
637 combo
.setSelection(selection
);
641 public void selectAndReveal(@NonNull ITimeGraphEntry selection
) {
642 combo
.selectAndReveal(selection
);
647 * Base class to provide the labels for the tree viewer. Views extending
648 * this class typically need to override the getColumnText method if they
649 * have more than one column to display
651 protected static class TreeLabelProvider
implements ITableLabelProvider
, ILabelProvider
{
654 public void addListener(ILabelProviderListener listener
) {
658 public void dispose() {
662 public boolean isLabelProperty(Object element
, String property
) {
667 public void removeListener(ILabelProviderListener listener
) {
671 public Image
getColumnImage(Object element
, int columnIndex
) {
676 public String
getColumnText(Object element
, int columnIndex
) {
677 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
678 if (columnIndex
== 0) {
679 return entry
.getName();
685 public Image
getImage(Object element
) {
690 public String
getText(Object element
) {
691 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
692 return entry
.getName();
697 // TODO: This can implement ICoreRunnable once support for Eclipse 4.5. is not necessary anymore.
698 private class BuildRunnable
{
699 private final @NonNull ITmfTrace fBuildTrace
;
700 private final @NonNull ITmfTrace fParentTrace
;
702 public BuildRunnable(final @NonNull ITmfTrace trace
, final @NonNull ITmfTrace parentTrace
) {
704 fParentTrace
= parentTrace
;
707 public void run(IProgressMonitor monitor
) {
708 LOGGER
.info(() -> getLogMessage("BuildThreadStart", "trace=" + fBuildTrace
.getName())); //$NON-NLS-1$ //$NON-NLS-2$
710 buildEntryList(fBuildTrace
, fParentTrace
, NonNullUtils
.checkNotNull(monitor
));
711 synchronized (fBuildJobMap
) {
712 fBuildJobMap
.remove(fBuildTrace
);
715 LOGGER
.info(() -> getLogMessage("BuildThreadEnd", null)); //$NON-NLS-1$
723 protected abstract class ZoomThread
extends Thread
{
724 private final long fZoomStartTime
;
725 private final long fZoomEndTime
;
726 private final long fResolution
;
727 private final @NonNull IProgressMonitor fMonitor
;
739 public ZoomThread(long startTime
, long endTime
, long resolution
) {
740 super(AbstractTimeGraphView
.this.getName() + " zoom"); //$NON-NLS-1$
741 fZoomStartTime
= startTime
;
742 fZoomEndTime
= endTime
;
743 fResolution
= resolution
;
744 fMonitor
= new NullProgressMonitor();
748 * @return the zoom start time
750 public long getZoomStartTime() {
751 return fZoomStartTime
;
755 * @return the zoom end time
757 public long getZoomEndTime() {
762 * @return the resolution
764 public long getResolution() {
769 * @return the monitor
771 public @NonNull IProgressMonitor
getMonitor() {
776 * Cancel the zoom thread
778 public void cancel() {
779 fMonitor
.setCanceled(true);
783 public final void run() {
784 LOGGER
.info(() -> getLogMessage("ZoomThreadStart", "start=" + fZoomStartTime
+ ", end=" + fZoomEndTime
)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
787 fDirty
.decrementAndGet();
789 LOGGER
.info(() -> getLogMessage("ZoomThreadEnd", null)); //$NON-NLS-1$
793 * Applies the results of the ZoomThread calculations.
795 * Note: This method makes sure that only the results of the last
796 * created ZoomThread are applied.
799 * the code to run in order to apply the results
802 protected void applyResults(Runnable runnable
) {
803 synchronized (fZoomThreadResultLock
) {
804 if (this == fZoomThread
) {
811 * Run the zoom operation.
814 public abstract void doRun();
817 private class ZoomThreadByEntry
extends ZoomThread
{
818 private final @NonNull List
<TimeGraphEntry
> fZoomEntryList
;
820 public ZoomThreadByEntry(@NonNull List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, long resolution
) {
821 super(startTime
, endTime
, resolution
);
822 fZoomEntryList
= entryList
;
826 public void doRun() {
827 LOGGER
.config(() -> getLogMessage("ZoomThreadGettingStates", null)); //$NON-NLS-1$
829 for (TimeGraphEntry entry
: fZoomEntryList
) {
830 if (getMonitor().isCanceled()) {
831 LOGGER
.info(() -> getLogMessage("ZoomThreadCanceled", null)); //$NON-NLS-1$
837 zoom(entry
, getMonitor());
839 /* Refresh the arrows when zooming */
840 LOGGER
.config(() -> getLogMessage("ZoomThreadGettingLinks", null)); //$NON-NLS-1$
841 List
<ILinkEvent
> events
= getLinkList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor());
843 /* Refresh the view-specific markers when zooming */
844 LOGGER
.config(() -> getLogMessage("ZoomThreadGettingMarkers", null)); //$NON-NLS-1$
845 List
<IMarkerEvent
> markers
= new ArrayList
<>(getViewMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
846 /* Refresh the trace-specific markers when zooming */
847 markers
.addAll(getTraceMarkerList(getZoomStartTime(), getZoomEndTime(), getResolution(), getMonitor()));
849 if (events
!= null) {
850 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
852 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
853 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(markers
);
858 private void zoom(@NonNull TimeGraphEntry entry
, @NonNull IProgressMonitor monitor
) {
859 if (getZoomStartTime() <= fStartTime
&& getZoomEndTime() >= fEndTime
) {
861 entry
.setZoomedEventList(null);
864 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, getZoomStartTime(), getZoomEndTime(), getResolution(), monitor
);
865 if (zoomedEventList
!= null) {
867 entry
.setZoomedEventList(zoomedEventList
);
872 for (TimeGraphEntry child
: entry
.getChildren()) {
873 if (monitor
.isCanceled()) {
876 zoom(child
, monitor
);
882 // ------------------------------------------------------------------------
884 // ------------------------------------------------------------------------
887 * Constructs a time graph view that contains either a time graph viewer or
888 * a time graph combo.
890 * By default, the view uses a time graph viewer. To use a time graph combo,
891 * the subclass constructor must call {@link #setTreeColumns(String[])} and
892 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
897 * The presentation provider
899 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
901 fPresentation
= pres
;
902 fDisplayWidth
= Display
.getDefault().getBounds().width
;
903 fFindTarget
= new FindTarget();
906 // ------------------------------------------------------------------------
907 // Getters and setters
908 // ------------------------------------------------------------------------
911 * Getter for the time graph combo
913 * @return The time graph combo, or null if combo is not used
915 protected TimeGraphCombo
getTimeGraphCombo() {
916 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
917 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
923 * Getter for the time graph viewer
925 * @return The time graph viewer
927 protected TimeGraphViewer
getTimeGraphViewer() {
928 return fTimeGraphWrapper
.getTimeGraphViewer();
932 * Getter for the presentation provider
934 * @return The time graph presentation provider
936 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
937 return fPresentation
;
941 * Sets the tree column labels.
943 * This should be called from the constructor.
946 * The array of tree column labels
948 protected void setTreeColumns(final String
[] columns
) {
949 setTreeColumns(columns
, null, 0);
953 * Sets the tree column labels.
955 * This should be called from the constructor.
958 * The array of tree column labels
960 * An array of column comparators for sorting of columns when
961 * clicking on column header
962 * @param initialSortColumn
963 * Index of column to sort initially
966 protected void setTreeColumns(final String
[] columns
, final Comparator
<ITimeGraphEntry
>[] comparators
, int initialSortColumn
) {
967 checkPartNotCreated();
969 fColumnComparators
= comparators
;
970 fInitialSortColumn
= initialSortColumn
;
974 * Sets the tree label provider.
976 * This should be called from the constructor.
979 * The tree label provider
981 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
982 checkPartNotCreated();
983 fLabelProvider
= tlp
;
987 * Sets the time graph content provider.
989 * This should be called from the constructor.
992 * The time graph content provider
995 protected void setTimeGraphContentProvider(final @NonNull ITimeGraphContentProvider tgcp
) {
996 checkPartNotCreated();
997 fTimeGraphContentProvider
= tgcp
;
1001 * Sets the relative weight of each part of the time graph combo.
1003 * This should be called from the constructor.
1006 * The array (length 2) of relative weights of each part of the combo
1008 protected void setWeight(final int[] weights
) {
1009 checkPartNotCreated();
1014 * Sets the filter column labels.
1016 * This should be called from the constructor.
1018 * @param filterColumns
1019 * The array of filter column labels
1021 protected void setFilterColumns(final String
[] filterColumns
) {
1022 checkPartNotCreated();
1023 fFilterColumns
= filterColumns
;
1027 * Sets the filter content provider.
1029 * This should be called from the constructor.
1031 * @param contentProvider
1032 * The filter content provider
1035 protected void setFilterContentProvider(final ITreeContentProvider contentProvider
) {
1036 checkPartNotCreated();
1037 fFilterContentProvider
= contentProvider
;
1041 * Sets the filter label provider.
1043 * This should be called from the constructor.
1045 * @param labelProvider
1046 * The filter label provider
1048 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
1049 checkPartNotCreated();
1050 fFilterLabelProvider
= labelProvider
;
1053 private void checkPartNotCreated() {
1054 if (getParentComposite() != null) {
1055 throw new IllegalStateException("This method must be called before createPartControl."); //$NON-NLS-1$
1060 * Gets the display width
1062 * @return the display width
1064 protected int getDisplayWidth() {
1065 return fDisplayWidth
;
1069 * Gets the comparator for the entries
1071 * @return The entry comparator
1073 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
1074 return fEntryComparator
;
1078 * Sets the comparator class for the entries.
1080 * This comparator will apply recursively to entries that implement
1081 * {@link TimeGraphEntry#sortChildren(Comparator)}.
1084 * A comparator object
1086 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
1087 fEntryComparator
= comparator
;
1091 * Gets the trace displayed in the view
1095 protected ITmfTrace
getTrace() {
1100 * Gets the start time
1102 * @return The start time
1104 protected long getStartTime() {
1109 * Sets the start time
1114 protected void setStartTime(long time
) {
1121 * @return The end time
1123 protected long getEndTime() {
1133 protected void setEndTime(long time
) {
1138 * Sets the auto-expand level to be used for the input of the view. The
1139 * value 0 means that there is no auto-expand; 1 means that top-level
1140 * elements are expanded, but not their children; 2 means that top-level
1141 * elements are expanded, and their children, but not grand-children; and so
1144 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1148 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1149 * levels of the tree
1151 protected void setAutoExpandLevel(int level
) {
1152 fAutoExpandLevel
= level
;
1153 ITimeGraphWrapper tgWrapper
= fTimeGraphWrapper
;
1154 if (tgWrapper
!= null) {
1155 tgWrapper
.setAutoExpandLevel(level
);
1160 * Gets the entry list for a trace
1165 * @return the entry list map
1167 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
1168 synchronized (fEntryListMap
) {
1169 return fEntryListMap
.get(trace
);
1174 * Adds a trace entry list to the entry list map
1179 * the list of time graph entries
1181 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1182 synchronized (fEntryListMap
) {
1183 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1188 * Adds a list of entries to a trace's entry list
1193 * the list of time graph entries to add
1195 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1196 synchronized (fEntryListMap
) {
1197 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1198 if (entryList
== null) {
1199 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
1201 entryList
.addAll(list
);
1207 * Removes a list of entries from a trace's entry list
1212 * the list of time graph entries to remove
1214 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
1215 synchronized (fEntryListMap
) {
1216 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
1217 if (entryList
!= null) {
1218 entryList
.removeAll(list
);
1224 * Text for the "next" button
1226 * @return The "next" button text
1228 protected String
getNextText() {
1229 return Messages
.AbstractTimeGraphtView_NextText
;
1233 * Tooltip for the "next" button
1235 * @return Tooltip for the "next" button
1237 protected String
getNextTooltip() {
1238 return Messages
.AbstractTimeGraphView_NextTooltip
;
1242 * Text for the "Previous" button
1244 * @return The "Previous" button text
1246 protected String
getPrevText() {
1247 return Messages
.AbstractTimeGraphView_PreviousText
;
1251 * Tooltip for the "previous" button
1253 * @return Tooltip for the "previous" button
1255 protected String
getPrevTooltip() {
1256 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
1260 FindTarget
getFindTarget() {
1265 * Formats a log message for this class
1268 * The event to log, that will be appended to the class name to
1269 * make the full event name
1271 * The string of extra parameters to add to the log message, in
1272 * the format name=value[, name=value]*, or <code>null</code> for
1274 * @return The complete log message for this class
1276 private String
getLogMessage(String event
, @Nullable String parameters
) {
1277 if (parameters
== null) {
1278 return String
.format(LOG_STRING
, event
, getViewId());
1280 return String
.format(LOG_STRING_WITH_PARAM
, event
, getViewId(), parameters
);
1283 // ------------------------------------------------------------------------
1285 // ------------------------------------------------------------------------
1288 public void createPartControl(Composite parent
) {
1289 super.createPartControl(parent
);
1290 if (fColumns
== null || fLabelProvider
== null) {
1291 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
1293 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
1294 fTimeGraphWrapper
= wrapper
;
1295 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
1296 combo
.setTreeContentProvider(fTimeGraphContentProvider
);
1297 combo
.setTreeLabelProvider(fLabelProvider
);
1298 combo
.setTreeColumns(fColumns
);
1299 if (fColumnComparators
!= null) {
1300 createColumnSelectionListener(combo
.getTreeViewer());
1302 // Add double click listener to tree viewer
1303 createDoubleClickListener(combo
.getTreeViewer());
1305 fTimeGraphWrapper
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
1306 fTimeGraphWrapper
.setFilterContentProvider(fFilterContentProvider
!= null ? fFilterContentProvider
: fTimeGraphContentProvider
);
1307 fTimeGraphWrapper
.setFilterLabelProvider(fFilterLabelProvider
);
1308 fTimeGraphWrapper
.setFilterColumns(fFilterColumns
);
1310 fTimeGraphWrapper
.setTimeGraphPresentationProvider(fPresentation
);
1311 fTimeGraphWrapper
.setAutoExpandLevel(fAutoExpandLevel
);
1313 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
1315 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
1316 final long startTime
= event
.getStartTime();
1317 final long endTime
= event
.getEndTime();
1318 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.fromNanos(startTime
), TmfTimestamp
.fromNanos(endTime
));
1319 broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView
.this, range
));
1320 startZoomThread(startTime
, endTime
);
1324 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
1326 public void timeSelected(TimeGraphTimeEvent event
) {
1327 ITmfTimestamp startTime
= TmfTimestamp
.fromNanos(event
.getBeginTime());
1328 ITmfTimestamp endTime
= TmfTimestamp
.fromNanos(event
.getEndTime());
1329 broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
1333 fTimeGraphWrapper
.getTimeGraphViewer().addBookmarkListener(new ITimeGraphBookmarkListener() {
1335 public void bookmarkAdded(final TimeGraphBookmarkEvent event
) {
1337 ResourcesPlugin
.getWorkspace().run(new IWorkspaceRunnable() {
1339 public void run(IProgressMonitor monitor
) throws CoreException
{
1340 IMarkerEvent bookmark
= event
.getBookmark();
1341 IMarker marker
= fEditorFile
.createMarker(IMarker
.BOOKMARK
);
1342 marker
.setAttribute(IMarker
.MESSAGE
, bookmark
.getLabel());
1343 marker
.setAttribute(ITmfMarker
.MARKER_TIME
, Long
.toString(bookmark
.getTime()));
1344 if (bookmark
.getDuration() > 0) {
1345 marker
.setAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(bookmark
.getDuration()));
1346 marker
.setAttribute(IMarker
.LOCATION
,
1347 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTimeRange
,
1348 TmfTimestamp
.fromNanos(bookmark
.getTime()),
1349 TmfTimestamp
.fromNanos(bookmark
.getTime() + bookmark
.getDuration())));
1351 marker
.setAttribute(IMarker
.LOCATION
,
1352 NLS
.bind(org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
.TmfMarker_LocationTime
,
1353 TmfTimestamp
.fromNanos(bookmark
.getTime())));
1355 marker
.setAttribute(ITmfMarker
.MARKER_COLOR
, bookmark
.getColor().toString());
1358 } catch (CoreException e
) {
1359 Activator
.getDefault().logError(e
.getMessage());
1364 public void bookmarkRemoved(TimeGraphBookmarkEvent event
) {
1366 IMarkerEvent bookmark
= event
.getBookmark();
1367 IMarker
[] markers
= fEditorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1368 for (IMarker marker
: markers
) {
1369 if (bookmark
.getLabel().equals(marker
.getAttribute(IMarker
.MESSAGE
)) &&
1370 Long
.toString(bookmark
.getTime()).equals(marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null)) &&
1371 Long
.toString(bookmark
.getDuration()).equals(marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0))) &&
1372 bookmark
.getColor().toString().equals(marker
.getAttribute(ITmfMarker
.MARKER_COLOR
))) {
1377 } catch (CoreException e
) {
1378 Activator
.getDefault().logError(e
.getMessage());
1383 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
1385 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
1386 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
1388 // View Action Handling
1390 contributeToActionBars();
1392 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
1393 if (trace
!= null) {
1394 traceSelected(new TmfTraceSelectedSignal(this, trace
));
1397 // make selection available to other views
1398 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
1400 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
1402 createContextMenu();
1403 fPartListener
= new TimeGraphPartListener();
1404 getSite().getPage().addPartListener(fPartListener
);
1408 public void setFocus() {
1409 fTimeGraphWrapper
.setFocus();
1413 public void dispose() {
1415 synchronized (fBuildJobMap
) {
1416 fBuildJobMap
.values().forEach(buildJob
-> {
1420 if (fZoomThread
!= null) {
1421 fZoomThread
.cancel();
1423 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
1424 getSite().getPage().removePartListener(fPartListener
);
1431 public void resourceChanged(final IResourceChangeEvent event
) {
1432 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
1433 if (delta
.getResource().equals(fEditorFile
)) {
1434 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1441 private static List
<IMarkerEvent
> refreshBookmarks(final IFile editorFile
) {
1442 List
<IMarkerEvent
> bookmarks
= new ArrayList
<>();
1443 if (editorFile
== null || !editorFile
.exists()) {
1447 IMarker
[] markers
= editorFile
.findMarkers(IMarker
.BOOKMARK
, false, IResource
.DEPTH_ZERO
);
1448 for (IMarker marker
: markers
) {
1449 String label
= marker
.getAttribute(IMarker
.MESSAGE
, (String
) null);
1450 String time
= marker
.getAttribute(ITmfMarker
.MARKER_TIME
, (String
) null);
1451 String duration
= marker
.getAttribute(ITmfMarker
.MARKER_DURATION
, Long
.toString(0));
1452 String rgba
= marker
.getAttribute(ITmfMarker
.MARKER_COLOR
, (String
) null);
1453 if (label
!= null && time
!= null && rgba
!= null) {
1454 Matcher matcher
= RGBA_PATTERN
.matcher(rgba
);
1455 if (matcher
.matches()) {
1457 int red
= Integer
.valueOf(matcher
.group(1));
1458 int green
= Integer
.valueOf(matcher
.group(2));
1459 int blue
= Integer
.valueOf(matcher
.group(3));
1460 int alpha
= Integer
.valueOf(matcher
.group(4));
1461 RGBA color
= new RGBA(red
, green
, blue
, alpha
);
1462 bookmarks
.add(new MarkerEvent(null, Long
.valueOf(time
), Long
.valueOf(duration
), IMarkerEvent
.BOOKMARKS
, color
, label
, true));
1463 } catch (NumberFormatException e
) {
1464 Activator
.getDefault().logError(e
.getMessage());
1469 } catch (CoreException e
) {
1470 Activator
.getDefault().logError(e
.getMessage());
1477 // ------------------------------------------------------------------------
1479 // ------------------------------------------------------------------------
1482 * Handler for the trace opened signal.
1485 * The incoming signal
1488 public void traceOpened(TmfTraceOpenedSignal signal
) {
1489 loadTrace(signal
.getTrace());
1493 * Handler for the trace selected signal
1496 * The incoming signal
1499 public void traceSelected(final TmfTraceSelectedSignal signal
) {
1500 if (signal
.getTrace() == fTrace
) {
1503 loadTrace(signal
.getTrace());
1507 * Trace is closed: clear the data structures and the view
1510 * the signal received
1513 public void traceClosed(final TmfTraceClosedSignal signal
) {
1514 resetView(signal
.getTrace());
1515 if (signal
.getTrace() == fTrace
) {
1518 setStartTime(SWT
.DEFAULT
);
1519 setEndTime(SWT
.DEFAULT
);
1525 * Handler for the selection range signal.
1528 * The signal that's received
1532 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
1533 if (signal
.getSource() == this || fTrace
== null) {
1536 final long beginTime
= signal
.getBeginTime().toNanos();
1537 final long endTime
= signal
.getEndTime().toNanos();
1539 Display
.getDefault().asyncExec(new Runnable() {
1542 if (fTimeGraphWrapper
.isDisposed()) {
1545 if (beginTime
== endTime
) {
1546 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
1548 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
1550 synchingToTime(fTimeGraphWrapper
.getTimeGraphViewer().getSelectionBegin());
1556 * Handler for the window range signal.
1559 * The signal that's received
1563 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
1564 if (signal
.getSource() == this || fTrace
== null) {
1567 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
1570 final long startTime
= signal
.getCurrentRange().getStartTime().toNanos();
1571 final long endTime
= signal
.getCurrentRange().getEndTime().toNanos();
1572 Display
.getDefault().asyncExec(new Runnable() {
1575 if (fTimeGraphWrapper
.isDisposed()) {
1578 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1579 startZoomThread(startTime
, endTime
);
1585 * @param signal the format of the timestamps was updated.
1588 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1589 fTimeGraphWrapper
.refresh();
1593 * A marker event source has been updated
1600 public void markerEventSourceUpdated(final TmfMarkerEventSourceUpdatedSignal signal
) {
1601 getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1602 getTimeGraphViewer().setMarkers(null);
1606 // ------------------------------------------------------------------------
1608 // ------------------------------------------------------------------------
1610 private void loadTrace(final ITmfTrace trace
) {
1611 if (fZoomThread
!= null) {
1612 fZoomThread
.cancel();
1615 if (fTrace
!= null) {
1616 /* save the filters of the previous trace */
1617 fFiltersMap
.put(fTrace
, fTimeGraphWrapper
.getFilters());
1618 fViewContext
.put(fTrace
, new ViewContext(fCurrentSortColumn
, fSortDirection
, fTimeGraphWrapper
.getSelection()));
1622 LOGGER
.info(() -> getLogMessage("LoadingTrace", "trace=" + trace
.getName())); //$NON-NLS-1$ //$NON-NLS-2$
1624 restoreViewContext();
1625 fEditorFile
= TmfTraceManager
.getInstance().getTraceEditorFile(trace
);
1626 synchronized (fEntryListMap
) {
1627 fEntryList
= fEntryListMap
.get(fTrace
);
1628 if (fEntryList
== null) {
1631 setStartTime(fTrace
.getStartTime().toNanos());
1632 setEndTime(fTrace
.getEndTime().toNanos());
1639 * Forces a rebuild of the entries list, even if entries already exist for this trace
1641 protected void rebuild() {
1642 setStartTime(Long
.MAX_VALUE
);
1643 setEndTime(Long
.MIN_VALUE
);
1645 ITmfTrace viewTrace
= fTrace
;
1646 if (viewTrace
== null) {
1649 resetView(viewTrace
);
1651 List
<IMarkerEventSource
> markerEventSources
= new ArrayList
<>();
1652 synchronized (fBuildJobMap
) {
1653 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
1654 if (trace
== null) {
1657 markerEventSources
.addAll(TmfTraceAdapterManager
.getAdapters(trace
, IMarkerEventSource
.class));
1658 Job buildJob
= new Job(getTitle() + Messages
.AbstractTimeGraphView_BuildJob
) {
1660 protected IStatus
run(IProgressMonitor monitor
) {
1661 new BuildRunnable(trace
, viewTrace
).run(monitor
);
1663 return Status
.OK_STATUS
;
1666 fBuildJobMap
.put(trace
, buildJob
);
1667 buildJob
.schedule();
1670 fMarkerEventSourcesMap
.put(viewTrace
, markerEventSources
);
1674 * Method called when synching to a given timestamp. Inheriting classes can
1675 * perform actions here to update the view at the given timestamp.
1678 * The currently selected time
1680 protected void synchingToTime(long time
) {
1685 * Return the list of traces whose data or analysis results will be used to
1686 * populate the view. By default, if the trace is an experiment, the traces
1687 * under it will be returned, otherwise, the trace itself is returned.
1689 * A build thread will be started for each trace returned by this method,
1690 * some of which may receive events in live streaming mode.
1693 * The trace associated with this view, can be null
1694 * @return List of traces with data to display
1696 protected @NonNull Iterable
<ITmfTrace
> getTracesToBuild(@Nullable ITmfTrace trace
) {
1697 return TmfTraceManager
.getTraceSet(trace
);
1701 * Build the entry list to show in this time graph view.
1703 * Called from the BuildJob for each trace returned by
1704 * {@link #getTracesToBuild(ITmfTrace)}. The full event list is also
1705 * normally computed for every entry that is created.
1708 * The trace being built
1709 * @param parentTrace
1710 * The parent of the trace set, or the trace itself
1712 * The progress monitor object
1715 protected abstract void buildEntryList(@NonNull ITmfTrace trace
, @NonNull ITmfTrace parentTrace
, @NonNull IProgressMonitor monitor
);
1718 * Gets the list of event for an entry in a given time range.
1720 * Called from the ZoomThread for every entry to update the zoomed event
1721 * list. Can be an empty implementation if the view does not support zoomed
1722 * event lists. Can also be used to compute the full event list.
1725 * The entry to get events for
1727 * Start of the time range
1729 * End of the time range
1733 * The progress monitor object
1734 * @return The list of events for the entry
1736 protected abstract @Nullable List
<@NonNull ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
,
1737 long startTime
, long endTime
, long resolution
,
1738 @NonNull IProgressMonitor monitor
);
1741 * Gets the list of links (displayed as arrows) for a trace in a given
1742 * timerange. Default implementation returns an empty list.
1745 * Start of the time range
1747 * End of the time range
1751 * The progress monitor object
1752 * @return The list of link events
1754 protected @Nullable List
<@NonNull ILinkEvent
> getLinkList(long startTime
, long endTime
,
1755 long resolution
, @NonNull IProgressMonitor monitor
) {
1756 return new ArrayList
<>();
1760 * Gets the list of view-specific marker categories. Default implementation
1761 * returns an empty list.
1763 * @return The list of marker categories
1766 protected @NonNull List
<String
> getViewMarkerCategories() {
1767 return new ArrayList
<>();
1771 * Gets the list of view-specific markers for a trace in a given time range.
1772 * Default implementation returns an empty list.
1775 * Start of the time range
1777 * End of the time range
1781 * The progress monitor object
1782 * @return The list of marker events
1785 protected @NonNull List
<IMarkerEvent
> getViewMarkerList(long startTime
, long endTime
,
1786 long resolution
, @NonNull IProgressMonitor monitor
) {
1787 return new ArrayList
<>();
1791 * Gets the list of trace-specific markers for a trace in a given time range.
1794 * Start of the time range
1796 * End of the time range
1800 * The progress monitor object
1801 * @return The list of marker events
1804 protected @NonNull List
<IMarkerEvent
> getTraceMarkerList(long startTime
, long endTime
,
1805 long resolution
, @NonNull IProgressMonitor monitor
) {
1806 List
<IMarkerEvent
> markers
= new ArrayList
<>();
1807 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1808 for (String category
: markerEventSource
.getMarkerCategories()) {
1809 if (monitor
.isCanceled()) {
1812 markers
.addAll(markerEventSource
.getMarkerList(category
, startTime
, endTime
, resolution
, monitor
));
1819 * Get the list of current marker categories.
1821 * @return The list of marker categories
1824 protected @NonNull List
<String
> getMarkerCategories() {
1825 Set
<String
> categories
= new LinkedHashSet
<>(getViewMarkerCategories());
1826 for (IMarkerEventSource markerEventSource
: getMarkerEventSources(fTrace
)) {
1827 categories
.addAll(markerEventSource
.getMarkerCategories());
1829 return new ArrayList
<>(categories
);
1833 * Gets the list of marker event sources for a given trace.
1837 * @return The list of marker event sources
1840 private @NonNull List
<IMarkerEventSource
> getMarkerEventSources(ITmfTrace trace
) {
1841 List
<IMarkerEventSource
> markerEventSources
= fMarkerEventSourcesMap
.get(trace
);
1842 if (markerEventSources
== null) {
1843 markerEventSources
= Collections
.emptyList();
1845 return markerEventSources
;
1849 * Refresh the display
1851 protected void refresh() {
1852 LOGGER
.info(() -> getLogMessage("RefreshRequested", null)); //$NON-NLS-1$
1853 final boolean zoomThread
= Thread
.currentThread() instanceof ZoomThread
;
1854 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1857 LOGGER
.info(() -> getLogMessage("RefreshStart", null)); //$NON-NLS-1$
1858 if (fTimeGraphWrapper
.isDisposed()) {
1861 fDirty
.incrementAndGet();
1863 boolean hasEntries
= false;
1864 synchronized (fEntryListMap
) {
1865 fEntryList
= fEntryListMap
.get(fTrace
);
1866 if (fEntryList
== null) {
1867 fEntryList
= new CopyOnWriteArrayList
<>();
1868 } else if (fEntryComparator
!= null) {
1869 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1870 Collections
.sort(list
, fEntryComparator
);
1871 for (ITimeGraphEntry entry
: list
) {
1872 sortChildren(entry
, fEntryComparator
);
1875 fEntryList
.addAll(list
);
1877 hasEntries
= !fEntryList
.isEmpty();
1879 boolean inputChanged
= fEntryList
!= fTimeGraphWrapper
.getInput();
1880 TimeGraphCombo combo
= getTimeGraphCombo();
1882 // Set redraw to false to only draw once
1883 if (combo
!= null) {
1884 combo
.getTreeViewer().getTree().setRedraw(false);
1886 getTimeGraphViewer().getTimeGraphControl().setRedraw(false);
1888 fTimeGraphWrapper
.setInput(fEntryList
);
1889 /* restore the previously saved filters, if any */
1890 fTimeGraphWrapper
.setFilters(fFiltersMap
.get(fTrace
));
1891 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(null);
1892 fTimeGraphWrapper
.getTimeGraphViewer().setBookmarks(refreshBookmarks(fEditorFile
));
1893 fTimeGraphWrapper
.getTimeGraphViewer().setMarkerCategories(getMarkerCategories());
1894 fTimeGraphWrapper
.getTimeGraphViewer().setMarkers(null);
1897 fTimeGraphWrapper
.refresh();
1900 if (fIsRevealSelection
) {
1901 fIsRevealSelection
= false;
1902 ITimeGraphEntry entry1
= fTimeGraphWrapper
.getSelection();
1903 fTimeGraphWrapper
.setSelection(entry1
);
1906 if (combo
!= null) {
1907 combo
.getTreeViewer().getTree().setRedraw(true);
1909 getTimeGraphViewer().getTimeGraphControl().setRedraw(true);
1911 long startBound
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: fStartTime
);
1912 long endBound
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: fEndTime
);
1913 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(startBound
, endBound
);
1915 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
1916 long selectionBeginTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getStartTime().toNanos();
1917 long selectionEndTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getSelectionRange().getEndTime().toNanos();
1918 long startTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getStartTime().toNanos();
1919 long endTime
= fTrace
== null ? SWT
.DEFAULT
: ctx
.getWindowRange().getEndTime().toNanos();
1920 startTime
= (fStartTime
== Long
.MAX_VALUE ? SWT
.DEFAULT
: Math
.max(startTime
, fStartTime
));
1921 endTime
= (fEndTime
== Long
.MIN_VALUE ? SWT
.DEFAULT
: Math
.min(endTime
, fEndTime
));
1922 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
, false);
1923 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1925 if (inputChanged
&& selectionBeginTime
!= SWT
.DEFAULT
) {
1926 synchingToTime(selectionBeginTime
);
1929 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1930 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1939 startZoomThread(startTime
, endTime
);
1941 fDirty
.decrementAndGet();
1942 LOGGER
.info(() -> getLogMessage("RefreshEnd", null)); //$NON-NLS-1$
1950 protected void redraw() {
1951 synchronized (fSyncObj
) {
1952 if (fRedrawState
== State
.IDLE
) {
1953 fRedrawState
= State
.BUSY
;
1955 fRedrawState
= State
.PENDING
;
1959 LOGGER
.info(() -> getLogMessage("RedrawRequested", null)); //$NON-NLS-1$
1960 Display
.getDefault().asyncExec(new Runnable() {
1963 LOGGER
.info(() -> getLogMessage("RedrawStart", null)); //$NON-NLS-1$
1964 if (fTimeGraphWrapper
.isDisposed()) {
1967 fTimeGraphWrapper
.redraw();
1968 fTimeGraphWrapper
.update();
1969 synchronized (fSyncObj
) {
1970 if (fRedrawState
== State
.PENDING
) {
1971 fRedrawState
= State
.IDLE
;
1974 fRedrawState
= State
.IDLE
;
1977 LOGGER
.info(() -> getLogMessage("RedrawEnd", null)); //$NON-NLS-1$
1982 private void sortChildren(ITimeGraphEntry entry
, Comparator
<ITimeGraphEntry
> comparator
) {
1983 if (entry
instanceof TimeGraphEntry
) {
1984 ((TimeGraphEntry
) entry
).sortChildren(comparator
);
1986 for (ITimeGraphEntry child
: entry
.getChildren()) {
1987 sortChildren(child
, comparator
);
1992 * Start or restart the zoom thread.
1995 * the zoom start time
2000 protected final void startZoomThread(long startTime
, long endTime
) {
2001 long clampedStartTime
= (fStartTime
== Long
.MAX_VALUE ? startTime
: Math
.min(Math
.max(startTime
, fStartTime
), fEndTime
));
2002 long clampedEndTime
= (fEndTime
== Long
.MIN_VALUE ? endTime
: Math
.max(Math
.min(endTime
, fEndTime
), fStartTime
));
2003 fDirty
.incrementAndGet();
2004 boolean restart
= false;
2005 if (fZoomThread
!= null) {
2006 fZoomThread
.cancel();
2007 if (fZoomThread
.fZoomStartTime
== clampedStartTime
&& fZoomThread
.fZoomEndTime
== clampedEndTime
) {
2011 long resolution
= Math
.max(1, (clampedEndTime
- clampedStartTime
) / fDisplayWidth
);
2012 fZoomThread
= createZoomThread(clampedStartTime
, clampedEndTime
, resolution
, restart
);
2013 if (fZoomThread
!= null) {
2014 // Don't start a new thread right away if results are being applied
2015 // from an old ZoomThread. Otherwise, the old results might
2016 // overwrite the new results if it finishes after.
2017 synchronized (fZoomThreadResultLock
) {
2018 fZoomThread
.start();
2021 fDirty
.decrementAndGet();
2026 * Create a zoom thread.
2029 * the zoom start time
2035 * true if restarting zoom for the same time range
2036 * @return a zoom thread
2039 protected @Nullable ZoomThread
createZoomThread(long startTime
, long endTime
, long resolution
, boolean restart
) {
2040 final List
<TimeGraphEntry
> entryList
= fEntryList
;
2041 if (entryList
== null) {
2044 return new ZoomThreadByEntry(entryList
, startTime
, endTime
, resolution
);
2047 private void makeActions() {
2048 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
2049 fPreviousResourceAction
.setText(getPrevText());
2050 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
2051 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
2052 fNextResourceAction
.setText(getNextText());
2053 fNextResourceAction
.setToolTipText(getNextTooltip());
2056 private void contributeToActionBars() {
2057 IActionBars bars
= getViewSite().getActionBars();
2058 fillLocalToolBar(bars
.getToolBarManager());
2059 fillLocalMenu(bars
.getMenuManager());
2063 * Add actions to local tool bar manager
2065 * @param manager the tool bar manager
2067 protected void fillLocalToolBar(IToolBarManager manager
) {
2068 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
2069 manager
.add(fTimeGraphWrapper
.getShowFilterDialogAction());
2071 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
2072 manager
.add(new Separator());
2073 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
2074 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
2075 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
2076 manager
.add(new Separator());
2077 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getToggleBookmarkAction());
2078 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousMarkerAction());
2079 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextMarkerAction());
2080 manager
.add(new Separator());
2081 manager
.add(fPreviousResourceAction
);
2082 manager
.add(fNextResourceAction
);
2083 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
2084 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
2085 manager
.add(new Separator());
2089 * Add actions to local menu manager
2091 * @param manager the tool bar manager
2094 protected void fillLocalMenu(IMenuManager manager
) {
2095 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getMarkersMenu());
2102 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
2103 if (fTimeGraphWrapper
== null) {
2106 return fTimeGraphWrapper
.getTimeViewAlignmentInfo();
2113 public int getAvailableWidth(int requestedOffset
) {
2114 if (fTimeGraphWrapper
== null) {
2117 return fTimeGraphWrapper
.getAvailableWidth(requestedOffset
);
2124 public void performAlign(int offset
, int width
) {
2125 if (fTimeGraphWrapper
!= null) {
2126 fTimeGraphWrapper
.performAlign(offset
, width
);
2131 * Returns whether or not the time graph view is dirty. The time graph view
2132 * is considered dirty if it has yet to completely update its model.
2134 * This method is meant to be used by tests in order to know when it is safe
2137 * Note: If a trace is smaller than the initial window range (see
2138 * {@link ITmfTrace#getInitialRangeOffset}) this method will return true
2141 * @return true if the time graph view has yet to completely update its
2142 * model, false otherwise
2145 public boolean isDirty() {
2146 if (fTrace
== null) {
2150 TmfTraceContext ctx
= TmfTraceManager
.getInstance().getCurrentTraceContext();
2151 long startTime
= ctx
.getWindowRange().getStartTime().toNanos();
2152 long endTime
= ctx
.getWindowRange().getEndTime().toNanos();
2154 // If the time graph control hasn't updated all the way to the end of
2155 // the window range then it's dirty. A refresh should happen later.
2156 if (fTimeGraphWrapper
.getTimeGraphViewer().getTime0() != startTime
|| fTimeGraphWrapper
.getTimeGraphViewer().getTime1() != endTime
) {
2160 if (fZoomThread
== null) {
2161 // The zoom thread is null but we might be just about to create it (refresh called).
2162 return fDirty
.get() != 0;
2164 // Dirty if the zoom thread is not done or if it hasn't zoomed all the
2165 // way to the end of the window range. In the latter case, there should be
2166 // a subsequent zoom thread that will be triggered.
2167 return fDirty
.get() != 0 || fZoomThread
.getZoomStartTime() != startTime
|| fZoomThread
.getZoomEndTime() != endTime
;
2170 private void createColumnSelectionListener(TreeViewer treeViewer
) {
2171 for (int i
= 0; i
< fColumnComparators
.length
; i
++) {
2172 final int index
= i
;
2173 final Comparator
<ITimeGraphEntry
> comp
= fColumnComparators
[index
];
2174 final Tree tree
= treeViewer
.getTree();
2175 final TreeColumn column
= tree
.getColumn(i
);
2178 column
.addSelectionListener(new SelectionAdapter() {
2180 public void widgetSelected(SelectionEvent e
) {
2181 TreeColumn prevSortcolumn
= tree
.getSortColumn();
2182 int direction
= tree
.getSortDirection();
2183 if (prevSortcolumn
== column
) {
2184 direction
= (direction
== SWT
.DOWN
) ? SWT
.UP
: SWT
.DOWN
;
2186 direction
= SWT
.DOWN
;
2188 tree
.setSortColumn(column
);
2189 tree
.setSortDirection(direction
);
2190 fSortDirection
= direction
;
2191 fCurrentSortColumn
= index
;
2192 Comparator
<ITimeGraphEntry
> comparator
= comp
;
2194 if (comparator
instanceof ITimeGraphEntryComparator
) {
2195 ((ITimeGraphEntryComparator
) comparator
).setDirection(direction
);
2197 if (direction
!= SWT
.DOWN
) {
2198 comparator
= checkNotNull(Collections
.reverseOrder(comparator
));
2200 setEntryComparator(comparator
);
2201 fIsRevealSelection
= true;
2202 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
2203 ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getControl().setFocus();
2212 private void createDoubleClickListener(TreeViewer treeViewer
) {
2213 treeViewer
.addDoubleClickListener(event
-> {
2214 if (event
.getSelection() instanceof TreeSelection
) {
2215 TreeSelection selection
= (TreeSelection
) event
.getSelection();
2216 if (selection
.getFirstElement() instanceof ITimeGraphEntry
) {
2217 ITimeGraphEntry entry
= (ITimeGraphEntry
) selection
.getFirstElement();
2218 if (entry
.hasChildren()) {
2219 fTimeGraphWrapper
.setExpandedState(entry
, !fTimeGraphWrapper
.getExpandedState(entry
));
2227 private void restoreViewContext() {
2228 TimeGraphCombo combo
= getTimeGraphCombo();
2229 ViewContext viewContext
= fViewContext
.get(fTrace
);
2230 if (combo
!= null) {
2231 if (fColumnComparators
!= null) {
2232 // restore sort settings
2233 fSortDirection
= SWT
.DOWN
;
2234 fCurrentSortColumn
= fInitialSortColumn
;
2235 if (viewContext
!= null) {
2236 fSortDirection
= viewContext
.getSortDirection();
2237 fCurrentSortColumn
= viewContext
.getSortColumn();
2239 if ((fCurrentSortColumn
< fColumnComparators
.length
) && (fColumnComparators
[fCurrentSortColumn
] != null)) {
2240 Comparator
<ITimeGraphEntry
> comparator
= fColumnComparators
[fCurrentSortColumn
];
2241 if (comparator
instanceof ITimeGraphEntryComparator
) {
2242 ((ITimeGraphEntryComparator
) comparator
).setDirection(fSortDirection
);
2244 if (fSortDirection
!= SWT
.DOWN
) {
2245 comparator
= checkNotNull(Collections
.reverseOrder(comparator
));
2247 setEntryComparator(comparator
);
2253 private void applyViewContext() {
2254 TimeGraphCombo combo
= getTimeGraphCombo();
2255 ViewContext viewContext
= fViewContext
.get(fTrace
);
2256 if (combo
!= null) {
2257 TreeViewer treeViewer
= combo
.getTreeViewer();
2258 final Tree tree
= treeViewer
.getTree();
2259 final TreeColumn column
= tree
.getColumn(fCurrentSortColumn
);
2260 tree
.setSortDirection(fSortDirection
);
2261 tree
.setSortColumn(column
);
2262 combo
.getTreeViewer().getControl().setFocus();
2264 // restore and reveal selection
2265 if ((viewContext
!= null) && (viewContext
.getSelection() != null)) {
2266 fTimeGraphWrapper
.setSelection(viewContext
.getSelection());
2268 fViewContext
.remove(fTrace
);
2271 private static class ViewContext
{
2272 private int fSortColumnIndex
;
2273 private int fSortDirection
;
2274 private @Nullable ITimeGraphEntry fSelection
;
2276 ViewContext(int sortColunm
, int sortDirection
, ITimeGraphEntry selection
) {
2277 fSortColumnIndex
= sortColunm
;
2278 fSortDirection
= sortDirection
;
2279 fSelection
= selection
;
2282 * @return the sortColumn
2284 public int getSortColumn() {
2285 return fSortColumnIndex
;
2288 * @return the sortDirection
2290 public int getSortDirection() {
2291 return fSortDirection
;
2294 * @return the selection
2296 public ITimeGraphEntry
getSelection() {
2302 * Method to reset the view internal data for a given trace.
2304 * When overriding this method make sure to call the super
2308 * trace to reset the view for.
2311 protected void resetView(ITmfTrace viewTrace
) {
2312 if (viewTrace
== null) {
2315 synchronized (fBuildJobMap
) {
2316 for (ITmfTrace trace
: getTracesToBuild(viewTrace
)) {
2317 Job buildJob
= fBuildJobMap
.remove(trace
);
2318 if (buildJob
!= null) {
2323 synchronized (fEntryListMap
) {
2324 fEntryListMap
.remove(viewTrace
);
2326 fViewContext
.remove(viewTrace
);
2327 fFiltersMap
.remove(viewTrace
);
2328 fMarkerEventSourcesMap
.remove(viewTrace
);
2329 if (viewTrace
== fTrace
) {
2330 if (fZoomThread
!= null) {
2331 fZoomThread
.cancel();
2337 private void createContextMenu() {
2338 TimeGraphCombo combo
= getTimeGraphCombo();
2339 fEntryMenuManager
.setRemoveAllWhenShown(true);
2340 if (combo
!= null) {
2341 TreeViewer treeViewer
= combo
.getTreeViewer();
2342 Tree tree
= treeViewer
.getTree();
2343 Menu menu
= fEntryMenuManager
.createContextMenu(tree
);
2346 TimeGraphControl timeGraphControl
= getTimeGraphViewer().getTimeGraphControl();
2347 final Menu entryMenu
= fEntryMenuManager
.createContextMenu(timeGraphControl
);
2348 timeGraphControl
.addTimeGraphEntryMenuListener(new MenuDetectListener() {
2350 public void menuDetected(MenuDetectEvent event
) {
2351 Point p
= timeGraphControl
.toControl(event
.x
, event
.y
);
2353 * The TimeGraphControl will call the TimeGraphEntryMenuListener
2354 * before the TimeEventMenuListener. If the event is
2355 * triggered on the namespace then show the menu else
2358 if (p
.x
< getTimeGraphViewer().getNameSpace()) {
2359 timeGraphControl
.setMenu(entryMenu
);
2361 timeGraphControl
.setMenu(null);
2367 fEntryMenuManager
.addMenuListener(new IMenuListener() {
2369 public void menuAboutToShow(IMenuManager manager
) {
2370 fillTimeGraphEntryContextMenu(fEntryMenuManager
);
2371 fEntryMenuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
2374 getSite().registerContextMenu(fEntryMenuManager
, fTimeGraphWrapper
.getSelectionProvider());
2380 * @param menuManager
2381 * a menuManager to fill
2384 protected void fillTimeGraphEntryContextMenu (@NonNull IMenuManager menuManager
) {
2388 * Inner classes used for searching
2391 public ITimeGraphEntry
getSelection() {
2392 return fTimeGraphWrapper
.getSelection();
2395 public void selectAndReveal(@NonNull ITimeGraphEntry entry
) {
2396 fTimeGraphWrapper
.selectAndReveal(entry
);
2399 public ITimeGraphEntry
[] getEntries() {
2400 TimeGraphViewer viewer
= getTimeGraphViewer();
2401 return viewer
.getTimeGraphContentProvider().getElements(viewer
.getInput());
2404 public Shell
getShell() {
2405 return getSite().getShell();
2409 class TimeGraphPartListener
implements IPartListener
{
2411 public void partActivated(IWorkbenchPart part
) {
2412 if (part
== AbstractTimeGraphView
.this) {
2413 synchronized (FIND_ACTION
) {
2414 if (fFindActionHandler
== null) {
2415 fFindActionHandler
= new ActionHandler(FIND_ACTION
);
2417 if (fFindHandlerActivation
== null) {
2418 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
2419 fFindHandlerActivation
= ((IHandlerService
) service
).activateHandler(ActionFactory
.FIND
.getCommandId(), fFindActionHandler
);
2423 // Notify action for all parts
2424 FIND_ACTION
.partActivated(part
);
2427 public void partDeactivated(IWorkbenchPart part
) {
2428 if ((part
== AbstractTimeGraphView
.this) && (fFindHandlerActivation
!= null)) {
2429 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
2430 ((IHandlerService
) service
).deactivateHandler(fFindHandlerActivation
);
2431 fFindHandlerActivation
= null;
2435 public void partBroughtToTop(IWorkbenchPart part
) {
2438 public void partClosed(IWorkbenchPart part
) {
2441 public void partOpened(IWorkbenchPart part
) {