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
.MenuDetectEvent
;
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 // Calender Time format, using Epoch reference or Relative time
95 private boolean calendarTimeFormat
= false;
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 if (null != _stateCtrl
) {
141 input
= new ITimeGraphEntry
[0];
144 _verticalScrollBar
.setEnabled(true);
147 _selectedEntry
= null;
148 refreshAllData(input
);
155 public void refresh() {
156 setInput(_stateCtrl
.getTraces());
160 * Callback for when the control is moved
165 public void controlMoved(ControlEvent e
) {
169 * Callback for when the control is resized
174 public void controlResized(ControlEvent e
) {
179 * Handler for when the model is updated. Called from the display order in
183 * The traces in the model
188 * @param updateTimeBounds
189 * Should we updated the time bounds too
191 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
192 long end
, boolean updateTimeBounds
) {
193 if (null != _stateCtrl
) {
195 updateInternalData(traces
, start
, end
);
196 if (updateTimeBounds
) {
197 _timeRangeFixed
= true;
198 // set window to match limits
199 setStartFinishTime(_time0_
, _time1_
);
202 _timeScaleCtrl
.redraw();
207 protected String
getViewTypeStr() {
208 return "viewoption.threads"; //$NON-NLS-1$
211 int getMarginWidth(int idx
) {
215 int getMarginHeight(int idx
) {
220 _minTimeInterval
= 1;
222 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
223 _nameWidthPref
, _minNameWidth
, 1000);
227 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
230 protected Control
createDataViewer(Composite parent
, int style
) {
232 _colors
= new TimeGraphColorScheme();
233 _dataViewer
= new Composite(parent
, style
) {
235 public void redraw() {
236 _timeScaleCtrl
.redraw();
241 GridLayout gl
= new GridLayout(2, false);
242 gl
.marginHeight
= borderWidth
;
244 gl
.verticalSpacing
= 0;
245 gl
.horizontalSpacing
= 0;
246 _dataViewer
.setLayout(gl
);
248 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
249 _timeScaleCtrl
.setTimeProvider(this);
250 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
251 _timeScaleCtrl
.setHeight(timeScaleHeight
);
253 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
254 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
255 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
257 public void widgetSelected(SelectionEvent e
) {
258 setTopIndex(_verticalScrollBar
.getSelection());
261 _verticalScrollBar
.setEnabled(false);
263 _stateCtrl
= createTimeGraphControl();
265 _stateCtrl
.setTimeProvider(this);
266 _stateCtrl
.addSelectionListener(this);
267 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
268 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
270 public void mouseScrolled(MouseEvent e
) {
271 adjustVerticalScrollBar();
274 _stateCtrl
.addKeyListener(new KeyAdapter() {
276 public void keyPressed(KeyEvent e
) {
277 adjustVerticalScrollBar();
281 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
282 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
283 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
284 filler
.setLayoutData(gd
);
285 filler
.setLayout(new FillLayout());
287 _stateCtrl
.addControlListener(new ControlAdapter() {
289 public void controlResized(ControlEvent event
) {
294 _dataViewer
.update();
295 adjustVerticalScrollBar();
302 public void dispose() {
304 _stateCtrl
.dispose();
305 _dataViewer
.dispose();
309 protected TimeGraphControl
createTimeGraphControl() {
310 return new TimeGraphControl(_dataViewer
, _colors
);
314 * Resize the controls
316 public void resizeControls() {
317 Rectangle r
= _dataViewer
.getClientArea();
323 if (_nameWidth
> width
- _minNameWidth
) {
324 _nameWidth
= width
- _minNameWidth
;
326 if (_nameWidth
< _minNameWidth
) {
327 _nameWidth
= _minNameWidth
;
329 adjustVerticalScrollBar();
333 * Try to set most convenient time range for display.
336 * The traces in the model
338 public void setTimeRange(ITimeGraphEntry traces
[]) {
341 for (int i
= 0; i
< traces
.length
; i
++) {
342 ITimeGraphEntry entry
= traces
[i
];
343 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
344 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
345 _beginTime
= entry
.getStartTime();
347 if (entry
.getEndTime() > _endTime
) {
348 _endTime
= entry
.getEndTime();
353 if (_beginTime
< 0) {
359 * Recalculate the time bounds
361 public void setTimeBounds() {
362 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
363 _time0_
= _beginTime
;
367 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
369 // _time0_ = Math.floor(_time0_);
370 // _time1_ = Math.ceil(_time1_);
371 if (!_timeRangeFixed
) {
375 if (_time1
- _time0
< _minTimeInterval
) {
376 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
385 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
386 if (null == traces
) {
387 traces
= new ITimeGraphEntry
[0];
389 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
390 // Start and end time are unspecified and need to be determined from
391 // individual processes
392 setTimeRange(traces
);
398 refreshAllData(traces
);
404 private void refreshAllData(ITimeGraphEntry
[] traces
) {
406 if (_selectedTime
< _beginTime
) {
407 _selectedTime
= _beginTime
;
408 } else if (_selectedTime
> _endTime
) {
409 _selectedTime
= _endTime
;
411 _stateCtrl
.refreshData(traces
);
412 _timeScaleCtrl
.redraw();
413 adjustVerticalScrollBar();
417 * Callback for when this view is focused
419 public void setFocus() {
420 if (null != _stateCtrl
) {
421 _stateCtrl
.setFocus();
426 * Get the current focus status of this view.
428 * @return If the view is currently focused, or not
430 public boolean isInFocus() {
431 return _stateCtrl
.isInFocus();
435 * Get the view's current selection
437 * @return The entry that is selected
439 public ITimeGraphEntry
getSelection() {
440 return _stateCtrl
.getSelectedTrace();
444 * Get the index of the current selection
448 public int getSelectionIndex() {
449 return _stateCtrl
.getSelectedIndex();
453 public long getTime0() {
458 public long getTime1() {
463 public long getMinTimeInterval() {
464 return _minTimeInterval
;
468 public int getNameSpace() {
473 public void setNameSpace(int width
) {
475 width
= _stateCtrl
.getClientArea().width
;
476 if (_nameWidth
> width
- 6) {
477 _nameWidth
= width
- 6;
479 if (_nameWidth
< 6) {
482 _stateCtrl
.adjustScrolls();
484 _timeScaleCtrl
.redraw();
488 public int getTimeSpace() {
489 int w
= _stateCtrl
.getClientArea().width
;
490 return w
- _nameWidth
;
494 public long getSelectedTime() {
495 return _selectedTime
;
499 public long getBeginTime() {
504 public long getEndTime() {
509 public long getMaxTime() {
514 public long getMinTime() {
522 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
523 * #setStartFinishTimeNotify(long, long)
526 public void setStartFinishTimeNotify(long time0
, long time1
) {
527 setStartFinishTime(time0
, time1
);
528 notifyRangeListeners(time0
, time1
);
533 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
536 public void notifyStartFinishTime() {
537 notifyRangeListeners(_time0
, _time1
);
544 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
545 * #setStartFinishTime(long, long)
548 public void setStartFinishTime(long time0
, long time1
) {
550 if (_time0
< _time0_
) {
553 if (_time0
> _time1_
) {
557 if (_time1
< _time0_
) {
560 if (_time1
> _time1_
) {
563 if (_time1
- _time0
< _minTimeInterval
) {
564 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
566 _timeRangeFixed
= true;
567 _stateCtrl
.adjustScrolls();
569 _timeScaleCtrl
.redraw();
573 * Set the time bounds to the provided values
576 * The start time of the window
580 public void setTimeBounds(long beginTime
, long endTime
) {
581 _beginTime
= beginTime
;
585 _stateCtrl
.adjustScrolls();
589 public void resetStartFinishTime() {
590 setStartFinishTimeNotify(_time0_
, _time1_
);
591 _timeRangeFixed
= false;
595 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
596 setSelectedTimeInt(time
, ensureVisible
, true);
600 public void setSelectedTime(long time
, boolean ensureVisible
) {
601 setSelectedTimeInt(time
, ensureVisible
, false);
604 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
608 long timeSpace
= (long) ((_time1
- _time0
) * .02);
609 long timeMid
= (long) ((_time1
- _time0
) * .5);
610 if (time
< _time0
+ timeSpace
) {
611 long dt
= _time0
- time
+ timeMid
;
614 } else if (time
> _time1
- timeSpace
) {
615 long dt
= time
- _time1
+ timeMid
;
619 if (_time0
< _time0_
) {
620 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
622 } else if (_time1
> _time1_
) {
623 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
627 if (_time1
- _time0
< _minTimeInterval
) {
628 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
630 _stateCtrl
.adjustScrolls();
632 _timeScaleCtrl
.redraw();
635 boolean notifySelectedTime
= (time
!= _selectedTime
);
636 _selectedTime
= time
;
638 if (doNotify
&& ((time0
!= _time0
) || (time1
!= _time1
))) {
639 notifyRangeListeners(_time0
, _time1
);
642 if (doNotify
&& notifySelectedTime
) {
643 notifyTimeListeners(_selectedTime
);
648 public void widgetDefaultSelected(SelectionEvent e
) {
649 if (_selectedEntry
!= getSelection()) {
650 _selectedEntry
= getSelection();
651 notifySelectionListeners(_selectedEntry
);
656 public void widgetSelected(SelectionEvent e
) {
657 if (_selectedEntry
!= getSelection()) {
658 _selectedEntry
= getSelection();
659 notifySelectionListeners(_selectedEntry
);
664 * Callback for when the next event is selected
666 public void selectNextEvent() {
667 _stateCtrl
.selectNextEvent();
668 adjustVerticalScrollBar();
672 * Callback for when the previous event is selected
674 public void selectPrevEvent() {
675 _stateCtrl
.selectPrevEvent();
676 adjustVerticalScrollBar();
680 * Callback for when the next item is selected
682 public void selectNextItem() {
683 _stateCtrl
.selectNextTrace();
684 adjustVerticalScrollBar();
688 * Callback for when the previous item is selected
690 public void selectPrevItem() {
691 _stateCtrl
.selectPrevTrace();
692 adjustVerticalScrollBar();
696 * Callback for the show legend action
698 public void showLegend() {
699 if (_dataViewer
== null || _dataViewer
.isDisposed()) {
703 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
707 * Callback for the Zoom In action
709 public void zoomIn() {
714 * Callback for the Zoom Out action
716 public void zoomOut() {
717 _stateCtrl
.zoomOut();
720 private String
getPreferenceString(String string
) {
721 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
725 * Add a selection listener
728 * The listener to add
730 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
731 fSelectionListeners
.add(listener
);
735 * Remove a selection listener
738 * The listener to remove
740 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
741 fSelectionListeners
.remove(listener
);
744 private void notifySelectionListeners(ITimeGraphEntry selection
) {
745 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
747 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
748 listener
.selectionChanged(event
);
753 * Add a time listener
756 * The listener to add
758 public void addTimeListener(ITimeGraphTimeListener listener
) {
759 fTimeListeners
.add(listener
);
763 * Remove a time listener
766 * The listener to remove
768 public void removeTimeListener(ITimeGraphTimeListener listener
) {
769 fTimeListeners
.remove(listener
);
772 private void notifyTimeListeners(long time
) {
773 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
775 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
776 listener
.timeSelected(event
);
781 * Add a range listener
784 * The listener to add
786 public void addRangeListener(ITimeGraphRangeListener listener
) {
787 fRangeListeners
.add(listener
);
791 * Remove a range listener
794 * The listener to remove
796 public void removeRangeListener(ITimeGraphRangeListener listener
) {
797 fRangeListeners
.remove(listener
);
800 private void notifyRangeListeners(long startTime
, long endTime
) {
801 // Check if the time has actually changed from last notification
802 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
803 // Notify Time Scale Selection Listeners
804 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
806 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
807 listener
.timeRangeUpdated(event
);
810 // update external synch timers
811 updateExtSynchTimers();
816 * Callback to set a selected event in the view
819 * The event that was selected
821 * The source of this selection event
823 public void setSelectedEvent(ITimeEvent event
, Object source
) {
824 if (event
== null || source
== this) {
827 _selectedEntry
= event
.getEntry();
828 _stateCtrl
.selectItem(_selectedEntry
, false);
830 setSelectedTimeInt(event
.getTime(), true, true);
831 adjustVerticalScrollBar();
835 * Set the seeked time of a trace
838 * The trace that was seeked
842 * The source of this seek event
844 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
845 if (trace
== null || source
== this) {
848 _selectedEntry
= trace
;
849 _stateCtrl
.selectItem(trace
, false);
851 setSelectedTimeInt(time
, true, true);
855 * Callback for a trace selection
858 * The trace that was selected
860 public void setSelection(ITimeGraphEntry trace
) {
861 _selectedEntry
= trace
;
862 _stateCtrl
.selectItem(trace
, false);
863 adjustVerticalScrollBar();
867 * Callback for a time window selection
870 * Start time of the range
872 * End time of the range
874 * Source of the event
876 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
877 if (source
== this) {
881 setStartFinishTime(time0
, time1
);
883 // update notification time values since we are now in synch with the
884 // external application
885 updateExtSynchTimers();
889 * update the cache timers used to identify the need to send a time window
890 * update to external registered listeners
892 private void updateExtSynchTimers() {
893 // last time notification cache
894 _time0_extSynch
= _time0
;
895 _time1_extSynch
= _time1
;
899 * Set the calendar format
901 * @param toAbsoluteCaltime
902 * True for absolute time, false for relative
904 public void setTimeCalendarFormat(boolean toAbsoluteCaltime
) {
905 calendarTimeFormat
= toAbsoluteCaltime
;
909 public boolean isCalendarFormat() {
910 return calendarTimeFormat
;
914 * Retrieve the border width
918 public int getBorderWidth() {
923 * Set the border width
928 public void setBorderWidth(int borderWidth
) {
929 if (borderWidth
> -1) {
930 this.borderWidth
= borderWidth
;
931 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
932 gl
.marginHeight
= borderWidth
;
937 * Retrieve the height of the header
941 public int getHeaderHeight() {
942 return timeScaleHeight
;
946 * Set the height of the header
948 * @param headerHeight
951 public void setHeaderHeight(int headerHeight
) {
952 if (headerHeight
> -1) {
953 this.timeScaleHeight
= headerHeight
;
954 _timeScaleCtrl
.setHeight(headerHeight
);
959 * Retrieve the height of an item row
963 public int getItemHeight() {
964 if (_stateCtrl
!= null) {
965 return _stateCtrl
.getItemHeight();
971 * Set the height of an item row
976 public void setItemHeight(int rowHeight
) {
977 if (_stateCtrl
!= null) {
978 _stateCtrl
.setItemHeight(rowHeight
);
983 * Set the minimum item width
988 public void setMinimumItemWidth(int width
) {
989 if (_stateCtrl
!= null) {
990 _stateCtrl
.setMinimumItemWidth(width
);
995 * Set the width for the name column
997 * @param width The width
999 public void setNameWidthPref(int width
) {
1000 _nameWidthPref
= width
;
1008 * Retrieve the configure width for the name column
1014 public int getNameWidthPref(int width
) {
1015 return _nameWidthPref
;
1019 * Returns the primary control associated with this viewer.
1021 * @return the SWT control which displays this viewer's content
1023 public Control
getControl() {
1028 * Returns the time graph control associated with this viewer.
1030 * @return the time graph control
1032 TimeGraphControl
getTimeGraphControl() {
1037 * Returns the time graph scale associated with this viewer.
1039 * @return the time graph scale
1041 TimeGraphScale
getTimeGraphScale() {
1042 return _timeScaleCtrl
;
1046 * Get the selection provider
1048 * @return the selection provider
1050 public ISelectionProvider
getSelectionProvider() {
1055 * Wait for the cursor
1058 * Wait indefinitely?
1060 public void waitCursor(boolean waitInd
) {
1061 _stateCtrl
.waitCursor(waitInd
);
1065 * Get the horizontal scroll bar object
1067 * @return The scroll bar
1069 public ScrollBar
getHorizontalBar() {
1070 return _stateCtrl
.getHorizontalBar();
1074 * Get the vertical scroll bar object
1076 * @return The scroll bar
1078 public Slider
getVerticalBar() {
1079 return _verticalScrollBar
;
1083 * Set the given index as the top one
1086 * The index that will go to the top
1088 public void setTopIndex(int index
) {
1089 _stateCtrl
.setTopIndex(index
);
1090 adjustVerticalScrollBar();
1094 * Retrieve the current top index
1096 * @return The top index
1098 public int getTopIndex() {
1099 return _stateCtrl
.getTopIndex();
1103 * Set the expanded state of an entry
1106 * The entry to expand/collapse
1108 * True for expanded, false for collapsed
1110 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1111 _stateCtrl
.setExpandedState(entry
, expanded
);
1112 adjustVerticalScrollBar();
1116 * Get the number of sub-elements when expanded
1118 * @return The element count
1120 public int getExpandedElementCount() {
1121 return _stateCtrl
.getExpandedElementCount();
1125 * Get the sub-elements
1127 * @return The array of entries that are below this one
1129 public ITimeGraphEntry
[] getExpandedElements() {
1130 return _stateCtrl
.getExpandedElements();
1134 * Add a tree listener
1137 * The listener to add
1139 public void addTreeListener(ITimeGraphTreeListener listener
) {
1140 _stateCtrl
.addTreeListener(listener
);
1144 * Remove a tree listener
1147 * The listener to remove
1149 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1150 _stateCtrl
.removeTreeListener(listener
);
1154 * Get the reset scale action.
1156 * @return The Action object
1158 public Action
getResetScaleAction() {
1159 if (resetScale
== null) {
1161 resetScale
= new Action() {
1164 resetStartFinishTime();
1167 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1168 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1169 resetScale
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1175 * Get the show legend action.
1177 * @return The Action object
1179 public Action
getShowLegendAction() {
1180 if (showLegendAction
== null) {
1182 showLegendAction
= new Action() {
1188 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1189 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1190 showLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1193 return showLegendAction
;
1197 * Get the the next event action.
1199 * @return The action object
1201 public Action
getNextEventAction() {
1202 if (nextEventAction
== null) {
1203 nextEventAction
= new Action() {
1210 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1211 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1212 nextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1215 return nextEventAction
;
1219 * Get the previous event action.
1221 * @return The Action object
1223 public Action
getPreviousEventAction() {
1224 if (prevEventAction
== null) {
1225 prevEventAction
= new Action() {
1232 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1233 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1234 prevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1237 return prevEventAction
;
1241 * Get the next item action.
1243 * @return The Action object
1245 public Action
getNextItemAction() {
1246 if (nextItemAction
== null) {
1248 nextItemAction
= new Action() {
1254 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1255 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1256 nextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1258 return nextItemAction
;
1262 * Get the previous item action.
1264 * @return The Action object
1266 public Action
getPreviousItemAction() {
1267 if (previousItemAction
== null) {
1269 previousItemAction
= new Action() {
1275 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1276 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1277 previousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1279 return previousItemAction
;
1283 * Get the zoom in action
1285 * @return The Action object
1287 public Action
getZoomInAction() {
1288 if (zoomInAction
== null) {
1289 zoomInAction
= new Action() {
1295 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1296 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1297 zoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1299 return zoomInAction
;
1303 * Get the zoom out action
1305 * @return The Action object
1307 public Action
getZoomOutAction() {
1308 if (zoomOutAction
== null) {
1309 zoomOutAction
= new Action() {
1315 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1316 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1317 zoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1319 return zoomOutAction
;
1323 private void adjustVerticalScrollBar() {
1324 int topIndex
= _stateCtrl
.getTopIndex();
1325 int countPerPage
= _stateCtrl
.countPerPage();
1326 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
1327 if (topIndex
+ countPerPage
> expandedElementCount
) {
1328 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1331 int selection
= _stateCtrl
.getTopIndex();
1333 int max
= Math
.max(1, expandedElementCount
- 1);
1334 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1336 int pageIncrement
= Math
.max(1, countPerPage
);
1337 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);
1342 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1344 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1345 _stateCtrl
.addTimeGraphEntryMenuListener(listener
);
1350 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1352 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
1353 _stateCtrl
.removeTimeGraphEntryMenuListener(listener
);
1358 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1360 public void addTimeEventMenuListener(MenuDetectListener listener
) {
1361 _stateCtrl
.addTimeEventMenuListener(listener
);
1366 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1368 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
1369 _stateCtrl
.removeTimeEventMenuListener(listener
);