1 /*****************************************************************************
2 * Copyright (c) 2007, 2013 Intel Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alexander N. Alexeev, Intel - Add monitors statistics support
12 * Alvaro Sanchez-Leon - Adapted for TMF
13 * Patrick Tasse - Refactoring
14 *****************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.eclipse
.jface
.action
.Action
;
22 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
23 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
37 import org
.eclipse
.swt
.SWT
;
38 import org
.eclipse
.swt
.events
.ControlAdapter
;
39 import org
.eclipse
.swt
.events
.ControlEvent
;
40 import org
.eclipse
.swt
.events
.KeyAdapter
;
41 import org
.eclipse
.swt
.events
.KeyEvent
;
42 import org
.eclipse
.swt
.events
.MenuDetectListener
;
43 import org
.eclipse
.swt
.events
.MouseEvent
;
44 import org
.eclipse
.swt
.events
.MouseWheelListener
;
45 import org
.eclipse
.swt
.events
.SelectionAdapter
;
46 import org
.eclipse
.swt
.events
.SelectionEvent
;
47 import org
.eclipse
.swt
.events
.SelectionListener
;
48 import org
.eclipse
.swt
.graphics
.Rectangle
;
49 import org
.eclipse
.swt
.layout
.FillLayout
;
50 import org
.eclipse
.swt
.layout
.GridData
;
51 import org
.eclipse
.swt
.layout
.GridLayout
;
52 import org
.eclipse
.swt
.widgets
.Composite
;
53 import org
.eclipse
.swt
.widgets
.Control
;
54 import org
.eclipse
.swt
.widgets
.ScrollBar
;
55 import org
.eclipse
.swt
.widgets
.Slider
;
58 * Generic time graph viewer implementation
61 * @author Patrick Tasse, and others
63 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
65 private static final int DEFAULT_NAME_WIDTH
= 200;
66 private static final int MIN_NAME_WIDTH
= 6;
67 private static final int MAX_NAME_WIDTH
= 1000;
68 private static final int DEFAULT_HEIGHT
= 22;
69 private static final long RECENTERING_MARGIN_FACTOR
= 50;
71 private long fMinTimeInterval
;
72 private long fSelectedTime
;
73 private ITimeGraphEntry fSelectedEntry
;
74 private long fBeginTime
;
75 private long fEndTime
;
78 private long fTime0Bound
;
79 private long fTime1Bound
;
80 private long fTime0ExtSynch
= 0;
81 private long fTime1ExtSynch
= 0;
82 private boolean fTimeRangeFixed
;
83 private int fNameWidthPref
= DEFAULT_NAME_WIDTH
;
84 private int fMinNameWidth
= MIN_NAME_WIDTH
;
85 private int fNameWidth
;
86 private Composite fDataViewer
;
88 private TimeGraphControl fTimeGraphCtrl
;
89 private TimeGraphScale fTimeScaleCtrl
;
90 private Slider fVerticalScrollBar
;
91 private TimeGraphColorScheme fColorScheme
;
92 private ITimeGraphPresentationProvider fTimeGraphProvider
;
94 private List
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
95 private List
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
96 private List
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
98 // Time format, using Epoch reference, Relative time format(default) or Number
99 private TimeFormat fTimeFormat
= TimeFormat
.RELATIVE
;
100 private int fBorderWidth
= 0;
101 private int fTimeScaleHeight
= DEFAULT_HEIGHT
;
103 private Action fResetScaleAction
;
104 private Action fShowLegendAction
;
105 private Action fNextEventAction
;
106 private Action fPrevEventAction
;
107 private Action fNextItemAction
;
108 private Action fPreviousItemAction
;
109 private Action fZoomInAction
;
110 private Action fZoomOutAction
;
113 * Standard constructor
116 * The parent UI composite object
120 public TimeGraphViewer(Composite parent
, int style
) {
121 createDataViewer(parent
, style
);
125 * Sets the timegraph provider used by this timegraph viewer.
127 * @param timeGraphProvider the timegraph provider
129 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
130 fTimeGraphProvider
= timeGraphProvider
;
131 fTimeGraphCtrl
.setTimeGraphProvider(timeGraphProvider
);
132 TimeGraphTooltipHandler toolTipHandler
= new TimeGraphTooltipHandler(fTimeGraphProvider
, this);
133 toolTipHandler
.activateHoverHelp(fTimeGraphCtrl
);
137 * Sets or clears the input for this time graph viewer.
138 * The input array should only contain top-level elements.
140 * @param input The input of this time graph viewer, or <code>null</code> if none
142 public void setInput(ITimeGraphEntry
[] input
) {
143 ITimeGraphEntry
[] realInput
= input
;
145 if (fTimeGraphCtrl
!= null) {
146 if (realInput
== null) {
147 realInput
= new ITimeGraphEntry
[0];
149 setTimeRange(realInput
);
150 fVerticalScrollBar
.setEnabled(true);
153 fSelectedEntry
= null;
154 refreshAllData(realInput
);
161 public void refresh() {
162 setTimeRange(fTimeGraphCtrl
.getTraces());
163 fVerticalScrollBar
.setEnabled(true);
164 refreshAllData(fTimeGraphCtrl
.getTraces());
168 * Callback for when the control is moved
173 public void controlMoved(ControlEvent e
) {
177 * Callback for when the control is resized
182 public void controlResized(ControlEvent e
) {
187 * Handler for when the model is updated. Called from the display order in
191 * The traces in the model
196 * @param updateTimeBounds
197 * Should we updated the time bounds too
199 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
200 long end
, boolean updateTimeBounds
) {
201 if (null != fTimeGraphCtrl
) {
202 updateInternalData(traces
, start
, end
);
203 if (updateTimeBounds
) {
204 fTimeRangeFixed
= true;
205 // set window to match limits
206 setStartFinishTime(fTime0Bound
, fTime1Bound
);
208 fTimeGraphCtrl
.redraw();
209 fTimeScaleCtrl
.redraw();
215 * @return The string representing the view type
217 protected String
getViewTypeStr() {
218 return "viewoption.threads"; //$NON-NLS-1$
221 int getMarginWidth() {
225 int getMarginHeight() {
230 fMinTimeInterval
= 1;
232 fNameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
233 fNameWidthPref
, fMinNameWidth
, MAX_NAME_WIDTH
);
237 Utils
.saveIntOption(getPreferenceString("namewidth"), fNameWidth
); //$NON-NLS-1$
241 * Create a data viewer.
247 * @return The new data viewer
249 protected Control
createDataViewer(Composite parent
, int style
) {
251 fColorScheme
= new TimeGraphColorScheme();
252 fDataViewer
= new Composite(parent
, style
) {
254 public void redraw() {
255 fTimeScaleCtrl
.redraw();
256 fTimeGraphCtrl
.redraw();
260 GridLayout gl
= new GridLayout(2, false);
261 gl
.marginHeight
= fBorderWidth
;
263 gl
.verticalSpacing
= 0;
264 gl
.horizontalSpacing
= 0;
265 fDataViewer
.setLayout(gl
);
267 fTimeScaleCtrl
= new TimeGraphScale(fDataViewer
, fColorScheme
);
268 fTimeScaleCtrl
.setTimeProvider(this);
269 fTimeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
270 fTimeScaleCtrl
.setHeight(fTimeScaleHeight
);
272 fVerticalScrollBar
= new Slider(fDataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
273 fVerticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
274 fVerticalScrollBar
.addSelectionListener(new SelectionAdapter() {
276 public void widgetSelected(SelectionEvent e
) {
277 setTopIndex(fVerticalScrollBar
.getSelection());
280 fVerticalScrollBar
.setEnabled(false);
282 fTimeGraphCtrl
= createTimeGraphControl(fDataViewer
, fColorScheme
);
284 fTimeGraphCtrl
.setTimeProvider(this);
285 fTimeGraphCtrl
.addSelectionListener(this);
286 fTimeGraphCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
287 fTimeGraphCtrl
.addMouseWheelListener(new MouseWheelListener() {
289 public void mouseScrolled(MouseEvent e
) {
290 adjustVerticalScrollBar();
293 fTimeGraphCtrl
.addKeyListener(new KeyAdapter() {
295 public void keyPressed(KeyEvent e
) {
296 adjustVerticalScrollBar();
300 Composite filler
= new Composite(fDataViewer
, SWT
.NONE
);
301 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
302 gd
.heightHint
= fTimeGraphCtrl
.getHorizontalBar().getSize().y
;
303 filler
.setLayoutData(gd
);
304 filler
.setLayout(new FillLayout());
306 fTimeGraphCtrl
.addControlListener(new ControlAdapter() {
308 public void controlResized(ControlEvent event
) {
313 fDataViewer
.update();
314 adjustVerticalScrollBar();
321 public void dispose() {
323 fTimeGraphCtrl
.dispose();
324 fDataViewer
.dispose();
325 fColorScheme
.dispose();
329 * Create a new time graph control.
332 * The parent composite
335 * @return The new TimeGraphControl
338 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
339 TimeGraphColorScheme colors
) {
340 return new TimeGraphControl(parent
, colors
);
344 * Resize the controls
346 public void resizeControls() {
347 Rectangle r
= fDataViewer
.getClientArea();
353 if (fNameWidth
> width
- fMinNameWidth
) {
354 fNameWidth
= width
- fMinNameWidth
;
356 if (fNameWidth
< fMinNameWidth
) {
357 fNameWidth
= fMinNameWidth
;
359 adjustVerticalScrollBar();
363 * Try to set most convenient time range for display.
366 * The traces in the model
368 public void setTimeRange(ITimeGraphEntry traces
[]) {
371 for (int i
= 0; i
< traces
.length
; i
++) {
372 ITimeGraphEntry entry
= traces
[i
];
373 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
374 if (fBeginTime
< 0 || entry
.getStartTime() < fBeginTime
) {
375 fBeginTime
= entry
.getStartTime();
377 if (entry
.getEndTime() > fEndTime
) {
378 fEndTime
= entry
.getEndTime();
383 if (fBeginTime
< 0) {
389 * Recalculate the time bounds
391 public void setTimeBounds() {
392 fTime0Bound
= fBeginTime
;
393 if (fTime0Bound
< 0) {
396 fTime1Bound
= fEndTime
;
397 if (!fTimeRangeFixed
) {
398 fTime0
= fTime0Bound
;
399 fTime1
= fTime1Bound
;
401 if (fTime1
- fTime0
< fMinTimeInterval
) {
402 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
411 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
412 ITimeGraphEntry
[] realTraces
= traces
;
414 if (null == realTraces
) {
415 realTraces
= new ITimeGraphEntry
[0];
417 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
418 // Start and end time are unspecified and need to be determined from
419 // individual processes
420 setTimeRange(realTraces
);
426 refreshAllData(realTraces
);
432 private void refreshAllData(ITimeGraphEntry
[] traces
) {
434 if (fSelectedTime
< fBeginTime
) {
435 fSelectedTime
= fBeginTime
;
436 } else if (fSelectedTime
> fEndTime
) {
437 fSelectedTime
= fEndTime
;
439 fTimeGraphCtrl
.refreshData(traces
);
440 fTimeScaleCtrl
.redraw();
441 adjustVerticalScrollBar();
445 * Callback for when this view is focused
447 public void setFocus() {
448 if (null != fTimeGraphCtrl
) {
449 fTimeGraphCtrl
.setFocus();
454 * Get the current focus status of this view.
456 * @return If the view is currently focused, or not
458 public boolean isInFocus() {
459 return fTimeGraphCtrl
.isInFocus();
463 * Get the view's current selection
465 * @return The entry that is selected
467 public ITimeGraphEntry
getSelection() {
468 return fTimeGraphCtrl
.getSelectedTrace();
472 * Get the index of the current selection
476 public int getSelectionIndex() {
477 return fTimeGraphCtrl
.getSelectedIndex();
481 public long getTime0() {
486 public long getTime1() {
491 public long getMinTimeInterval() {
492 return fMinTimeInterval
;
496 public int getNameSpace() {
501 public void setNameSpace(int width
) {
503 int w
= fTimeGraphCtrl
.getClientArea().width
;
504 if (fNameWidth
> w
- MIN_NAME_WIDTH
) {
505 fNameWidth
= w
- MIN_NAME_WIDTH
;
507 if (fNameWidth
< MIN_NAME_WIDTH
) {
508 fNameWidth
= MIN_NAME_WIDTH
;
510 fTimeGraphCtrl
.adjustScrolls();
511 fTimeGraphCtrl
.redraw();
512 fTimeScaleCtrl
.redraw();
516 public int getTimeSpace() {
517 int w
= fTimeGraphCtrl
.getClientArea().width
;
518 return w
- fNameWidth
;
522 public long getSelectedTime() {
523 return fSelectedTime
;
527 public long getBeginTime() {
532 public long getEndTime() {
537 public long getMaxTime() {
542 public long getMinTime() {
547 public void setStartFinishTimeNotify(long time0
, long time1
) {
548 setStartFinishTime(time0
, time1
);
549 notifyRangeListeners(time0
, time1
);
553 public void notifyStartFinishTime() {
554 notifyRangeListeners(fTime0
, fTime1
);
558 public void setStartFinishTime(long time0
, long time1
) {
560 if (fTime0
< fTime0Bound
) {
561 fTime0
= fTime0Bound
;
563 if (fTime0
> fTime1Bound
) {
564 fTime0
= fTime1Bound
;
567 if (fTime1
< fTime0Bound
) {
568 fTime1
= fTime0Bound
;
570 if (fTime1
> fTime1Bound
) {
571 fTime1
= fTime1Bound
;
573 if (fTime1
- fTime0
< fMinTimeInterval
) {
574 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
576 fTimeRangeFixed
= true;
577 fTimeGraphCtrl
.adjustScrolls();
578 fTimeGraphCtrl
.redraw();
579 fTimeScaleCtrl
.redraw();
583 * Set the time bounds to the provided values
586 * The start time of the window
590 public void setTimeBounds(long beginTime
, long endTime
) {
591 fBeginTime
= beginTime
;
593 fTime0Bound
= beginTime
;
594 fTime1Bound
= endTime
;
595 fTimeGraphCtrl
.adjustScrolls();
599 public void resetStartFinishTime() {
600 setStartFinishTime(fTime0Bound
, fTime1Bound
);
601 fTimeRangeFixed
= false;
605 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
606 setSelectedTimeInt(time
, ensureVisible
, true);
610 public void setSelectedTime(long time
, boolean ensureVisible
) {
611 setSelectedTimeInt(time
, ensureVisible
, false);
614 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
618 long timeSpace
= (fTime1
- fTime0
) / RECENTERING_MARGIN_FACTOR
;
619 long timeMid
= (fTime1
- fTime0
) / 2;
620 if (time
< fTime0
+ timeSpace
) {
621 long dt
= fTime0
- time
+ timeMid
;
624 } else if (time
> fTime1
- timeSpace
) {
625 long dt
= time
- fTime1
+ timeMid
;
629 if (fTime0
< fTime0Bound
) {
630 fTime1
= Math
.min(fTime1Bound
, fTime1
+ (fTime0Bound
- fTime0
));
631 fTime0
= fTime0Bound
;
632 } else if (fTime1
> fTime1Bound
) {
633 fTime0
= Math
.max(fTime0Bound
, fTime0
- (fTime1
- fTime1Bound
));
634 fTime1
= fTime1Bound
;
637 if (fTime1
- fTime0
< fMinTimeInterval
) {
638 fTime1
= Math
.min(fTime1Bound
, fTime0
+ fMinTimeInterval
);
640 fTimeGraphCtrl
.adjustScrolls();
641 fTimeGraphCtrl
.redraw();
642 fTimeScaleCtrl
.redraw();
645 boolean notifySelectedTime
= (time
!= fSelectedTime
);
646 fSelectedTime
= time
;
648 if (doNotify
&& ((time0
!= fTime0
) || (time1
!= fTime1
))) {
649 notifyRangeListeners(fTime0
, fTime1
);
652 if (doNotify
&& notifySelectedTime
) {
653 notifyTimeListeners(fSelectedTime
);
658 public void widgetDefaultSelected(SelectionEvent e
) {
659 if (fSelectedEntry
!= getSelection()) {
660 fSelectedEntry
= getSelection();
661 notifySelectionListeners(fSelectedEntry
);
666 public void widgetSelected(SelectionEvent e
) {
667 if (fSelectedEntry
!= getSelection()) {
668 fSelectedEntry
= getSelection();
669 notifySelectionListeners(fSelectedEntry
);
674 * Callback for when the next event is selected
676 public void selectNextEvent() {
677 fTimeGraphCtrl
.selectNextEvent();
678 adjustVerticalScrollBar();
682 * Callback for when the previous event is selected
684 public void selectPrevEvent() {
685 fTimeGraphCtrl
.selectPrevEvent();
686 adjustVerticalScrollBar();
690 * Callback for when the next item is selected
692 public void selectNextItem() {
693 fTimeGraphCtrl
.selectNextTrace();
694 adjustVerticalScrollBar();
698 * Callback for when the previous item is selected
700 public void selectPrevItem() {
701 fTimeGraphCtrl
.selectPrevTrace();
702 adjustVerticalScrollBar();
706 * Callback for the show legend action
708 public void showLegend() {
709 if (fDataViewer
== null || fDataViewer
.isDisposed()) {
713 TimeGraphLegend
.open(fDataViewer
.getShell(), fTimeGraphProvider
);
717 * Callback for the Zoom In action
719 public void zoomIn() {
720 fTimeGraphCtrl
.zoomIn();
724 * Callback for the Zoom Out action
726 public void zoomOut() {
727 fTimeGraphCtrl
.zoomOut();
730 private String
getPreferenceString(String string
) {
731 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
735 * Add a selection listener
738 * The listener to add
740 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
741 fSelectionListeners
.add(listener
);
745 * Remove a selection listener
748 * The listener to remove
750 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
751 fSelectionListeners
.remove(listener
);
754 private void notifySelectionListeners(ITimeGraphEntry selection
) {
755 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
757 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
758 listener
.selectionChanged(event
);
763 * Add a time listener
766 * The listener to add
768 public void addTimeListener(ITimeGraphTimeListener listener
) {
769 fTimeListeners
.add(listener
);
773 * Remove a time listener
776 * The listener to remove
778 public void removeTimeListener(ITimeGraphTimeListener listener
) {
779 fTimeListeners
.remove(listener
);
782 private void notifyTimeListeners(long time
) {
783 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
785 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
786 listener
.timeSelected(event
);
791 * Add a range listener
794 * The listener to add
796 public void addRangeListener(ITimeGraphRangeListener listener
) {
797 fRangeListeners
.add(listener
);
801 * Remove a range listener
804 * The listener to remove
806 public void removeRangeListener(ITimeGraphRangeListener listener
) {
807 fRangeListeners
.remove(listener
);
810 private void notifyRangeListeners(long startTime
, long endTime
) {
811 // Check if the time has actually changed from last notification
812 if (startTime
!= fTime0ExtSynch
|| endTime
!= fTime1ExtSynch
) {
813 // Notify Time Scale Selection Listeners
814 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
816 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
817 listener
.timeRangeUpdated(event
);
820 // update external synch timers
821 updateExtSynchTimers();
826 * Callback to set a selected event in the view
829 * The event that was selected
831 * The source of this selection event
833 public void setSelectedEvent(ITimeEvent event
, Object source
) {
834 if (event
== null || source
== this) {
837 fSelectedEntry
= event
.getEntry();
838 fTimeGraphCtrl
.selectItem(fSelectedEntry
, false);
840 setSelectedTimeInt(event
.getTime(), true, true);
841 adjustVerticalScrollBar();
845 * Set the seeked time of a trace
848 * The trace that was seeked
852 * The source of this seek event
854 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
855 if (trace
== null || source
== this) {
858 fSelectedEntry
= trace
;
859 fTimeGraphCtrl
.selectItem(trace
, false);
861 setSelectedTimeInt(time
, true, true);
865 * Callback for a trace selection
868 * The trace that was selected
870 public void setSelection(ITimeGraphEntry trace
) {
871 fSelectedEntry
= trace
;
872 fTimeGraphCtrl
.selectItem(trace
, false);
873 adjustVerticalScrollBar();
877 * Callback for a time window selection
880 * Start time of the range
882 * End time of the range
884 * Source of the event
886 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
887 if (source
== this) {
891 setStartFinishTime(time0
, time1
);
893 // update notification time values since we are now in synch with the
894 // external application
895 updateExtSynchTimers();
899 * update the cache timers used to identify the need to send a time window
900 * update to external registered listeners
902 private void updateExtSynchTimers() {
903 // last time notification cache
904 fTime0ExtSynch
= fTime0
;
905 fTime1ExtSynch
= fTime1
;
912 public TimeFormat
getTimeFormat() {
917 * @param tf the {@link TimeFormat} used to display timestamps
920 public void setTimeFormat(TimeFormat tf
) {
921 this.fTimeFormat
= tf
;
925 * Retrieve the border width
929 public int getBorderWidth() {
934 * Set the border width
939 public void setBorderWidth(int borderWidth
) {
940 if (borderWidth
> -1) {
941 this.fBorderWidth
= borderWidth
;
942 GridLayout gl
= (GridLayout
)fDataViewer
.getLayout();
943 gl
.marginHeight
= borderWidth
;
948 * Retrieve the height of the header
952 public int getHeaderHeight() {
953 return fTimeScaleHeight
;
957 * Set the height of the header
959 * @param headerHeight
962 public void setHeaderHeight(int headerHeight
) {
963 if (headerHeight
> -1) {
964 this.fTimeScaleHeight
= headerHeight
;
965 fTimeScaleCtrl
.setHeight(headerHeight
);
970 * Retrieve the height of an item row
974 public int getItemHeight() {
975 if (fTimeGraphCtrl
!= null) {
976 return fTimeGraphCtrl
.getItemHeight();
982 * Set the height of an item row
987 public void setItemHeight(int rowHeight
) {
988 if (fTimeGraphCtrl
!= null) {
989 fTimeGraphCtrl
.setItemHeight(rowHeight
);
994 * Set the minimum item width
999 public void setMinimumItemWidth(int width
) {
1000 if (fTimeGraphCtrl
!= null) {
1001 fTimeGraphCtrl
.setMinimumItemWidth(width
);
1006 * Set the width for the name column
1008 * @param width The width
1010 public void setNameWidthPref(int width
) {
1011 fNameWidthPref
= width
;
1019 * Retrieve the configure width for the name column
1025 public int getNameWidthPref(int width
) {
1026 return fNameWidthPref
;
1030 * Returns the primary control associated with this viewer.
1032 * @return the SWT control which displays this viewer's content
1034 public Control
getControl() {
1039 * Returns the time graph control associated with this viewer.
1041 * @return the time graph control
1044 public TimeGraphControl
getTimeGraphControl() {
1045 return fTimeGraphCtrl
;
1049 * Returns the time graph scale associated with this viewer.
1051 * @return the time graph scale
1054 public TimeGraphScale
getTimeGraphScale() {
1055 return fTimeScaleCtrl
;
1059 * Return the x coordinate corresponding to a time
1061 * @param time the time
1062 * @return the x coordinate corresponding to the time
1066 public int getXForTime(long time
) {
1067 return fTimeGraphCtrl
.getXForTime(time
);
1071 * Return the time corresponding to an x coordinate
1073 * @param x the x coordinate
1074 * @return the time corresponding to the x coordinate
1078 public long getTimeAtX(int x
) {
1079 return fTimeGraphCtrl
.getTimeAtX(x
);
1083 * Get the selection provider
1085 * @return the selection provider
1087 public ISelectionProvider
getSelectionProvider() {
1088 return fTimeGraphCtrl
;
1092 * Wait for the cursor
1095 * Wait indefinitely?
1097 public void waitCursor(boolean waitInd
) {
1098 fTimeGraphCtrl
.waitCursor(waitInd
);
1102 * Get the horizontal scroll bar object
1104 * @return The scroll bar
1106 public ScrollBar
getHorizontalBar() {
1107 return fTimeGraphCtrl
.getHorizontalBar();
1111 * Get the vertical scroll bar object
1113 * @return The scroll bar
1115 public Slider
getVerticalBar() {
1116 return fVerticalScrollBar
;
1120 * Set the given index as the top one
1123 * The index that will go to the top
1125 public void setTopIndex(int index
) {
1126 fTimeGraphCtrl
.setTopIndex(index
);
1127 adjustVerticalScrollBar();
1131 * Retrieve the current top index
1133 * @return The top index
1135 public int getTopIndex() {
1136 return fTimeGraphCtrl
.getTopIndex();
1140 * Set the expanded state of an entry
1143 * The entry to expand/collapse
1145 * True for expanded, false for collapsed
1147 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1148 fTimeGraphCtrl
.setExpandedState(entry
, expanded
);
1149 adjustVerticalScrollBar();
1153 * Collapses all nodes of the viewer's tree, starting with the root.
1157 public void collapseAll() {
1158 fTimeGraphCtrl
.collapseAll();
1159 adjustVerticalScrollBar();
1163 * Expands all nodes of the viewer's tree, starting with the root.
1167 public void expandAll() {
1168 fTimeGraphCtrl
.expandAll();
1169 adjustVerticalScrollBar();
1173 * Get the number of sub-elements when expanded
1175 * @return The element count
1177 public int getExpandedElementCount() {
1178 return fTimeGraphCtrl
.getExpandedElementCount();
1182 * Get the sub-elements
1184 * @return The array of entries that are below this one
1186 public ITimeGraphEntry
[] getExpandedElements() {
1187 return fTimeGraphCtrl
.getExpandedElements();
1191 * Add a tree listener
1194 * The listener to add
1196 public void addTreeListener(ITimeGraphTreeListener listener
) {
1197 fTimeGraphCtrl
.addTreeListener(listener
);
1201 * Remove a tree listener
1204 * The listener to remove
1206 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1207 fTimeGraphCtrl
.removeTreeListener(listener
);
1211 * Get the reset scale action.
1213 * @return The Action object
1215 public Action
getResetScaleAction() {
1216 if (fResetScaleAction
== null) {
1218 fResetScaleAction
= new Action() {
1221 resetStartFinishTime();
1222 notifyStartFinishTime();
1225 fResetScaleAction
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1226 fResetScaleAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1227 fResetScaleAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1229 return fResetScaleAction
;
1233 * Get the show legend action.
1235 * @return The Action object
1237 public Action
getShowLegendAction() {
1238 if (fShowLegendAction
== null) {
1240 fShowLegendAction
= new Action() {
1246 fShowLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1247 fShowLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1248 fShowLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1251 return fShowLegendAction
;
1255 * Get the the next event action.
1257 * @return The action object
1259 public Action
getNextEventAction() {
1260 if (fNextEventAction
== null) {
1261 fNextEventAction
= new Action() {
1268 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1269 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1270 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1273 return fNextEventAction
;
1277 * Get the previous event action.
1279 * @return The Action object
1281 public Action
getPreviousEventAction() {
1282 if (fPrevEventAction
== null) {
1283 fPrevEventAction
= new Action() {
1290 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1291 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1292 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1295 return fPrevEventAction
;
1299 * Get the next item action.
1301 * @return The Action object
1303 public Action
getNextItemAction() {
1304 if (fNextItemAction
== null) {
1306 fNextItemAction
= new Action() {
1312 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1313 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1314 fNextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1316 return fNextItemAction
;
1320 * Get the previous item action.
1322 * @return The Action object
1324 public Action
getPreviousItemAction() {
1325 if (fPreviousItemAction
== null) {
1327 fPreviousItemAction
= new Action() {
1333 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1334 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1335 fPreviousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1337 return fPreviousItemAction
;
1341 * Get the zoom in action
1343 * @return The Action object
1345 public Action
getZoomInAction() {
1346 if (fZoomInAction
== null) {
1347 fZoomInAction
= new Action() {
1353 fZoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1354 fZoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1355 fZoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1357 return fZoomInAction
;
1361 * Get the zoom out action
1363 * @return The Action object
1365 public Action
getZoomOutAction() {
1366 if (fZoomOutAction
== null) {
1367 fZoomOutAction
= new Action() {
1373 fZoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1374 fZoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1375 fZoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1377 return fZoomOutAction
;
1381 private void adjustVerticalScrollBar() {
1382 int topIndex
= fTimeGraphCtrl
.getTopIndex();
1383 int countPerPage
= fTimeGraphCtrl
.countPerPage();
1384 int expandedElementCount
= fTimeGraphCtrl
.getExpandedElementCount();
1385 if (topIndex
+ countPerPage
> expandedElementCount
) {
1386 fTimeGraphCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1389 int selection
= fTimeGraphCtrl
.getTopIndex();
1391 int max
= Math
.max(1, expandedElementCount
- 1);
1392 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1394 int pageIncrement
= Math
.max(1, countPerPage
);
1395 fVerticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1399 * @param listener a {@link MenuDetectListener}
1400 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1403 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1404 fTimeGraphCtrl
.addTimeGraphEntryMenuListener(listener
);
1408 * @param listener a {@link MenuDetectListener}
1409 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1412 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1413 fTimeGraphCtrl
.removeTimeGraphEntryMenuListener(listener
);
1417 * @param listener a {@link MenuDetectListener}
1418 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1421 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1422 fTimeGraphCtrl
.addTimeEventMenuListener(listener
);
1426 * @param listener a {@link MenuDetectListener}
1427 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1430 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1431 fTimeGraphCtrl
.removeTimeEventMenuListener(listener
);
1435 * @param filter The filter object to be attached to the view
1438 public void addFilter(ViewerFilter filter
) {
1439 fTimeGraphCtrl
.addFilter(filter
);
1444 * @param filter The filter object to be attached to the view
1447 public void removeFilter(ViewerFilter filter
) {
1448 fTimeGraphCtrl
.removeFilter(filter
);