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
;
20 import org
.eclipse
.jface
.action
.Action
;
21 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
22 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
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
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.events
.ControlAdapter
;
38 import org
.eclipse
.swt
.events
.ControlEvent
;
39 import org
.eclipse
.swt
.events
.KeyAdapter
;
40 import org
.eclipse
.swt
.events
.KeyEvent
;
41 import org
.eclipse
.swt
.events
.MenuDetectListener
;
42 import org
.eclipse
.swt
.events
.MouseEvent
;
43 import org
.eclipse
.swt
.events
.MouseWheelListener
;
44 import org
.eclipse
.swt
.events
.SelectionAdapter
;
45 import org
.eclipse
.swt
.events
.SelectionEvent
;
46 import org
.eclipse
.swt
.events
.SelectionListener
;
47 import org
.eclipse
.swt
.graphics
.Rectangle
;
48 import org
.eclipse
.swt
.layout
.FillLayout
;
49 import org
.eclipse
.swt
.layout
.GridData
;
50 import org
.eclipse
.swt
.layout
.GridLayout
;
51 import org
.eclipse
.swt
.widgets
.Composite
;
52 import org
.eclipse
.swt
.widgets
.Control
;
53 import org
.eclipse
.swt
.widgets
.ScrollBar
;
54 import org
.eclipse
.swt
.widgets
.Slider
;
57 * Generic time graph viewer implementation
60 * @author Patrick Tasse, and others
62 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
65 private long _minTimeInterval
;
66 private long _selectedTime
;
67 private ITimeGraphEntry _selectedEntry
;
68 private long _beginTime
;
69 private long _endTime
;
74 private long _time0_extSynch
= 0;
75 private long _time1_extSynch
= 0;
76 private boolean _timeRangeFixed
;
77 private int _nameWidthPref
= 200;
78 private int _minNameWidth
= 6;
79 private int _nameWidth
;
80 private Composite _dataViewer
;
82 private TimeGraphControl _stateCtrl
;
83 private TimeGraphScale _timeScaleCtrl
;
84 private Slider _verticalScrollBar
;
85 private TimeGraphTooltipHandler _threadTip
;
86 private TimeGraphColorScheme _colors
;
87 private ITimeGraphPresentationProvider fTimeGraphProvider
;
89 ArrayList
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
90 ArrayList
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
91 ArrayList
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
93 // Time format, using Epoch reference, Relative time format(default) or Number
94 private TimeFormat timeFormat
= TimeFormat
.RELATIVE
;
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 ITimeGraphEntry
[] realInput
= input
;
140 if (_stateCtrl
!= null) {
141 if (realInput
== null) {
142 realInput
= new ITimeGraphEntry
[0];
144 setTimeRange(realInput
);
145 _verticalScrollBar
.setEnabled(true);
148 _selectedEntry
= null;
149 refreshAllData(realInput
);
156 public void refresh() {
157 setInput(_stateCtrl
.getTraces());
161 * Callback for when the control is moved
166 public void controlMoved(ControlEvent e
) {
170 * Callback for when the control is resized
175 public void controlResized(ControlEvent e
) {
180 * Handler for when the model is updated. Called from the display order in
184 * The traces in the model
189 * @param updateTimeBounds
190 * Should we updated the time bounds too
192 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
193 long end
, boolean updateTimeBounds
) {
194 if (null != _stateCtrl
) {
196 updateInternalData(traces
, start
, end
);
197 if (updateTimeBounds
) {
198 _timeRangeFixed
= true;
199 // set window to match limits
200 setStartFinishTime(_time0_
, _time1_
);
203 _timeScaleCtrl
.redraw();
209 * @return The string representing the view type
211 protected String
getViewTypeStr() {
212 return "viewoption.threads"; //$NON-NLS-1$
215 int getMarginWidth() {
219 int getMarginHeight() {
224 _minTimeInterval
= 1;
226 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
227 _nameWidthPref
, _minNameWidth
, 1000);
231 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
235 * Create a data viewer.
241 * @return The new data viewer
243 protected Control
createDataViewer(Composite parent
, int style
) {
245 _colors
= new TimeGraphColorScheme();
246 _dataViewer
= new Composite(parent
, style
) {
248 public void redraw() {
249 _timeScaleCtrl
.redraw();
254 GridLayout gl
= new GridLayout(2, false);
255 gl
.marginHeight
= borderWidth
;
257 gl
.verticalSpacing
= 0;
258 gl
.horizontalSpacing
= 0;
259 _dataViewer
.setLayout(gl
);
261 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
262 _timeScaleCtrl
.setTimeProvider(this);
263 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
264 _timeScaleCtrl
.setHeight(timeScaleHeight
);
266 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
267 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
268 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
270 public void widgetSelected(SelectionEvent e
) {
271 setTopIndex(_verticalScrollBar
.getSelection());
274 _verticalScrollBar
.setEnabled(false);
276 _stateCtrl
= createTimeGraphControl(_dataViewer
, _colors
);
278 _stateCtrl
.setTimeProvider(this);
279 _stateCtrl
.addSelectionListener(this);
280 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
281 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
283 public void mouseScrolled(MouseEvent e
) {
284 adjustVerticalScrollBar();
287 _stateCtrl
.addKeyListener(new KeyAdapter() {
289 public void keyPressed(KeyEvent e
) {
290 adjustVerticalScrollBar();
294 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
295 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
296 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
297 filler
.setLayoutData(gd
);
298 filler
.setLayout(new FillLayout());
300 _stateCtrl
.addControlListener(new ControlAdapter() {
302 public void controlResized(ControlEvent event
) {
307 _dataViewer
.update();
308 adjustVerticalScrollBar();
315 public void dispose() {
317 _stateCtrl
.dispose();
318 _dataViewer
.dispose();
323 * Create a new time graph control.
326 * The parent composite
329 * @return The new TimeGraphControl
332 protected TimeGraphControl
createTimeGraphControl(Composite parent
,
333 TimeGraphColorScheme colors
) {
334 return new TimeGraphControl(parent
, colors
);
338 * Resize the controls
340 public void resizeControls() {
341 Rectangle r
= _dataViewer
.getClientArea();
347 if (_nameWidth
> width
- _minNameWidth
) {
348 _nameWidth
= width
- _minNameWidth
;
350 if (_nameWidth
< _minNameWidth
) {
351 _nameWidth
= _minNameWidth
;
353 adjustVerticalScrollBar();
357 * Try to set most convenient time range for display.
360 * The traces in the model
362 public void setTimeRange(ITimeGraphEntry traces
[]) {
365 for (int i
= 0; i
< traces
.length
; i
++) {
366 ITimeGraphEntry entry
= traces
[i
];
367 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
368 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
369 _beginTime
= entry
.getStartTime();
371 if (entry
.getEndTime() > _endTime
) {
372 _endTime
= entry
.getEndTime();
377 if (_beginTime
< 0) {
383 * Recalculate the time bounds
385 public void setTimeBounds() {
386 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
387 _time0_
= _beginTime
;
391 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
393 // _time0_ = Math.floor(_time0_);
394 // _time1_ = Math.ceil(_time1_);
395 if (!_timeRangeFixed
) {
399 if (_time1
- _time0
< _minTimeInterval
) {
400 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
409 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
410 ITimeGraphEntry
[] realTraces
= traces
;
412 if (null == realTraces
) {
413 realTraces
= new ITimeGraphEntry
[0];
415 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
416 // Start and end time are unspecified and need to be determined from
417 // individual processes
418 setTimeRange(realTraces
);
424 refreshAllData(realTraces
);
430 private void refreshAllData(ITimeGraphEntry
[] traces
) {
432 if (_selectedTime
< _beginTime
) {
433 _selectedTime
= _beginTime
;
434 } else if (_selectedTime
> _endTime
) {
435 _selectedTime
= _endTime
;
437 _stateCtrl
.refreshData(traces
);
438 _timeScaleCtrl
.redraw();
439 adjustVerticalScrollBar();
443 * Callback for when this view is focused
445 public void setFocus() {
446 if (null != _stateCtrl
) {
447 _stateCtrl
.setFocus();
452 * Get the current focus status of this view.
454 * @return If the view is currently focused, or not
456 public boolean isInFocus() {
457 return _stateCtrl
.isInFocus();
461 * Get the view's current selection
463 * @return The entry that is selected
465 public ITimeGraphEntry
getSelection() {
466 return _stateCtrl
.getSelectedTrace();
470 * Get the index of the current selection
474 public int getSelectionIndex() {
475 return _stateCtrl
.getSelectedIndex();
479 public long getTime0() {
484 public long getTime1() {
489 public long getMinTimeInterval() {
490 return _minTimeInterval
;
494 public int getNameSpace() {
499 public void setNameSpace(int width
) {
501 int w
= _stateCtrl
.getClientArea().width
;
502 if (_nameWidth
> w
- 6) {
505 if (_nameWidth
< 6) {
508 _stateCtrl
.adjustScrolls();
510 _timeScaleCtrl
.redraw();
514 public int getTimeSpace() {
515 int w
= _stateCtrl
.getClientArea().width
;
516 return w
- _nameWidth
;
520 public long getSelectedTime() {
521 return _selectedTime
;
525 public long getBeginTime() {
530 public long getEndTime() {
535 public long getMaxTime() {
540 public long getMinTime() {
548 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
549 * #setStartFinishTimeNotify(long, long)
552 public void setStartFinishTimeNotify(long time0
, long time1
) {
553 setStartFinishTime(time0
, time1
);
554 notifyRangeListeners(time0
, time1
);
559 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
562 public void notifyStartFinishTime() {
563 notifyRangeListeners(_time0
, _time1
);
570 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
571 * #setStartFinishTime(long, long)
574 public void setStartFinishTime(long time0
, long time1
) {
576 if (_time0
< _time0_
) {
579 if (_time0
> _time1_
) {
583 if (_time1
< _time0_
) {
586 if (_time1
> _time1_
) {
589 if (_time1
- _time0
< _minTimeInterval
) {
590 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
592 _timeRangeFixed
= true;
593 _stateCtrl
.adjustScrolls();
595 _timeScaleCtrl
.redraw();
599 * Set the time bounds to the provided values
602 * The start time of the window
606 public void setTimeBounds(long beginTime
, long endTime
) {
607 _beginTime
= beginTime
;
611 _stateCtrl
.adjustScrolls();
615 public void resetStartFinishTime() {
616 setStartFinishTime(_time0_
, _time1_
);
617 _timeRangeFixed
= false;
621 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
622 setSelectedTimeInt(time
, ensureVisible
, true);
626 public void setSelectedTime(long time
, boolean ensureVisible
) {
627 setSelectedTimeInt(time
, ensureVisible
, false);
630 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
634 long timeSpace
= (long) ((_time1
- _time0
) * .02);
635 long timeMid
= (long) ((_time1
- _time0
) * .5);
636 if (time
< _time0
+ timeSpace
) {
637 long dt
= _time0
- time
+ timeMid
;
640 } else if (time
> _time1
- timeSpace
) {
641 long dt
= time
- _time1
+ timeMid
;
645 if (_time0
< _time0_
) {
646 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
648 } else if (_time1
> _time1_
) {
649 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
653 if (_time1
- _time0
< _minTimeInterval
) {
654 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
656 _stateCtrl
.adjustScrolls();
658 _timeScaleCtrl
.redraw();
661 boolean notifySelectedTime
= (time
!= _selectedTime
);
662 _selectedTime
= time
;
664 if (doNotify
&& ((time0
!= _time0
) || (time1
!= _time1
))) {
665 notifyRangeListeners(_time0
, _time1
);
668 if (doNotify
&& notifySelectedTime
) {
669 notifyTimeListeners(_selectedTime
);
674 public void widgetDefaultSelected(SelectionEvent e
) {
675 if (_selectedEntry
!= getSelection()) {
676 _selectedEntry
= getSelection();
677 notifySelectionListeners(_selectedEntry
);
682 public void widgetSelected(SelectionEvent e
) {
683 if (_selectedEntry
!= getSelection()) {
684 _selectedEntry
= getSelection();
685 notifySelectionListeners(_selectedEntry
);
690 * Callback for when the next event is selected
692 public void selectNextEvent() {
693 _stateCtrl
.selectNextEvent();
694 adjustVerticalScrollBar();
698 * Callback for when the previous event is selected
700 public void selectPrevEvent() {
701 _stateCtrl
.selectPrevEvent();
702 adjustVerticalScrollBar();
706 * Callback for when the next item is selected
708 public void selectNextItem() {
709 _stateCtrl
.selectNextTrace();
710 adjustVerticalScrollBar();
714 * Callback for when the previous item is selected
716 public void selectPrevItem() {
717 _stateCtrl
.selectPrevTrace();
718 adjustVerticalScrollBar();
722 * Callback for the show legend action
724 public void showLegend() {
725 if (_dataViewer
== null || _dataViewer
.isDisposed()) {
729 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
733 * Callback for the Zoom In action
735 public void zoomIn() {
740 * Callback for the Zoom Out action
742 public void zoomOut() {
743 _stateCtrl
.zoomOut();
746 private String
getPreferenceString(String string
) {
747 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
751 * Add a selection listener
754 * The listener to add
756 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
757 fSelectionListeners
.add(listener
);
761 * Remove a selection listener
764 * The listener to remove
766 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
767 fSelectionListeners
.remove(listener
);
770 private void notifySelectionListeners(ITimeGraphEntry selection
) {
771 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
773 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
774 listener
.selectionChanged(event
);
779 * Add a time listener
782 * The listener to add
784 public void addTimeListener(ITimeGraphTimeListener listener
) {
785 fTimeListeners
.add(listener
);
789 * Remove a time listener
792 * The listener to remove
794 public void removeTimeListener(ITimeGraphTimeListener listener
) {
795 fTimeListeners
.remove(listener
);
798 private void notifyTimeListeners(long time
) {
799 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
801 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
802 listener
.timeSelected(event
);
807 * Add a range listener
810 * The listener to add
812 public void addRangeListener(ITimeGraphRangeListener listener
) {
813 fRangeListeners
.add(listener
);
817 * Remove a range listener
820 * The listener to remove
822 public void removeRangeListener(ITimeGraphRangeListener listener
) {
823 fRangeListeners
.remove(listener
);
826 private void notifyRangeListeners(long startTime
, long endTime
) {
827 // Check if the time has actually changed from last notification
828 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
829 // Notify Time Scale Selection Listeners
830 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
832 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
833 listener
.timeRangeUpdated(event
);
836 // update external synch timers
837 updateExtSynchTimers();
842 * Callback to set a selected event in the view
845 * The event that was selected
847 * The source of this selection event
849 public void setSelectedEvent(ITimeEvent event
, Object source
) {
850 if (event
== null || source
== this) {
853 _selectedEntry
= event
.getEntry();
854 _stateCtrl
.selectItem(_selectedEntry
, false);
856 setSelectedTimeInt(event
.getTime(), true, true);
857 adjustVerticalScrollBar();
861 * Set the seeked time of a trace
864 * The trace that was seeked
868 * The source of this seek event
870 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
871 if (trace
== null || source
== this) {
874 _selectedEntry
= trace
;
875 _stateCtrl
.selectItem(trace
, false);
877 setSelectedTimeInt(time
, true, true);
881 * Callback for a trace selection
884 * The trace that was selected
886 public void setSelection(ITimeGraphEntry trace
) {
887 _selectedEntry
= trace
;
888 _stateCtrl
.selectItem(trace
, false);
889 adjustVerticalScrollBar();
893 * Callback for a time window selection
896 * Start time of the range
898 * End time of the range
900 * Source of the event
902 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
903 if (source
== this) {
907 setStartFinishTime(time0
, time1
);
909 // update notification time values since we are now in synch with the
910 // external application
911 updateExtSynchTimers();
915 * update the cache timers used to identify the need to send a time window
916 * update to external registered listeners
918 private void updateExtSynchTimers() {
919 // last time notification cache
920 _time0_extSynch
= _time0
;
921 _time1_extSynch
= _time1
;
928 public TimeFormat
getTimeFormat() {
933 * @param tf the {@link TimeFormat} used to display timestamps
936 public void setTimeFormat(TimeFormat tf
) {
937 this.timeFormat
= tf
;
941 * Retrieve the border width
945 public int getBorderWidth() {
950 * Set the border width
955 public void setBorderWidth(int borderWidth
) {
956 if (borderWidth
> -1) {
957 this.borderWidth
= borderWidth
;
958 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
959 gl
.marginHeight
= borderWidth
;
964 * Retrieve the height of the header
968 public int getHeaderHeight() {
969 return timeScaleHeight
;
973 * Set the height of the header
975 * @param headerHeight
978 public void setHeaderHeight(int headerHeight
) {
979 if (headerHeight
> -1) {
980 this.timeScaleHeight
= headerHeight
;
981 _timeScaleCtrl
.setHeight(headerHeight
);
986 * Retrieve the height of an item row
990 public int getItemHeight() {
991 if (_stateCtrl
!= null) {
992 return _stateCtrl
.getItemHeight();
998 * Set the height of an item row
1003 public void setItemHeight(int rowHeight
) {
1004 if (_stateCtrl
!= null) {
1005 _stateCtrl
.setItemHeight(rowHeight
);
1010 * Set the minimum item width
1015 public void setMinimumItemWidth(int width
) {
1016 if (_stateCtrl
!= null) {
1017 _stateCtrl
.setMinimumItemWidth(width
);
1022 * Set the width for the name column
1024 * @param width The width
1026 public void setNameWidthPref(int width
) {
1027 _nameWidthPref
= width
;
1035 * Retrieve the configure width for the name column
1041 public int getNameWidthPref(int width
) {
1042 return _nameWidthPref
;
1046 * Returns the primary control associated with this viewer.
1048 * @return the SWT control which displays this viewer's content
1050 public Control
getControl() {
1055 * Returns the time graph control associated with this viewer.
1057 * @return the time graph control
1059 TimeGraphControl
getTimeGraphControl() {
1064 * Returns the time graph scale associated with this viewer.
1066 * @return the time graph scale
1068 TimeGraphScale
getTimeGraphScale() {
1069 return _timeScaleCtrl
;
1073 * Return the x coordinate corresponding to a time
1075 * @param time the time
1076 * @return the x coordinate corresponding to the time
1080 public int getXForTime(long time
) {
1081 return _stateCtrl
.getXForTime(time
);
1085 * Return the time corresponding to an x coordinate
1087 * @param x the x coordinate
1088 * @return the time corresponding to the x coordinate
1092 public long getTimeAtX(int x
) {
1093 return _stateCtrl
.getTimeAtX(x
);
1097 * Get the selection provider
1099 * @return the selection provider
1101 public ISelectionProvider
getSelectionProvider() {
1106 * Wait for the cursor
1109 * Wait indefinitely?
1111 public void waitCursor(boolean waitInd
) {
1112 _stateCtrl
.waitCursor(waitInd
);
1116 * Get the horizontal scroll bar object
1118 * @return The scroll bar
1120 public ScrollBar
getHorizontalBar() {
1121 return _stateCtrl
.getHorizontalBar();
1125 * Get the vertical scroll bar object
1127 * @return The scroll bar
1129 public Slider
getVerticalBar() {
1130 return _verticalScrollBar
;
1134 * Set the given index as the top one
1137 * The index that will go to the top
1139 public void setTopIndex(int index
) {
1140 _stateCtrl
.setTopIndex(index
);
1141 adjustVerticalScrollBar();
1145 * Retrieve the current top index
1147 * @return The top index
1149 public int getTopIndex() {
1150 return _stateCtrl
.getTopIndex();
1154 * Set the expanded state of an entry
1157 * The entry to expand/collapse
1159 * True for expanded, false for collapsed
1161 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1162 _stateCtrl
.setExpandedState(entry
, expanded
);
1163 adjustVerticalScrollBar();
1167 * Collapses all nodes of the viewer's tree, starting with the root.
1171 public void collapseAll() {
1172 _stateCtrl
.collapseAll();
1173 adjustVerticalScrollBar();
1177 * Expands all nodes of the viewer's tree, starting with the root.
1181 public void expandAll() {
1182 _stateCtrl
.expandAll();
1183 adjustVerticalScrollBar();
1187 * Get the number of sub-elements when expanded
1189 * @return The element count
1191 public int getExpandedElementCount() {
1192 return _stateCtrl
.getExpandedElementCount();
1196 * Get the sub-elements
1198 * @return The array of entries that are below this one
1200 public ITimeGraphEntry
[] getExpandedElements() {
1201 return _stateCtrl
.getExpandedElements();
1205 * Add a tree listener
1208 * The listener to add
1210 public void addTreeListener(ITimeGraphTreeListener listener
) {
1211 _stateCtrl
.addTreeListener(listener
);
1215 * Remove a tree listener
1218 * The listener to remove
1220 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1221 _stateCtrl
.removeTreeListener(listener
);
1225 * Get the reset scale action.
1227 * @return The Action object
1229 public Action
getResetScaleAction() {
1230 if (resetScale
== null) {
1232 resetScale
= new Action() {
1235 resetStartFinishTime();
1236 notifyStartFinishTime();
1239 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1240 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1241 resetScale
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1247 * Get the show legend action.
1249 * @return The Action object
1251 public Action
getShowLegendAction() {
1252 if (showLegendAction
== null) {
1254 showLegendAction
= new Action() {
1260 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1261 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1262 showLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1265 return showLegendAction
;
1269 * Get the the next event action.
1271 * @return The action object
1273 public Action
getNextEventAction() {
1274 if (nextEventAction
== null) {
1275 nextEventAction
= new Action() {
1282 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1283 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1284 nextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1287 return nextEventAction
;
1291 * Get the previous event action.
1293 * @return The Action object
1295 public Action
getPreviousEventAction() {
1296 if (prevEventAction
== null) {
1297 prevEventAction
= new Action() {
1304 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1305 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1306 prevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1309 return prevEventAction
;
1313 * Get the next item action.
1315 * @return The Action object
1317 public Action
getNextItemAction() {
1318 if (nextItemAction
== null) {
1320 nextItemAction
= new Action() {
1326 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1327 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1328 nextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1330 return nextItemAction
;
1334 * Get the previous item action.
1336 * @return The Action object
1338 public Action
getPreviousItemAction() {
1339 if (previousItemAction
== null) {
1341 previousItemAction
= new Action() {
1347 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1348 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1349 previousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1351 return previousItemAction
;
1355 * Get the zoom in action
1357 * @return The Action object
1359 public Action
getZoomInAction() {
1360 if (zoomInAction
== null) {
1361 zoomInAction
= new Action() {
1367 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1368 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1369 zoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1371 return zoomInAction
;
1375 * Get the zoom out action
1377 * @return The Action object
1379 public Action
getZoomOutAction() {
1380 if (zoomOutAction
== null) {
1381 zoomOutAction
= new Action() {
1387 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1388 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1389 zoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1391 return zoomOutAction
;
1395 private void adjustVerticalScrollBar() {
1396 int topIndex
= _stateCtrl
.getTopIndex();
1397 int countPerPage
= _stateCtrl
.countPerPage();
1398 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
1399 if (topIndex
+ countPerPage
> expandedElementCount
) {
1400 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1403 int selection
= _stateCtrl
.getTopIndex();
1405 int max
= Math
.max(1, expandedElementCount
- 1);
1406 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1408 int pageIncrement
= Math
.max(1, countPerPage
);
1409 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1413 * @param listener a {@link MenuDetectListener}
1414 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1417 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1418 _stateCtrl
.addTimeGraphEntryMenuListener(listener
);
1422 * @param listener a {@link MenuDetectListener}
1423 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1426 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1427 _stateCtrl
.removeTimeGraphEntryMenuListener(listener
);
1431 * @param listener a {@link MenuDetectListener}
1432 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1435 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1436 _stateCtrl
.addTimeEventMenuListener(listener
);
1440 * @param listener a {@link MenuDetectListener}
1441 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1444 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1445 _stateCtrl
.removeTimeEventMenuListener(listener
);
1449 * @param filter The filter object to be attached to the view
1452 public void addFilter(ViewerFilter filter
) {
1453 _stateCtrl
.addFilter(filter
);
1458 * @param filter The filter object to be attached to the view
1461 public void removeFilter(ViewerFilter filter
) {
1462 _stateCtrl
.removeFilter(filter
);