1 /*****************************************************************************
2 * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 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
15 *****************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
;
19 import java
.util
.ArrayList
;
21 import org
.eclipse
.jface
.action
.Action
;
22 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.dialogs
.TimeGraphLegend
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.ITimeDataProvider
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphColorScheme
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphScale
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphTooltipHandler
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.events
.ControlAdapter
;
37 import org
.eclipse
.swt
.events
.ControlEvent
;
38 import org
.eclipse
.swt
.events
.KeyAdapter
;
39 import org
.eclipse
.swt
.events
.KeyEvent
;
40 import org
.eclipse
.swt
.events
.MenuDetectListener
;
41 import org
.eclipse
.swt
.events
.MouseEvent
;
42 import org
.eclipse
.swt
.events
.MouseWheelListener
;
43 import org
.eclipse
.swt
.events
.SelectionAdapter
;
44 import org
.eclipse
.swt
.events
.SelectionEvent
;
45 import org
.eclipse
.swt
.events
.SelectionListener
;
46 import org
.eclipse
.swt
.graphics
.Rectangle
;
47 import org
.eclipse
.swt
.layout
.FillLayout
;
48 import org
.eclipse
.swt
.layout
.GridData
;
49 import org
.eclipse
.swt
.layout
.GridLayout
;
50 import org
.eclipse
.swt
.widgets
.Composite
;
51 import org
.eclipse
.swt
.widgets
.Control
;
52 import org
.eclipse
.swt
.widgets
.ScrollBar
;
53 import org
.eclipse
.swt
.widgets
.Slider
;
56 * Generic time graph viewer implementation
59 * @author Patrick Tasse, and others
61 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
64 private long _minTimeInterval
;
65 private long _selectedTime
;
66 private ITimeGraphEntry _selectedEntry
;
67 private long _beginTime
;
68 private long _endTime
;
73 private long _time0_extSynch
= 0;
74 private long _time1_extSynch
= 0;
75 private boolean _timeRangeFixed
;
76 private int _nameWidthPref
= 200;
77 private int _minNameWidth
= 6;
78 private int _nameWidth
;
79 private Composite _dataViewer
;
81 private TimeGraphControl _stateCtrl
;
82 private TimeGraphScale _timeScaleCtrl
;
83 private Slider _verticalScrollBar
;
84 private TimeGraphTooltipHandler _threadTip
;
85 private TimeGraphColorScheme _colors
;
86 private ITimeGraphPresentationProvider fTimeGraphProvider
;
88 ArrayList
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
89 ArrayList
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
90 ArrayList
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
92 // Calender Time format, using Epoch reference or Relative time
94 private boolean calendarTimeFormat
= false;
95 private int borderWidth
= 0;
96 private int timeScaleHeight
= 22;
98 private Action resetScale
;
99 private Action showLegendAction
;
100 private Action nextEventAction
;
101 private Action prevEventAction
;
102 private Action nextItemAction
;
103 private Action previousItemAction
;
104 private Action zoomInAction
;
105 private Action zoomOutAction
;
108 * Standard constructor
111 * The parent UI composite object
115 public TimeGraphViewer(Composite parent
, int style
) {
116 createDataViewer(parent
, style
);
120 * Sets the timegraph provider used by this timegraph viewer.
122 * @param timeGraphProvider the timegraph provider
124 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
125 fTimeGraphProvider
= timeGraphProvider
;
126 _stateCtrl
.setTimeGraphProvider(timeGraphProvider
);
127 _threadTip
= new TimeGraphTooltipHandler(_dataViewer
.getShell(), fTimeGraphProvider
, this);
128 _threadTip
.activateHoverHelp(_stateCtrl
);
132 * Sets or clears the input for this time graph viewer.
133 * The input array should only contain top-level elements.
135 * @param input the input of this time graph viewer, or <code>null</code> if none
137 public void setInput(ITimeGraphEntry
[] input
) {
138 if (null != _stateCtrl
) {
140 input
= new ITimeGraphEntry
[0];
143 _verticalScrollBar
.setEnabled(true);
146 _selectedEntry
= null;
147 refreshAllData(input
);
154 public void refresh() {
155 setInput(_stateCtrl
.getTraces());
159 * Callback for when the control is moved
164 public void controlMoved(ControlEvent e
) {
168 * Callback for when the control is resized
173 public void controlResized(ControlEvent e
) {
178 * Handler for when the model is updated. Called from the display order in
182 * The traces in the model
187 * @param updateTimeBounds
188 * Should we updated the time bounds too
190 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
191 long end
, boolean updateTimeBounds
) {
192 if (null != _stateCtrl
) {
194 updateInternalData(traces
, start
, end
);
195 if (updateTimeBounds
) {
196 _timeRangeFixed
= true;
197 // set window to match limits
198 setStartFinishTime(_time0_
, _time1_
);
201 _timeScaleCtrl
.redraw();
206 protected String
getViewTypeStr() {
207 return "viewoption.threads"; //$NON-NLS-1$
210 int getMarginWidth(int idx
) {
214 int getMarginHeight(int idx
) {
219 _minTimeInterval
= 1;
221 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
222 _nameWidthPref
, _minNameWidth
, 1000);
226 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
229 protected Control
createDataViewer(Composite parent
, int style
) {
231 _colors
= new TimeGraphColorScheme();
232 _dataViewer
= new Composite(parent
, style
) {
234 public void redraw() {
235 _timeScaleCtrl
.redraw();
240 GridLayout gl
= new GridLayout(2, false);
241 gl
.marginHeight
= borderWidth
;
243 gl
.verticalSpacing
= 0;
244 gl
.horizontalSpacing
= 0;
245 _dataViewer
.setLayout(gl
);
247 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
248 _timeScaleCtrl
.setTimeProvider(this);
249 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
250 _timeScaleCtrl
.setHeight(timeScaleHeight
);
252 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
253 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
254 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
256 public void widgetSelected(SelectionEvent e
) {
257 setTopIndex(_verticalScrollBar
.getSelection());
260 _verticalScrollBar
.setEnabled(false);
262 _stateCtrl
= createTimeGraphControl(_dataViewer
, _colors
);
264 _stateCtrl
.setTimeProvider(this);
265 _stateCtrl
.addSelectionListener(this);
266 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
267 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
269 public void mouseScrolled(MouseEvent e
) {
270 adjustVerticalScrollBar();
273 _stateCtrl
.addKeyListener(new KeyAdapter() {
275 public void keyPressed(KeyEvent e
) {
276 adjustVerticalScrollBar();
280 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
281 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
282 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
283 filler
.setLayoutData(gd
);
284 filler
.setLayout(new FillLayout());
286 _stateCtrl
.addControlListener(new ControlAdapter() {
288 public void controlResized(ControlEvent event
) {
293 _dataViewer
.update();
294 adjustVerticalScrollBar();
301 public void dispose() {
303 _stateCtrl
.dispose();
304 _dataViewer
.dispose();
311 protected TimeGraphControl
createTimeGraphControl(Composite parent
, TimeGraphColorScheme colors
) {
312 return new TimeGraphControl(parent
, colors
);
316 * Resize the controls
318 public void resizeControls() {
319 Rectangle r
= _dataViewer
.getClientArea();
325 if (_nameWidth
> width
- _minNameWidth
) {
326 _nameWidth
= width
- _minNameWidth
;
328 if (_nameWidth
< _minNameWidth
) {
329 _nameWidth
= _minNameWidth
;
331 adjustVerticalScrollBar();
335 * Try to set most convenient time range for display.
338 * The traces in the model
340 public void setTimeRange(ITimeGraphEntry traces
[]) {
343 for (int i
= 0; i
< traces
.length
; i
++) {
344 ITimeGraphEntry entry
= traces
[i
];
345 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
346 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
347 _beginTime
= entry
.getStartTime();
349 if (entry
.getEndTime() > _endTime
) {
350 _endTime
= entry
.getEndTime();
355 if (_beginTime
< 0) {
361 * Recalculate the time bounds
363 public void setTimeBounds() {
364 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
365 _time0_
= _beginTime
;
369 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
371 // _time0_ = Math.floor(_time0_);
372 // _time1_ = Math.ceil(_time1_);
373 if (!_timeRangeFixed
) {
377 if (_time1
- _time0
< _minTimeInterval
) {
378 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
387 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
388 if (null == traces
) {
389 traces
= new ITimeGraphEntry
[0];
391 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
392 // Start and end time are unspecified and need to be determined from
393 // individual processes
394 setTimeRange(traces
);
400 refreshAllData(traces
);
406 private void refreshAllData(ITimeGraphEntry
[] traces
) {
408 if (_selectedTime
< _beginTime
) {
409 _selectedTime
= _beginTime
;
410 } else if (_selectedTime
> _endTime
) {
411 _selectedTime
= _endTime
;
413 _stateCtrl
.refreshData(traces
);
414 _timeScaleCtrl
.redraw();
415 adjustVerticalScrollBar();
419 * Callback for when this view is focused
421 public void setFocus() {
422 if (null != _stateCtrl
) {
423 _stateCtrl
.setFocus();
428 * Get the current focus status of this view.
430 * @return If the view is currently focused, or not
432 public boolean isInFocus() {
433 return _stateCtrl
.isInFocus();
437 * Get the view's current selection
439 * @return The entry that is selected
441 public ITimeGraphEntry
getSelection() {
442 return _stateCtrl
.getSelectedTrace();
446 * Get the index of the current selection
450 public int getSelectionIndex() {
451 return _stateCtrl
.getSelectedIndex();
455 public long getTime0() {
460 public long getTime1() {
465 public long getMinTimeInterval() {
466 return _minTimeInterval
;
470 public int getNameSpace() {
475 public void setNameSpace(int width
) {
477 width
= _stateCtrl
.getClientArea().width
;
478 if (_nameWidth
> width
- 6) {
479 _nameWidth
= width
- 6;
481 if (_nameWidth
< 6) {
484 _stateCtrl
.adjustScrolls();
486 _timeScaleCtrl
.redraw();
490 public int getTimeSpace() {
491 int w
= _stateCtrl
.getClientArea().width
;
492 return w
- _nameWidth
;
496 public long getSelectedTime() {
497 return _selectedTime
;
501 public long getBeginTime() {
506 public long getEndTime() {
511 public long getMaxTime() {
516 public long getMinTime() {
524 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
525 * #setStartFinishTimeNotify(long, long)
528 public void setStartFinishTimeNotify(long time0
, long time1
) {
529 setStartFinishTime(time0
, time1
);
530 notifyRangeListeners(time0
, time1
);
535 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
538 public void notifyStartFinishTime() {
539 notifyRangeListeners(_time0
, _time1
);
546 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
547 * #setStartFinishTime(long, long)
550 public void setStartFinishTime(long time0
, long time1
) {
552 if (_time0
< _time0_
) {
555 if (_time0
> _time1_
) {
559 if (_time1
< _time0_
) {
562 if (_time1
> _time1_
) {
565 if (_time1
- _time0
< _minTimeInterval
) {
566 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
568 _timeRangeFixed
= true;
569 _stateCtrl
.adjustScrolls();
571 _timeScaleCtrl
.redraw();
575 * Set the time bounds to the provided values
578 * The start time of the window
582 public void setTimeBounds(long beginTime
, long endTime
) {
583 _beginTime
= beginTime
;
587 _stateCtrl
.adjustScrolls();
591 public void resetStartFinishTime() {
592 setStartFinishTime(_time0_
, _time1_
);
593 _timeRangeFixed
= false;
597 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
598 setSelectedTimeInt(time
, ensureVisible
, true);
602 public void setSelectedTime(long time
, boolean ensureVisible
) {
603 setSelectedTimeInt(time
, ensureVisible
, false);
606 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
610 long timeSpace
= (long) ((_time1
- _time0
) * .02);
611 long timeMid
= (long) ((_time1
- _time0
) * .5);
612 if (time
< _time0
+ timeSpace
) {
613 long dt
= _time0
- time
+ timeMid
;
616 } else if (time
> _time1
- timeSpace
) {
617 long dt
= time
- _time1
+ timeMid
;
621 if (_time0
< _time0_
) {
622 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
624 } else if (_time1
> _time1_
) {
625 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
629 if (_time1
- _time0
< _minTimeInterval
) {
630 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
632 _stateCtrl
.adjustScrolls();
634 _timeScaleCtrl
.redraw();
637 boolean notifySelectedTime
= (time
!= _selectedTime
);
638 _selectedTime
= time
;
640 if (doNotify
&& ((time0
!= _time0
) || (time1
!= _time1
))) {
641 notifyRangeListeners(_time0
, _time1
);
644 if (doNotify
&& notifySelectedTime
) {
645 notifyTimeListeners(_selectedTime
);
650 public void widgetDefaultSelected(SelectionEvent e
) {
651 if (_selectedEntry
!= getSelection()) {
652 _selectedEntry
= getSelection();
653 notifySelectionListeners(_selectedEntry
);
658 public void widgetSelected(SelectionEvent e
) {
659 if (_selectedEntry
!= getSelection()) {
660 _selectedEntry
= getSelection();
661 notifySelectionListeners(_selectedEntry
);
666 * Callback for when the next event is selected
668 public void selectNextEvent() {
669 _stateCtrl
.selectNextEvent();
670 adjustVerticalScrollBar();
674 * Callback for when the previous event is selected
676 public void selectPrevEvent() {
677 _stateCtrl
.selectPrevEvent();
678 adjustVerticalScrollBar();
682 * Callback for when the next item is selected
684 public void selectNextItem() {
685 _stateCtrl
.selectNextTrace();
686 adjustVerticalScrollBar();
690 * Callback for when the previous item is selected
692 public void selectPrevItem() {
693 _stateCtrl
.selectPrevTrace();
694 adjustVerticalScrollBar();
698 * Callback for the show legend action
700 public void showLegend() {
701 if (_dataViewer
== null || _dataViewer
.isDisposed()) {
705 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
709 * Callback for the Zoom In action
711 public void zoomIn() {
716 * Callback for the Zoom Out action
718 public void zoomOut() {
719 _stateCtrl
.zoomOut();
722 private String
getPreferenceString(String string
) {
723 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
727 * Add a selection listener
730 * The listener to add
732 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
733 fSelectionListeners
.add(listener
);
737 * Remove a selection listener
740 * The listener to remove
742 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
743 fSelectionListeners
.remove(listener
);
746 private void notifySelectionListeners(ITimeGraphEntry selection
) {
747 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
749 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
750 listener
.selectionChanged(event
);
755 * Add a time listener
758 * The listener to add
760 public void addTimeListener(ITimeGraphTimeListener listener
) {
761 fTimeListeners
.add(listener
);
765 * Remove a time listener
768 * The listener to remove
770 public void removeTimeListener(ITimeGraphTimeListener listener
) {
771 fTimeListeners
.remove(listener
);
774 private void notifyTimeListeners(long time
) {
775 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
777 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
778 listener
.timeSelected(event
);
783 * Add a range listener
786 * The listener to add
788 public void addRangeListener(ITimeGraphRangeListener listener
) {
789 fRangeListeners
.add(listener
);
793 * Remove a range listener
796 * The listener to remove
798 public void removeRangeListener(ITimeGraphRangeListener listener
) {
799 fRangeListeners
.remove(listener
);
802 private void notifyRangeListeners(long startTime
, long endTime
) {
803 // Check if the time has actually changed from last notification
804 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
805 // Notify Time Scale Selection Listeners
806 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
808 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
809 listener
.timeRangeUpdated(event
);
812 // update external synch timers
813 updateExtSynchTimers();
818 * Callback to set a selected event in the view
821 * The event that was selected
823 * The source of this selection event
825 public void setSelectedEvent(ITimeEvent event
, Object source
) {
826 if (event
== null || source
== this) {
829 _selectedEntry
= event
.getEntry();
830 _stateCtrl
.selectItem(_selectedEntry
, false);
832 setSelectedTimeInt(event
.getTime(), true, true);
833 adjustVerticalScrollBar();
837 * Set the seeked time of a trace
840 * The trace that was seeked
844 * The source of this seek event
846 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
847 if (trace
== null || source
== this) {
850 _selectedEntry
= trace
;
851 _stateCtrl
.selectItem(trace
, false);
853 setSelectedTimeInt(time
, true, true);
857 * Callback for a trace selection
860 * The trace that was selected
862 public void setSelection(ITimeGraphEntry trace
) {
863 _selectedEntry
= trace
;
864 _stateCtrl
.selectItem(trace
, false);
865 adjustVerticalScrollBar();
869 * Callback for a time window selection
872 * Start time of the range
874 * End time of the range
876 * Source of the event
878 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
879 if (source
== this) {
883 setStartFinishTime(time0
, time1
);
885 // update notification time values since we are now in synch with the
886 // external application
887 updateExtSynchTimers();
891 * update the cache timers used to identify the need to send a time window
892 * update to external registered listeners
894 private void updateExtSynchTimers() {
895 // last time notification cache
896 _time0_extSynch
= _time0
;
897 _time1_extSynch
= _time1
;
901 * Set the calendar format
903 * @param toAbsoluteCaltime
904 * True for absolute time, false for relative
906 public void setTimeCalendarFormat(boolean toAbsoluteCaltime
) {
907 calendarTimeFormat
= toAbsoluteCaltime
;
911 public boolean isCalendarFormat() {
912 return calendarTimeFormat
;
916 * Retrieve the border width
920 public int getBorderWidth() {
925 * Set the border width
930 public void setBorderWidth(int borderWidth
) {
931 if (borderWidth
> -1) {
932 this.borderWidth
= borderWidth
;
933 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
934 gl
.marginHeight
= borderWidth
;
939 * Retrieve the height of the header
943 public int getHeaderHeight() {
944 return timeScaleHeight
;
948 * Set the height of the header
950 * @param headerHeight
953 public void setHeaderHeight(int headerHeight
) {
954 if (headerHeight
> -1) {
955 this.timeScaleHeight
= headerHeight
;
956 _timeScaleCtrl
.setHeight(headerHeight
);
961 * Retrieve the height of an item row
965 public int getItemHeight() {
966 if (_stateCtrl
!= null) {
967 return _stateCtrl
.getItemHeight();
973 * Set the height of an item row
978 public void setItemHeight(int rowHeight
) {
979 if (_stateCtrl
!= null) {
980 _stateCtrl
.setItemHeight(rowHeight
);
985 * Set the minimum item width
990 public void setMinimumItemWidth(int width
) {
991 if (_stateCtrl
!= null) {
992 _stateCtrl
.setMinimumItemWidth(width
);
997 * Set the width for the name column
999 * @param width The width
1001 public void setNameWidthPref(int width
) {
1002 _nameWidthPref
= width
;
1010 * Retrieve the configure width for the name column
1016 public int getNameWidthPref(int width
) {
1017 return _nameWidthPref
;
1021 * Returns the primary control associated with this viewer.
1023 * @return the SWT control which displays this viewer's content
1025 public Control
getControl() {
1030 * Returns the time graph control associated with this viewer.
1032 * @return the time graph control
1034 TimeGraphControl
getTimeGraphControl() {
1039 * Returns the time graph scale associated with this viewer.
1041 * @return the time graph scale
1043 TimeGraphScale
getTimeGraphScale() {
1044 return _timeScaleCtrl
;
1048 * Return the x coordinate corresponding to a time
1050 * @param time the time
1051 * @return the x coordinate corresponding to the time
1055 public int getXForTime(long time
) {
1056 return _stateCtrl
.getXForTime(time
);
1060 * Return the time corresponding to an x coordinate
1062 * @param x the x coordinate
1063 * @return the time corresponding to the x coordinate
1067 public long getTimeAtX(int x
) {
1068 return _stateCtrl
.getTimeAtX(x
);
1072 * Get the selection provider
1074 * @return the selection provider
1076 public ISelectionProvider
getSelectionProvider() {
1081 * Wait for the cursor
1084 * Wait indefinitely?
1086 public void waitCursor(boolean waitInd
) {
1087 _stateCtrl
.waitCursor(waitInd
);
1091 * Get the horizontal scroll bar object
1093 * @return The scroll bar
1095 public ScrollBar
getHorizontalBar() {
1096 return _stateCtrl
.getHorizontalBar();
1100 * Get the vertical scroll bar object
1102 * @return The scroll bar
1104 public Slider
getVerticalBar() {
1105 return _verticalScrollBar
;
1109 * Set the given index as the top one
1112 * The index that will go to the top
1114 public void setTopIndex(int index
) {
1115 _stateCtrl
.setTopIndex(index
);
1116 adjustVerticalScrollBar();
1120 * Retrieve the current top index
1122 * @return The top index
1124 public int getTopIndex() {
1125 return _stateCtrl
.getTopIndex();
1129 * Set the expanded state of an entry
1132 * The entry to expand/collapse
1134 * True for expanded, false for collapsed
1136 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1137 _stateCtrl
.setExpandedState(entry
, expanded
);
1138 adjustVerticalScrollBar();
1142 * Collapses all nodes of the viewer's tree, starting with the root.
1146 public void collapseAll() {
1147 _stateCtrl
.collapseAll();
1148 adjustVerticalScrollBar();
1152 * Expands all nodes of the viewer's tree, starting with the root.
1156 public void expandAll() {
1157 _stateCtrl
.expandAll();
1158 adjustVerticalScrollBar();
1162 * Get the number of sub-elements when expanded
1164 * @return The element count
1166 public int getExpandedElementCount() {
1167 return _stateCtrl
.getExpandedElementCount();
1171 * Get the sub-elements
1173 * @return The array of entries that are below this one
1175 public ITimeGraphEntry
[] getExpandedElements() {
1176 return _stateCtrl
.getExpandedElements();
1180 * Add a tree listener
1183 * The listener to add
1185 public void addTreeListener(ITimeGraphTreeListener listener
) {
1186 _stateCtrl
.addTreeListener(listener
);
1190 * Remove a tree listener
1193 * The listener to remove
1195 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1196 _stateCtrl
.removeTreeListener(listener
);
1200 * Get the reset scale action.
1202 * @return The Action object
1204 public Action
getResetScaleAction() {
1205 if (resetScale
== null) {
1207 resetScale
= new Action() {
1210 resetStartFinishTime();
1211 notifyStartFinishTime();
1214 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1215 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1216 resetScale
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1222 * Get the show legend action.
1224 * @return The Action object
1226 public Action
getShowLegendAction() {
1227 if (showLegendAction
== null) {
1229 showLegendAction
= new Action() {
1235 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1236 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1237 showLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1240 return showLegendAction
;
1244 * Get the the next event action.
1246 * @return The action object
1248 public Action
getNextEventAction() {
1249 if (nextEventAction
== null) {
1250 nextEventAction
= new Action() {
1257 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1258 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1259 nextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1262 return nextEventAction
;
1266 * Get the previous event action.
1268 * @return The Action object
1270 public Action
getPreviousEventAction() {
1271 if (prevEventAction
== null) {
1272 prevEventAction
= new Action() {
1279 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1280 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1281 prevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1284 return prevEventAction
;
1288 * Get the next item action.
1290 * @return The Action object
1292 public Action
getNextItemAction() {
1293 if (nextItemAction
== null) {
1295 nextItemAction
= new Action() {
1301 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1302 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1303 nextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1305 return nextItemAction
;
1309 * Get the previous item action.
1311 * @return The Action object
1313 public Action
getPreviousItemAction() {
1314 if (previousItemAction
== null) {
1316 previousItemAction
= new Action() {
1322 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1323 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1324 previousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1326 return previousItemAction
;
1330 * Get the zoom in action
1332 * @return The Action object
1334 public Action
getZoomInAction() {
1335 if (zoomInAction
== null) {
1336 zoomInAction
= new Action() {
1342 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1343 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1344 zoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1346 return zoomInAction
;
1350 * Get the zoom out action
1352 * @return The Action object
1354 public Action
getZoomOutAction() {
1355 if (zoomOutAction
== null) {
1356 zoomOutAction
= new Action() {
1362 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1363 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1364 zoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1366 return zoomOutAction
;
1370 private void adjustVerticalScrollBar() {
1371 int topIndex
= _stateCtrl
.getTopIndex();
1372 int countPerPage
= _stateCtrl
.countPerPage();
1373 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
1374 if (topIndex
+ countPerPage
> expandedElementCount
) {
1375 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1378 int selection
= _stateCtrl
.getTopIndex();
1380 int max
= Math
.max(1, expandedElementCount
- 1);
1381 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1383 int pageIncrement
= Math
.max(1, countPerPage
);
1384 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1388 * @param listener a {@link MenuDetectListener}
1389 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1392 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1393 _stateCtrl
.addTimeGraphEntryMenuListener(listener
);
1397 * @param listener a {@link MenuDetectListener}
1398 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1401 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1402 _stateCtrl
.removeTimeGraphEntryMenuListener(listener
);
1406 * @param listener a {@link MenuDetectListener}
1407 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1410 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1411 _stateCtrl
.addTimeEventMenuListener(listener
);
1415 * @param listener a {@link MenuDetectListener}
1416 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1419 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1420 _stateCtrl
.removeTimeEventMenuListener(listener
);