1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated signal handling
12 * Geneviève Bastien - Move code to provide base classes for time graph view
13 * Marc-Andre Laperle - Add time zone preference
14 * Geneviève Bastien - Add event links between entries
15 *******************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.timegraph
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Arrays
;
21 import java
.util
.Collections
;
22 import java
.util
.Comparator
;
23 import java
.util
.HashMap
;
24 import java
.util
.List
;
26 import java
.util
.concurrent
.CopyOnWriteArrayList
;
28 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
29 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
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
.ILabelProviderListener
;
37 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
38 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
39 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
40 import org
.eclipse
.jface
.viewers
.TreeViewer
;
41 import org
.eclipse
.jface
.viewers
.Viewer
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
52 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
53 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiRefreshHandler
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
61 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
62 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
63 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
64 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphSelectionEvent
;
65 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
66 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
67 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
68 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
69 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
70 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
71 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
72 import org
.eclipse
.swt
.SWT
;
73 import org
.eclipse
.swt
.graphics
.Image
;
74 import org
.eclipse
.swt
.widgets
.Composite
;
75 import org
.eclipse
.swt
.widgets
.Display
;
76 import org
.eclipse
.swt
.widgets
.TreeColumn
;
77 import org
.eclipse
.ui
.IActionBars
;
80 * An abstract view all time graph views can inherit
82 * This view contains either a time graph viewer, or a time graph combo which is
83 * divided between a tree viewer on the left and a time graph viewer on the right.
87 public abstract class AbstractTimeGraphView
extends TmfView
{
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
100 /** The timegraph wrapper */
101 private ITimeGraphWrapper fTimeGraphWrapper
;
103 /** The selected trace */
104 private ITmfTrace fTrace
;
106 /** The timegraph entry list */
107 private List
<TimeGraphEntry
> fEntryList
;
109 /** The trace to entry list hash map */
110 private final Map
<ITmfTrace
, List
<TimeGraphEntry
>> fEntryListMap
= new HashMap
<>();
112 /** The trace to build thread hash map */
113 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
115 /** The start time */
116 private long fStartTime
;
119 private long fEndTime
;
121 /** The display width */
122 private final int fDisplayWidth
;
124 /** The zoom thread */
125 private ZoomThread fZoomThread
;
127 /** The next resource action */
128 private Action fNextResourceAction
;
130 /** The previous resource action */
131 private Action fPreviousResourceAction
;
133 /** A comparator class */
134 private Comparator
<ITimeGraphEntry
> fEntryComparator
= null;
136 /** The redraw state used to prevent unnecessary queuing of display runnables */
137 private State fRedrawState
= State
.IDLE
;
139 /** The redraw synchronization object */
140 private final Object fSyncObj
= new Object();
142 /** The presentation provider for this view */
143 private final TimeGraphPresentationProvider fPresentation
;
145 /** The tree column label array, or null if combo is not used */
146 private String
[] fColumns
;
148 /** The tree label provider, or null if combo is not used */
149 private TreeLabelProvider fLabelProvider
= null;
151 /** The relative weight of the sash, ignored if combo is not used */
152 private int[] fWeight
= { 1, 1 };
154 /** The filter column label array, or null if filter is not used */
155 private String
[] fFilterColumns
;
157 /** The pack done flag */
158 private boolean fPackDone
= false;
160 /** The filter label provider, or null if filter is not used */
161 private TreeLabelProvider fFilterLabelProvider
;
163 // ------------------------------------------------------------------------
165 // ------------------------------------------------------------------------
167 private interface ITimeGraphWrapper
{
169 void setTimeGraphProvider(TimeGraphPresentationProvider fPresentation
);
171 TimeGraphViewer
getTimeGraphViewer();
173 void addSelectionListener(ITimeGraphSelectionListener iTimeGraphSelectionListener
);
175 ISelectionProvider
getSelectionProvider();
179 boolean isDisposed();
183 void setInput(Object input
);
193 private class TimeGraphViewerWrapper
implements ITimeGraphWrapper
{
194 private TimeGraphViewer viewer
;
196 private TimeGraphViewerWrapper(Composite parent
, int style
) {
197 viewer
= new TimeGraphViewer(parent
, style
);
201 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
202 viewer
.setTimeGraphProvider(timeGraphProvider
);
206 public TimeGraphViewer
getTimeGraphViewer() {
211 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
212 viewer
.addSelectionListener(listener
);
216 public ISelectionProvider
getSelectionProvider() {
217 return viewer
.getSelectionProvider();
221 public void setFocus() {
226 public boolean isDisposed() {
227 return viewer
.getControl().isDisposed();
231 public void setInput(Object input
) {
232 viewer
.setInput(input
);
236 public Object
getInput() {
237 return viewer
.getInput();
241 public void refresh() {
246 public void redraw() {
247 viewer
.getControl().redraw();
251 public void update() {
252 viewer
.getControl().update();
256 private class TimeGraphComboWrapper
implements ITimeGraphWrapper
{
257 private TimeGraphCombo combo
;
259 private TimeGraphComboWrapper(Composite parent
, int style
) {
260 combo
= new TimeGraphCombo(parent
, style
, fWeight
);
264 public void setTimeGraphProvider(TimeGraphPresentationProvider timeGraphProvider
) {
265 combo
.setTimeGraphProvider(timeGraphProvider
);
269 public TimeGraphViewer
getTimeGraphViewer() {
270 return combo
.getTimeGraphViewer();
274 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
275 combo
.addSelectionListener(listener
);
279 public ISelectionProvider
getSelectionProvider() {
280 return combo
.getTreeViewer();
284 public void setFocus() {
289 public boolean isDisposed() {
290 return combo
.isDisposed();
294 public void setInput(Object input
) {
295 combo
.setInput(input
);
299 public Object
getInput() {
300 return combo
.getInput();
304 public void refresh() {
309 public void redraw() {
314 public void update() {
318 TimeGraphCombo
getTimeGraphCombo() {
322 TreeViewer
getTreeViewer() {
323 return combo
.getTreeViewer();
326 IAction
getShowFilterAction() {
327 return combo
.getShowFilterAction();
331 private class TreeContentProvider
implements ITreeContentProvider
{
334 public void dispose() {
338 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
342 public ITimeGraphEntry
[] getElements(Object inputElement
) {
343 if (inputElement
!= null) {
345 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
346 } catch (ClassCastException e
) {
349 return new ITimeGraphEntry
[0];
353 public Object
[] getChildren(Object parentElement
) {
354 ITimeGraphEntry entry
= (ITimeGraphEntry
) parentElement
;
355 List
<?
extends ITimeGraphEntry
> children
= entry
.getChildren();
356 return children
.toArray(new ITimeGraphEntry
[children
.size()]);
360 public Object
getParent(Object element
) {
361 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
362 return entry
.getParent();
366 public boolean hasChildren(Object element
) {
367 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
368 return entry
.hasChildren();
373 private class TimeGraphContentProvider
implements ITimeGraphContentProvider
{
376 public ITimeGraphEntry
[] getElements(Object inputElement
) {
377 if (inputElement
!= null) {
379 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
380 } catch (ClassCastException e
) {
383 return new ITimeGraphEntry
[0];
389 * Base class to provide the labels for the tree viewer. Views extending
390 * this class typically need to override the getColumnText method if they
391 * have more than one column to display
393 protected static class TreeLabelProvider
implements ITableLabelProvider
{
396 public void addListener(ILabelProviderListener listener
) {
400 public void dispose() {
404 public boolean isLabelProperty(Object element
, String property
) {
409 public void removeListener(ILabelProviderListener listener
) {
413 public Image
getColumnImage(Object element
, int columnIndex
) {
418 public String
getColumnText(Object element
, int columnIndex
) {
419 TimeGraphEntry entry
= (TimeGraphEntry
) element
;
420 if (columnIndex
== 0) {
421 return entry
.getName();
428 private class BuildThread
extends Thread
{
429 private final ITmfTrace fBuildTrace
;
430 private final ITmfTrace fParentTrace
;
431 private final IProgressMonitor fMonitor
;
433 public BuildThread(final ITmfTrace trace
, final ITmfTrace parentTrace
, final String name
) {
434 super(name
+ " build"); //$NON-NLS-1$
436 fParentTrace
= parentTrace
;
437 fMonitor
= new NullProgressMonitor();
442 buildEventList(fBuildTrace
, fParentTrace
, fMonitor
);
443 synchronized (fBuildThreadMap
) {
444 fBuildThreadMap
.remove(fBuildTrace
);
448 public void cancel() {
449 fMonitor
.setCanceled(true);
453 private class ZoomThread
extends Thread
{
454 private final List
<TimeGraphEntry
> fZoomEntryList
;
455 private final long fZoomStartTime
;
456 private final long fZoomEndTime
;
457 private final long fResolution
;
458 private final IProgressMonitor fMonitor
;
460 public ZoomThread(List
<TimeGraphEntry
> entryList
, long startTime
, long endTime
, String name
) {
461 super(name
+ " zoom"); //$NON-NLS-1$
462 fZoomEntryList
= entryList
;
463 fZoomStartTime
= startTime
;
464 fZoomEndTime
= endTime
;
465 fResolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
466 fMonitor
= new NullProgressMonitor();
471 if (fZoomEntryList
== null) {
474 for (TimeGraphEntry entry
: fZoomEntryList
) {
475 if (fMonitor
.isCanceled()) {
478 zoom(entry
, fMonitor
);
480 /* Refresh the arrows when zooming */
481 List
<ILinkEvent
> events
= getLinkList(fZoomStartTime
, fZoomEndTime
, fResolution
, fMonitor
);
482 if (events
!= null) {
483 fTimeGraphWrapper
.getTimeGraphViewer().setLinks(events
);
488 private void zoom(TimeGraphEntry entry
, IProgressMonitor monitor
) {
489 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
490 entry
.setZoomedEventList(null);
492 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, fResolution
, monitor
);
493 if (zoomedEventList
!= null) {
494 entry
.setZoomedEventList(zoomedEventList
);
498 for (TimeGraphEntry child
: entry
.getChildren()) {
499 if (fMonitor
.isCanceled()) {
502 zoom(child
, monitor
);
506 public void cancel() {
507 fMonitor
.setCanceled(true);
511 // ------------------------------------------------------------------------
513 // ------------------------------------------------------------------------
516 * Constructs a time graph view that contains either a time graph viewer or
517 * a time graph combo.
519 * By default, the view uses a time graph viewer. To use a time graph combo,
520 * the subclass constructor must call {@link #setTreeColumns(String[])} and
521 * {@link #setTreeLabelProvider(TreeLabelProvider)}.
526 * The presentation provider
528 public AbstractTimeGraphView(String id
, TimeGraphPresentationProvider pres
) {
530 fPresentation
= pres
;
531 fDisplayWidth
= Display
.getDefault().getBounds().width
;
534 // ------------------------------------------------------------------------
535 // Getters and setters
536 // ------------------------------------------------------------------------
539 * Getter for the time graph combo
541 * @return The time graph combo, or null if combo is not used
543 protected TimeGraphCombo
getTimeGraphCombo() {
544 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
545 return ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTimeGraphCombo();
551 * Getter for the time graph viewer
553 * @return The time graph viewer
555 protected TimeGraphViewer
getTimeGraphViewer() {
556 return fTimeGraphWrapper
.getTimeGraphViewer();
560 * Getter for the presentation provider
562 * @return The time graph presentation provider
565 protected ITimeGraphPresentationProvider2
getPresentationProvider() {
566 return fPresentation
;
570 * Sets the tree column labels.
571 * This should be called from the constructor.
574 * The array of tree column labels
576 protected void setTreeColumns(final String
[] columns
) {
581 * Sets the tree label provider.
582 * This should be called from the constructor.
585 * The tree label provider
587 protected void setTreeLabelProvider(final TreeLabelProvider tlp
) {
588 fLabelProvider
= tlp
;
592 * Sets the relative weight of each part of the time graph combo.
593 * This should be called from the constructor.
596 * The array (length 2) of relative weights of each part of the combo
598 protected void setWeight(final int[] weights
) {
603 * Sets the filter column labels.
604 * This should be called from the constructor.
606 * @param filterColumns
607 * The array of filter column labels
609 protected void setFilterColumns(final String
[] filterColumns
) {
610 fFilterColumns
= filterColumns
;
614 * Sets the filter label provider.
615 * This should be called from the constructor.
617 * @param labelProvider
618 * The filter label provider
622 protected void setFilterLabelProvider(final TreeLabelProvider labelProvider
) {
623 fFilterLabelProvider
= labelProvider
;
627 * Gets the display width
629 * @return the display width
631 protected int getDisplayWidth() {
632 return fDisplayWidth
;
636 * Gets the comparator for the entries
638 * @return The entry comparator
640 protected Comparator
<ITimeGraphEntry
> getEntryComparator() {
641 return fEntryComparator
;
645 * Sets the comparator class for the entries
648 * A comparator object
650 protected void setEntryComparator(final Comparator
<ITimeGraphEntry
> comparator
) {
651 fEntryComparator
= comparator
;
655 * Gets the trace displayed in the view
659 protected ITmfTrace
getTrace() {
664 * Gets the start time
666 * @return The start time
668 protected long getStartTime() {
673 * Sets the start time
678 protected void setStartTime(long time
) {
685 * @return The end time
687 protected long getEndTime() {
697 protected void setEndTime(long time
) {
702 * Gets the entry list for a trace
707 * @return the entry list map
710 protected List
<TimeGraphEntry
> getEntryList(ITmfTrace trace
) {
711 synchronized (fEntryListMap
) {
712 return fEntryListMap
.get(trace
);
717 * Adds a trace entry list to the entry list map
722 * the list of time graph entries
724 protected void putEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
725 synchronized (fEntryListMap
) {
726 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
731 * Adds a list of entries to a trace's entry list
736 * the list of time graph entries to add
739 protected void addToEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
740 synchronized (fEntryListMap
) {
741 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
742 if (entryList
== null) {
743 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
745 entryList
.addAll(list
);
751 * Removes a list of entries from a trace's entry list
756 * the list of time graph entries to remove
759 protected void removeFromEntryList(ITmfTrace trace
, List
<TimeGraphEntry
> list
) {
760 synchronized (fEntryListMap
) {
761 List
<TimeGraphEntry
> entryList
= fEntryListMap
.get(trace
);
762 if (entryList
!= null) {
763 entryList
.removeAll(list
);
769 * Text for the "next" button
771 * @return The "next" button text
773 protected String
getNextText() {
774 return Messages
.AbstractTimeGraphtView_NextText
;
778 * Tooltip for the "next" button
780 * @return Tooltip for the "next" button
782 protected String
getNextTooltip() {
783 return Messages
.AbstractTimeGraphView_NextTooltip
;
787 * Text for the "Previous" button
789 * @return The "Previous" button text
791 protected String
getPrevText() {
792 return Messages
.AbstractTimeGraphView_PreviousText
;
796 * Tooltip for the "previous" button
798 * @return Tooltip for the "previous" button
800 protected String
getPrevTooltip() {
801 return Messages
.AbstractTimeGraphView_PreviousTooltip
;
804 // ------------------------------------------------------------------------
806 // ------------------------------------------------------------------------
809 public void createPartControl(Composite parent
) {
810 if (fColumns
== null || fLabelProvider
== null) {
811 fTimeGraphWrapper
= new TimeGraphViewerWrapper(parent
, SWT
.NONE
);
812 TimeGraphViewer viewer
= fTimeGraphWrapper
.getTimeGraphViewer();
813 viewer
.setTimeGraphContentProvider(new TimeGraphContentProvider());
815 TimeGraphComboWrapper wrapper
= new TimeGraphComboWrapper(parent
, SWT
.NONE
);
816 fTimeGraphWrapper
= wrapper
;
817 TimeGraphCombo combo
= wrapper
.getTimeGraphCombo();
818 combo
.setTreeContentProvider(new TreeContentProvider());
819 combo
.setTreeLabelProvider(fLabelProvider
);
820 combo
.setTreeColumns(fColumns
);
821 combo
.setFilterContentProvider(new TreeContentProvider());
822 combo
.setFilterLabelProvider(fFilterLabelProvider
);
823 combo
.setFilterColumns(fFilterColumns
);
824 combo
.setTimeGraphContentProvider(new TimeGraphContentProvider());
827 fTimeGraphWrapper
.setTimeGraphProvider(fPresentation
);
829 fTimeGraphWrapper
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
831 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
832 final long startTime
= event
.getStartTime();
833 final long endTime
= event
.getEndTime();
834 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
835 broadcast(new TmfRangeSynchSignal(AbstractTimeGraphView
.this, range
));
836 if (fZoomThread
!= null) {
837 fZoomThread
.cancel();
839 startZoomThread(startTime
, endTime
);
843 fTimeGraphWrapper
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
845 public void timeSelected(TimeGraphTimeEvent event
) {
846 TmfNanoTimestamp startTime
= new TmfNanoTimestamp(event
.getBeginTime());
847 TmfNanoTimestamp endTime
= new TmfNanoTimestamp(event
.getEndTime());
848 broadcast(new TmfTimeSynchSignal(AbstractTimeGraphView
.this, startTime
, endTime
));
852 fTimeGraphWrapper
.addSelectionListener(new ITimeGraphSelectionListener() {
854 public void selectionChanged(TimeGraphSelectionEvent event
) {
855 // ITimeGraphEntry selection = event.getSelection();
859 fTimeGraphWrapper
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
861 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
862 fTimeGraphWrapper
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
864 // View Action Handling
866 contributeToActionBars();
868 ITmfTrace trace
= getActiveTrace();
870 traceSelected(new TmfTraceSelectedSignal(this, trace
));
873 // make selection available to other views
874 getSite().setSelectionProvider(fTimeGraphWrapper
.getSelectionProvider());
878 public void setFocus() {
879 fTimeGraphWrapper
.setFocus();
882 // ------------------------------------------------------------------------
884 // ------------------------------------------------------------------------
887 * Handler for the trace opened signal.
890 * The incoming signal
894 public void traceOpened(TmfTraceOpenedSignal signal
) {
895 fTrace
= signal
.getTrace();
900 * Handler for the trace selected signal
903 * The incoming signal
906 public void traceSelected(final TmfTraceSelectedSignal signal
) {
907 if (signal
.getTrace() == fTrace
) {
910 fTrace
= signal
.getTrace();
916 * Trace is closed: clear the data structures and the view
919 * the signal received
922 public void traceClosed(final TmfTraceClosedSignal signal
) {
923 synchronized (fBuildThreadMap
) {
924 for (ITmfTrace trace
: getTracesToBuild(signal
.getTrace())) {
925 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
926 if (buildThread
!= null) {
927 buildThread
.cancel();
931 synchronized (fEntryListMap
) {
932 fEntryListMap
.remove(signal
.getTrace());
934 if (signal
.getTrace() == fTrace
) {
938 if (fZoomThread
!= null) {
939 fZoomThread
.cancel();
946 * Handler for the time synch signal
949 * The signal that's received
952 public void synchToTime(final TmfTimeSynchSignal signal
) {
953 if (signal
.getSource() == this || fTrace
== null) {
956 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
957 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
959 Display
.getDefault().asyncExec(new Runnable() {
962 if (fTimeGraphWrapper
.isDisposed()) {
965 if (beginTime
== endTime
) {
966 fTimeGraphWrapper
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
968 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
);
970 startZoomThread(fTimeGraphWrapper
.getTimeGraphViewer().getTime0(), fTimeGraphWrapper
.getTimeGraphViewer().getTime1());
972 synchingToTime(beginTime
);
978 * Handler for the range synch signal
981 * The signal that's received
984 public void synchToRange(final TmfRangeSynchSignal signal
) {
985 if (signal
.getSource() == this || fTrace
== null) {
988 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
991 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
992 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
993 Display
.getDefault().asyncExec(new Runnable() {
996 if (fTimeGraphWrapper
.isDisposed()) {
999 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1000 startZoomThread(startTime
, endTime
);
1006 * @param signal the format of the timestamps was updated.
1010 public void updateTimeFormat( final TmfTimestampFormatUpdateSignal signal
){
1011 fTimeGraphWrapper
.refresh();
1014 // ------------------------------------------------------------------------
1016 // ------------------------------------------------------------------------
1018 private void loadTrace() {
1019 synchronized (fEntryListMap
) {
1020 fEntryList
= fEntryListMap
.get(fTrace
);
1021 if (fEntryList
== null) {
1024 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1025 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1032 * Forces a rebuild of the entries list, even if entries already exist for this trace
1035 protected void rebuild() {
1036 setStartTime(Long
.MAX_VALUE
);
1037 setEndTime(Long
.MIN_VALUE
);
1038 synchronized (fBuildThreadMap
) {
1039 for (ITmfTrace trace
: getTracesToBuild(fTrace
)) {
1040 BuildThread buildThread
= new BuildThread(trace
, fTrace
, getName());
1041 fBuildThreadMap
.put(trace
, buildThread
);
1042 buildThread
.start();
1048 * Method called when synching to a given timestamp. Inheriting classes can
1049 * perform actions here to update the view at the given timestamp.
1052 * The currently selected time
1054 protected void synchingToTime(long time
) {
1059 * Return the list of traces whose data or analysis results will be used to
1060 * populate the view. By default, if the trace is an experiment, the traces
1061 * under it will be returned, otherwise, the trace itself is returned.
1063 * A build thread will be started for each trace returned by this method,
1064 * some of which may receive events in live streaming mode.
1067 * The trace associated with this view
1068 * @return List of traces with data to display
1071 protected Iterable
<ITmfTrace
> getTracesToBuild(ITmfTrace trace
) {
1072 return Arrays
.asList(TmfTraceManager
.getTraceSet(trace
));
1076 * Build the entries list to show in this time graph
1078 * Called from the BuildThread
1081 * The trace being built
1082 * @param parentTrace
1083 * The parent of the trace set, or the trace itself
1085 * The progress monitor object
1088 protected abstract void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
);
1091 * Gets the list of event for an entry in a given timerange
1094 * The entry to get events for
1096 * Start of the time range
1098 * End of the time range
1102 * The progress monitor object
1103 * @return The list of events for the entry
1105 protected abstract @Nullable List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
1106 long startTime
, long endTime
, long resolution
,
1107 IProgressMonitor monitor
);
1110 * Gets the list of links (displayed as arrows) for a trace in a given
1111 * timerange. Default implementation returns an empty list.
1114 * Start of the time range
1116 * End of the time range
1120 * The progress monitor object
1121 * @return The list of link events
1124 protected List
<ILinkEvent
> getLinkList(long startTime
, long endTime
,
1125 long resolution
, IProgressMonitor monitor
) {
1126 return new ArrayList
<>();
1131 * Refresh the display
1133 protected void refresh() {
1134 TmfUiRefreshHandler
.getInstance().queueUpdate(this, new Runnable() {
1137 if (fTimeGraphWrapper
.isDisposed()) {
1140 boolean hasEntries
= false;
1141 synchronized (fEntryListMap
) {
1142 fEntryList
= fEntryListMap
.get(fTrace
);
1143 if (fEntryList
== null) {
1144 fEntryList
= new CopyOnWriteArrayList
<>();
1145 } else if (fEntryComparator
!= null) {
1146 List
<TimeGraphEntry
> list
= new ArrayList
<>(fEntryList
);
1147 Collections
.sort(list
, fEntryComparator
);
1149 fEntryList
.addAll(list
);
1151 hasEntries
= fEntryList
.size() != 0;
1153 if (fEntryList
!= fTimeGraphWrapper
.getInput()) {
1154 fTimeGraphWrapper
.setInput(fEntryList
);
1156 fTimeGraphWrapper
.refresh();
1158 fTimeGraphWrapper
.getTimeGraphViewer().setTimeBounds(fStartTime
, fEndTime
);
1160 long selectionBeginTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1161 long selectionEndTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1162 long startTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1163 long endTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1164 startTime
= Math
.max(startTime
, fStartTime
);
1165 endTime
= Math
.min(endTime
, fEndTime
);
1166 fTimeGraphWrapper
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
);
1167 fTimeGraphWrapper
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1169 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
&& !fPackDone
) {
1170 for (TreeColumn column
: ((TimeGraphComboWrapper
) fTimeGraphWrapper
).getTreeViewer().getTree().getColumns()) {
1178 startZoomThread(startTime
, endTime
);
1186 protected void redraw() {
1187 synchronized (fSyncObj
) {
1188 if (fRedrawState
== State
.IDLE
) {
1189 fRedrawState
= State
.BUSY
;
1191 fRedrawState
= State
.PENDING
;
1195 Display
.getDefault().asyncExec(new Runnable() {
1198 if (fTimeGraphWrapper
.isDisposed()) {
1201 fTimeGraphWrapper
.redraw();
1202 fTimeGraphWrapper
.update();
1203 synchronized (fSyncObj
) {
1204 if (fRedrawState
== State
.PENDING
) {
1205 fRedrawState
= State
.IDLE
;
1208 fRedrawState
= State
.IDLE
;
1215 private void startZoomThread(long startTime
, long endTime
) {
1216 if (fZoomThread
!= null) {
1217 fZoomThread
.cancel();
1219 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
, getName());
1220 fZoomThread
.start();
1223 private void makeActions() {
1224 fPreviousResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getPreviousItemAction();
1225 fPreviousResourceAction
.setText(getPrevText());
1226 fPreviousResourceAction
.setToolTipText(getPrevTooltip());
1227 fNextResourceAction
= fTimeGraphWrapper
.getTimeGraphViewer().getNextItemAction();
1228 fNextResourceAction
.setText(getNextText());
1229 fNextResourceAction
.setToolTipText(getNextTooltip());
1232 private void contributeToActionBars() {
1233 IActionBars bars
= getViewSite().getActionBars();
1234 fillLocalToolBar(bars
.getToolBarManager());
1238 * Add actions to local tool bar manager
1240 * @param manager the tool bar manager
1242 protected void fillLocalToolBar(IToolBarManager manager
) {
1243 if (fTimeGraphWrapper
instanceof TimeGraphComboWrapper
) {
1244 if (fFilterColumns
!= null && fFilterLabelProvider
!= null && fFilterColumns
.length
> 0) {
1245 manager
.add(((TimeGraphComboWrapper
) fTimeGraphWrapper
).getShowFilterAction());
1248 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getShowLegendAction());
1249 manager
.add(new Separator());
1250 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getResetScaleAction());
1251 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getPreviousEventAction());
1252 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getNextEventAction());
1253 manager
.add(fPreviousResourceAction
);
1254 manager
.add(fNextResourceAction
);
1255 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomInAction());
1256 manager
.add(fTimeGraphWrapper
.getTimeGraphViewer().getZoomOutAction());
1257 manager
.add(new Separator());