2 /*****************************************************************************
3 * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Intel Corporation - Initial API and implementation
11 * Ruslan A. Scherbakov, Intel - Initial API and implementation
12 * Alexander N. Alexeev, Intel - Add monitors statistics support
13 * Alvaro Sanchez-Leon - Adapted for TMF
14 * Patrick Tasse - Refactoring
16 *****************************************************************************/
18 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
;
20 import java
.util
.ArrayList
;
22 import org
.eclipse
.jface
.action
.Action
;
23 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
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
{
66 private long _minTimeInterval
;
67 private long _selectedTime
;
68 private ITimeGraphEntry _selectedEntry
;
69 private long _beginTime
;
70 private long _endTime
;
75 private long _time0_extSynch
= 0;
76 private long _time1_extSynch
= 0;
77 private boolean _timeRangeFixed
;
78 private int _nameWidthPref
= 200;
79 private int _minNameWidth
= 6;
80 private int _nameWidth
;
81 private Composite _dataViewer
;
83 private TimeGraphControl _stateCtrl
;
84 private TimeGraphScale _timeScaleCtrl
;
85 private Slider _verticalScrollBar
;
86 private TimeGraphTooltipHandler _threadTip
;
87 private TimeGraphColorScheme _colors
;
88 private ITimeGraphPresentationProvider fTimeGraphProvider
;
90 ArrayList
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
91 ArrayList
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
92 ArrayList
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
94 // Time format, using Epoch reference, Relative time format(default) or Number
95 private TimeFormat timeFormat
= TimeFormat
.RELATIVE
;
96 private int borderWidth
= 0;
97 private int timeScaleHeight
= 22;
99 private Action resetScale
;
100 private Action showLegendAction
;
101 private Action nextEventAction
;
102 private Action prevEventAction
;
103 private Action nextItemAction
;
104 private Action previousItemAction
;
105 private Action zoomInAction
;
106 private Action zoomOutAction
;
109 * Standard constructor
112 * The parent UI composite object
116 public TimeGraphViewer(Composite parent
, int style
) {
117 createDataViewer(parent
, style
);
121 * Sets the timegraph provider used by this timegraph viewer.
123 * @param timeGraphProvider the timegraph provider
125 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
126 fTimeGraphProvider
= timeGraphProvider
;
127 _stateCtrl
.setTimeGraphProvider(timeGraphProvider
);
128 _threadTip
= new TimeGraphTooltipHandler(_dataViewer
.getShell(), fTimeGraphProvider
, this);
129 _threadTip
.activateHoverHelp(_stateCtrl
);
133 * Sets or clears the input for this time graph viewer.
134 * The input array should only contain top-level elements.
136 * @param input The input of this time graph viewer, or <code>null</code> if none
138 public void setInput(ITimeGraphEntry
[] input
) {
139 ITimeGraphEntry
[] realInput
= input
;
141 if (_stateCtrl
!= null) {
142 if (realInput
== null) {
143 realInput
= new ITimeGraphEntry
[0];
145 setTimeRange(realInput
);
146 _verticalScrollBar
.setEnabled(true);
149 _selectedEntry
= null;
150 refreshAllData(realInput
);
157 public void refresh() {
158 setInput(_stateCtrl
.getTraces());
162 * Callback for when the control is moved
167 public void controlMoved(ControlEvent e
) {
171 * Callback for when the control is resized
176 public void controlResized(ControlEvent e
) {
181 * Handler for when the model is updated. Called from the display order in
185 * The traces in the model
190 * @param updateTimeBounds
191 * Should we updated the time bounds too
193 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
194 long end
, boolean updateTimeBounds
) {
195 if (null != _stateCtrl
) {
197 updateInternalData(traces
, start
, end
);
198 if (updateTimeBounds
) {
199 _timeRangeFixed
= true;
200 // set window to match limits
201 setStartFinishTime(_time0_
, _time1_
);
204 _timeScaleCtrl
.redraw();
210 * @return The string representing the view type
212 protected String
getViewTypeStr() {
213 return "viewoption.threads"; //$NON-NLS-1$
216 int getMarginWidth() {
220 int getMarginHeight() {
225 _minTimeInterval
= 1;
227 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
228 _nameWidthPref
, _minNameWidth
, 1000);
232 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
236 * Create a data viewer.
242 * @return The new data viewer
244 protected Control
createDataViewer(Composite parent
, int style
) {
246 _colors
= new TimeGraphColorScheme();
247 _dataViewer
= new Composite(parent
, style
) {
249 public void redraw() {
250 _timeScaleCtrl
.redraw();
255 GridLayout gl
= new GridLayout(2, false);
256 gl
.marginHeight
= borderWidth
;
258 gl
.verticalSpacing
= 0;
259 gl
.horizontalSpacing
= 0;
260 _dataViewer
.setLayout(gl
);
262 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
263 _timeScaleCtrl
.setTimeProvider(this);
264 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
265 _timeScaleCtrl
.setHeight(timeScaleHeight
);
267 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
268 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
269 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
271 public void widgetSelected(SelectionEvent e
) {
272 setTopIndex(_verticalScrollBar
.getSelection());
275 _verticalScrollBar
.setEnabled(false);
277 _stateCtrl
= createTimeGraphControl(_dataViewer
, _colors
);
279 _stateCtrl
.setTimeProvider(this);
280 _stateCtrl
.addSelectionListener(this);
281 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
282 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
284 public void mouseScrolled(MouseEvent e
) {
285 adjustVerticalScrollBar();
288 _stateCtrl
.addKeyListener(new KeyAdapter() {
290 public void keyPressed(KeyEvent e
) {
291 adjustVerticalScrollBar();
295 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
296 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
297 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
298 filler
.setLayoutData(gd
);
299 filler
.setLayout(new FillLayout());
301 _stateCtrl
.addControlListener(new ControlAdapter() {
303 public void controlResized(ControlEvent event
) {
308 _dataViewer
.update();
309 adjustVerticalScrollBar();
316 public void dispose() {
318 _stateCtrl
.dispose();
319 _dataViewer
.dispose();
324 * Create a new time graph control.
327 * The parent composite
330 * @return The new TimeGraphControl
333 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
334 TimeGraphColorScheme colors
) {
335 return new TimeGraphControl(parent
, colors
);
339 * Resize the controls
341 public void resizeControls() {
342 Rectangle r
= _dataViewer
.getClientArea();
348 if (_nameWidth
> width
- _minNameWidth
) {
349 _nameWidth
= width
- _minNameWidth
;
351 if (_nameWidth
< _minNameWidth
) {
352 _nameWidth
= _minNameWidth
;
354 adjustVerticalScrollBar();
358 * Try to set most convenient time range for display.
361 * The traces in the model
363 public void setTimeRange(ITimeGraphEntry traces
[]) {
366 for (int i
= 0; i
< traces
.length
; i
++) {
367 ITimeGraphEntry entry
= traces
[i
];
368 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
369 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
370 _beginTime
= entry
.getStartTime();
372 if (entry
.getEndTime() > _endTime
) {
373 _endTime
= entry
.getEndTime();
378 if (_beginTime
< 0) {
384 * Recalculate the time bounds
386 public void setTimeBounds() {
387 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
388 _time0_
= _beginTime
;
392 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
394 // _time0_ = Math.floor(_time0_);
395 // _time1_ = Math.ceil(_time1_);
396 if (!_timeRangeFixed
) {
400 if (_time1
- _time0
< _minTimeInterval
) {
401 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
410 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
411 ITimeGraphEntry
[] realTraces
= traces
;
413 if (null == realTraces
) {
414 realTraces
= new ITimeGraphEntry
[0];
416 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
417 // Start and end time are unspecified and need to be determined from
418 // individual processes
419 setTimeRange(realTraces
);
425 refreshAllData(realTraces
);
431 private void refreshAllData(ITimeGraphEntry
[] traces
) {
433 if (_selectedTime
< _beginTime
) {
434 _selectedTime
= _beginTime
;
435 } else if (_selectedTime
> _endTime
) {
436 _selectedTime
= _endTime
;
438 _stateCtrl
.refreshData(traces
);
439 _timeScaleCtrl
.redraw();
440 adjustVerticalScrollBar();
444 * Callback for when this view is focused
446 public void setFocus() {
447 if (null != _stateCtrl
) {
448 _stateCtrl
.setFocus();
453 * Get the current focus status of this view.
455 * @return If the view is currently focused, or not
457 public boolean isInFocus() {
458 return _stateCtrl
.isInFocus();
462 * Get the view's current selection
464 * @return The entry that is selected
466 public ITimeGraphEntry
getSelection() {
467 return _stateCtrl
.getSelectedTrace();
471 * Get the index of the current selection
475 public int getSelectionIndex() {
476 return _stateCtrl
.getSelectedIndex();
480 public long getTime0() {
485 public long getTime1() {
490 public long getMinTimeInterval() {
491 return _minTimeInterval
;
495 public int getNameSpace() {
500 public void setNameSpace(int width
) {
502 int w
= _stateCtrl
.getClientArea().width
;
503 if (_nameWidth
> w
- 6) {
506 if (_nameWidth
< 6) {
509 _stateCtrl
.adjustScrolls();
511 _timeScaleCtrl
.redraw();
515 public int getTimeSpace() {
516 int w
= _stateCtrl
.getClientArea().width
;
517 return w
- _nameWidth
;
521 public long getSelectedTime() {
522 return _selectedTime
;
526 public long getBeginTime() {
531 public long getEndTime() {
536 public long getMaxTime() {
541 public long getMinTime() {
549 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
550 * #setStartFinishTimeNotify(long, long)
553 public void setStartFinishTimeNotify(long time0
, long time1
) {
554 setStartFinishTime(time0
, time1
);
555 notifyRangeListeners(time0
, time1
);
560 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
563 public void notifyStartFinishTime() {
564 notifyRangeListeners(_time0
, _time1
);
571 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
572 * #setStartFinishTime(long, long)
575 public void setStartFinishTime(long time0
, long time1
) {
577 if (_time0
< _time0_
) {
580 if (_time0
> _time1_
) {
584 if (_time1
< _time0_
) {
587 if (_time1
> _time1_
) {
590 if (_time1
- _time0
< _minTimeInterval
) {
591 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
593 _timeRangeFixed
= true;
594 _stateCtrl
.adjustScrolls();
596 _timeScaleCtrl
.redraw();
600 * Set the time bounds to the provided values
603 * The start time of the window
607 public void setTimeBounds(long beginTime
, long endTime
) {
608 _beginTime
= beginTime
;
612 _stateCtrl
.adjustScrolls();
616 public void resetStartFinishTime() {
617 setStartFinishTime(_time0_
, _time1_
);
618 _timeRangeFixed
= false;
622 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
623 setSelectedTimeInt(time
, ensureVisible
, true);
627 public void setSelectedTime(long time
, boolean ensureVisible
) {
628 setSelectedTimeInt(time
, ensureVisible
, false);
631 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
635 long timeSpace
= (long) ((_time1
- _time0
) * .02);
636 long timeMid
= (long) ((_time1
- _time0
) * .5);
637 if (time
< _time0
+ timeSpace
) {
638 long dt
= _time0
- time
+ timeMid
;
641 } else if (time
> _time1
- timeSpace
) {
642 long dt
= time
- _time1
+ timeMid
;
646 if (_time0
< _time0_
) {
647 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
649 } else if (_time1
> _time1_
) {
650 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
654 if (_time1
- _time0
< _minTimeInterval
) {
655 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
657 _stateCtrl
.adjustScrolls();
659 _timeScaleCtrl
.redraw();
662 boolean notifySelectedTime
= (time
!= _selectedTime
);
663 _selectedTime
= time
;
665 if (doNotify
&& ((time0
!= _time0
) || (time1
!= _time1
))) {
666 notifyRangeListeners(_time0
, _time1
);
669 if (doNotify
&& notifySelectedTime
) {
670 notifyTimeListeners(_selectedTime
);
675 public void widgetDefaultSelected(SelectionEvent e
) {
676 if (_selectedEntry
!= getSelection()) {
677 _selectedEntry
= getSelection();
678 notifySelectionListeners(_selectedEntry
);
683 public void widgetSelected(SelectionEvent e
) {
684 if (_selectedEntry
!= getSelection()) {
685 _selectedEntry
= getSelection();
686 notifySelectionListeners(_selectedEntry
);
691 * Callback for when the next event is selected
693 public void selectNextEvent() {
694 _stateCtrl
.selectNextEvent();
695 adjustVerticalScrollBar();
699 * Callback for when the previous event is selected
701 public void selectPrevEvent() {
702 _stateCtrl
.selectPrevEvent();
703 adjustVerticalScrollBar();
707 * Callback for when the next item is selected
709 public void selectNextItem() {
710 _stateCtrl
.selectNextTrace();
711 adjustVerticalScrollBar();
715 * Callback for when the previous item is selected
717 public void selectPrevItem() {
718 _stateCtrl
.selectPrevTrace();
719 adjustVerticalScrollBar();
723 * Callback for the show legend action
725 public void showLegend() {
726 if (_dataViewer
== null || _dataViewer
.isDisposed()) {
730 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
734 * Callback for the Zoom In action
736 public void zoomIn() {
741 * Callback for the Zoom Out action
743 public void zoomOut() {
744 _stateCtrl
.zoomOut();
747 private String
getPreferenceString(String string
) {
748 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
752 * Add a selection listener
755 * The listener to add
757 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
758 fSelectionListeners
.add(listener
);
762 * Remove a selection listener
765 * The listener to remove
767 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
768 fSelectionListeners
.remove(listener
);
771 private void notifySelectionListeners(ITimeGraphEntry selection
) {
772 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
774 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
775 listener
.selectionChanged(event
);
780 * Add a time listener
783 * The listener to add
785 public void addTimeListener(ITimeGraphTimeListener listener
) {
786 fTimeListeners
.add(listener
);
790 * Remove a time listener
793 * The listener to remove
795 public void removeTimeListener(ITimeGraphTimeListener listener
) {
796 fTimeListeners
.remove(listener
);
799 private void notifyTimeListeners(long time
) {
800 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
802 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
803 listener
.timeSelected(event
);
808 * Add a range listener
811 * The listener to add
813 public void addRangeListener(ITimeGraphRangeListener listener
) {
814 fRangeListeners
.add(listener
);
818 * Remove a range listener
821 * The listener to remove
823 public void removeRangeListener(ITimeGraphRangeListener listener
) {
824 fRangeListeners
.remove(listener
);
827 private void notifyRangeListeners(long startTime
, long endTime
) {
828 // Check if the time has actually changed from last notification
829 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
830 // Notify Time Scale Selection Listeners
831 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
833 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
834 listener
.timeRangeUpdated(event
);
837 // update external synch timers
838 updateExtSynchTimers();
843 * Callback to set a selected event in the view
846 * The event that was selected
848 * The source of this selection event
850 public void setSelectedEvent(ITimeEvent event
, Object source
) {
851 if (event
== null || source
== this) {
854 _selectedEntry
= event
.getEntry();
855 _stateCtrl
.selectItem(_selectedEntry
, false);
857 setSelectedTimeInt(event
.getTime(), true, true);
858 adjustVerticalScrollBar();
862 * Set the seeked time of a trace
865 * The trace that was seeked
869 * The source of this seek event
871 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
872 if (trace
== null || source
== this) {
875 _selectedEntry
= trace
;
876 _stateCtrl
.selectItem(trace
, false);
878 setSelectedTimeInt(time
, true, true);
882 * Callback for a trace selection
885 * The trace that was selected
887 public void setSelection(ITimeGraphEntry trace
) {
888 _selectedEntry
= trace
;
889 _stateCtrl
.selectItem(trace
, false);
890 adjustVerticalScrollBar();
894 * Callback for a time window selection
897 * Start time of the range
899 * End time of the range
901 * Source of the event
903 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
904 if (source
== this) {
908 setStartFinishTime(time0
, time1
);
910 // update notification time values since we are now in synch with the
911 // external application
912 updateExtSynchTimers();
916 * update the cache timers used to identify the need to send a time window
917 * update to external registered listeners
919 private void updateExtSynchTimers() {
920 // last time notification cache
921 _time0_extSynch
= _time0
;
922 _time1_extSynch
= _time1
;
929 public TimeFormat
getTimeFormat() {
934 * @param tf the {@link TimeFormat} used to display timestamps
937 public void setTimeFormat(TimeFormat tf
) {
938 this.timeFormat
= tf
;
942 * Retrieve the border width
946 public int getBorderWidth() {
951 * Set the border width
956 public void setBorderWidth(int borderWidth
) {
957 if (borderWidth
> -1) {
958 this.borderWidth
= borderWidth
;
959 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
960 gl
.marginHeight
= borderWidth
;
965 * Retrieve the height of the header
969 public int getHeaderHeight() {
970 return timeScaleHeight
;
974 * Set the height of the header
976 * @param headerHeight
979 public void setHeaderHeight(int headerHeight
) {
980 if (headerHeight
> -1) {
981 this.timeScaleHeight
= headerHeight
;
982 _timeScaleCtrl
.setHeight(headerHeight
);
987 * Retrieve the height of an item row
991 public int getItemHeight() {
992 if (_stateCtrl
!= null) {
993 return _stateCtrl
.getItemHeight();
999 * Set the height of an item row
1004 public void setItemHeight(int rowHeight
) {
1005 if (_stateCtrl
!= null) {
1006 _stateCtrl
.setItemHeight(rowHeight
);
1011 * Set the minimum item width
1016 public void setMinimumItemWidth(int width
) {
1017 if (_stateCtrl
!= null) {
1018 _stateCtrl
.setMinimumItemWidth(width
);
1023 * Set the width for the name column
1025 * @param width The width
1027 public void setNameWidthPref(int width
) {
1028 _nameWidthPref
= width
;
1036 * Retrieve the configure width for the name column
1042 public int getNameWidthPref(int width
) {
1043 return _nameWidthPref
;
1047 * Returns the primary control associated with this viewer.
1049 * @return the SWT control which displays this viewer's content
1051 public Control
getControl() {
1056 * Returns the time graph control associated with this viewer.
1058 * @return the time graph control
1060 TimeGraphControl
getTimeGraphControl() {
1065 * Returns the time graph scale associated with this viewer.
1067 * @return the time graph scale
1069 TimeGraphScale
getTimeGraphScale() {
1070 return _timeScaleCtrl
;
1074 * Return the x coordinate corresponding to a time
1076 * @param time the time
1077 * @return the x coordinate corresponding to the time
1081 public int getXForTime(long time
) {
1082 return _stateCtrl
.getXForTime(time
);
1086 * Return the time corresponding to an x coordinate
1088 * @param x the x coordinate
1089 * @return the time corresponding to the x coordinate
1093 public long getTimeAtX(int x
) {
1094 return _stateCtrl
.getTimeAtX(x
);
1098 * Get the selection provider
1100 * @return the selection provider
1102 public ISelectionProvider
getSelectionProvider() {
1107 * Wait for the cursor
1110 * Wait indefinitely?
1112 public void waitCursor(boolean waitInd
) {
1113 _stateCtrl
.waitCursor(waitInd
);
1117 * Get the horizontal scroll bar object
1119 * @return The scroll bar
1121 public ScrollBar
getHorizontalBar() {
1122 return _stateCtrl
.getHorizontalBar();
1126 * Get the vertical scroll bar object
1128 * @return The scroll bar
1130 public Slider
getVerticalBar() {
1131 return _verticalScrollBar
;
1135 * Set the given index as the top one
1138 * The index that will go to the top
1140 public void setTopIndex(int index
) {
1141 _stateCtrl
.setTopIndex(index
);
1142 adjustVerticalScrollBar();
1146 * Retrieve the current top index
1148 * @return The top index
1150 public int getTopIndex() {
1151 return _stateCtrl
.getTopIndex();
1155 * Set the expanded state of an entry
1158 * The entry to expand/collapse
1160 * True for expanded, false for collapsed
1162 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1163 _stateCtrl
.setExpandedState(entry
, expanded
);
1164 adjustVerticalScrollBar();
1168 * Collapses all nodes of the viewer's tree, starting with the root.
1172 public void collapseAll() {
1173 _stateCtrl
.collapseAll();
1174 adjustVerticalScrollBar();
1178 * Expands all nodes of the viewer's tree, starting with the root.
1182 public void expandAll() {
1183 _stateCtrl
.expandAll();
1184 adjustVerticalScrollBar();
1188 * Get the number of sub-elements when expanded
1190 * @return The element count
1192 public int getExpandedElementCount() {
1193 return _stateCtrl
.getExpandedElementCount();
1197 * Get the sub-elements
1199 * @return The array of entries that are below this one
1201 public ITimeGraphEntry
[] getExpandedElements() {
1202 return _stateCtrl
.getExpandedElements();
1206 * Add a tree listener
1209 * The listener to add
1211 public void addTreeListener(ITimeGraphTreeListener listener
) {
1212 _stateCtrl
.addTreeListener(listener
);
1216 * Remove a tree listener
1219 * The listener to remove
1221 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1222 _stateCtrl
.removeTreeListener(listener
);
1226 * Get the reset scale action.
1228 * @return The Action object
1230 public Action
getResetScaleAction() {
1231 if (resetScale
== null) {
1233 resetScale
= new Action() {
1236 resetStartFinishTime();
1237 notifyStartFinishTime();
1240 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1241 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1242 resetScale
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1248 * Get the show legend action.
1250 * @return The Action object
1252 public Action
getShowLegendAction() {
1253 if (showLegendAction
== null) {
1255 showLegendAction
= new Action() {
1261 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1262 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1263 showLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1266 return showLegendAction
;
1270 * Get the the next event action.
1272 * @return The action object
1274 public Action
getNextEventAction() {
1275 if (nextEventAction
== null) {
1276 nextEventAction
= new Action() {
1283 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1284 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1285 nextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1288 return nextEventAction
;
1292 * Get the previous event action.
1294 * @return The Action object
1296 public Action
getPreviousEventAction() {
1297 if (prevEventAction
== null) {
1298 prevEventAction
= new Action() {
1305 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1306 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1307 prevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1310 return prevEventAction
;
1314 * Get the next item action.
1316 * @return The Action object
1318 public Action
getNextItemAction() {
1319 if (nextItemAction
== null) {
1321 nextItemAction
= new Action() {
1327 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1328 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1329 nextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1331 return nextItemAction
;
1335 * Get the previous item action.
1337 * @return The Action object
1339 public Action
getPreviousItemAction() {
1340 if (previousItemAction
== null) {
1342 previousItemAction
= new Action() {
1348 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1349 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1350 previousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1352 return previousItemAction
;
1356 * Get the zoom in action
1358 * @return The Action object
1360 public Action
getZoomInAction() {
1361 if (zoomInAction
== null) {
1362 zoomInAction
= new Action() {
1368 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1369 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1370 zoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1372 return zoomInAction
;
1376 * Get the zoom out action
1378 * @return The Action object
1380 public Action
getZoomOutAction() {
1381 if (zoomOutAction
== null) {
1382 zoomOutAction
= new Action() {
1388 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1389 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1390 zoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1392 return zoomOutAction
;
1396 private void adjustVerticalScrollBar() {
1397 int topIndex
= _stateCtrl
.getTopIndex();
1398 int countPerPage
= _stateCtrl
.countPerPage();
1399 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
1400 if (topIndex
+ countPerPage
> expandedElementCount
) {
1401 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1404 int selection
= _stateCtrl
.getTopIndex();
1406 int max
= Math
.max(1, expandedElementCount
- 1);
1407 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1409 int pageIncrement
= Math
.max(1, countPerPage
);
1410 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1414 * @param listener a {@link MenuDetectListener}
1415 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1418 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1419 _stateCtrl
.addTimeGraphEntryMenuListener(listener
);
1423 * @param listener a {@link MenuDetectListener}
1424 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1427 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1428 _stateCtrl
.removeTimeGraphEntryMenuListener(listener
);
1432 * @param listener a {@link MenuDetectListener}
1433 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1436 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1437 _stateCtrl
.addTimeEventMenuListener(listener
);
1441 * @param listener a {@link MenuDetectListener}
1442 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1445 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1446 _stateCtrl
.removeTimeEventMenuListener(listener
);