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
.MouseEvent
;
41 import org
.eclipse
.swt
.events
.MouseWheelListener
;
42 import org
.eclipse
.swt
.events
.SelectionAdapter
;
43 import org
.eclipse
.swt
.events
.SelectionEvent
;
44 import org
.eclipse
.swt
.events
.SelectionListener
;
45 import org
.eclipse
.swt
.graphics
.Rectangle
;
46 import org
.eclipse
.swt
.layout
.FillLayout
;
47 import org
.eclipse
.swt
.layout
.GridData
;
48 import org
.eclipse
.swt
.layout
.GridLayout
;
49 import org
.eclipse
.swt
.widgets
.Composite
;
50 import org
.eclipse
.swt
.widgets
.Control
;
51 import org
.eclipse
.swt
.widgets
.ScrollBar
;
52 import org
.eclipse
.swt
.widgets
.Slider
;
55 * Generic time graph viewer implementation
58 * @author Patrick Tasse, and others
60 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
63 private long _minTimeInterval
;
64 private long _selectedTime
;
65 private ITimeGraphEntry _selectedEntry
;
66 private long _beginTime
;
67 private long _endTime
;
72 private long _time0_extSynch
= 0;
73 private long _time1_extSynch
= 0;
74 private boolean _timeRangeFixed
;
75 private int _nameWidthPref
= 200;
76 private int _minNameWidth
= 6;
77 private int _nameWidth
;
78 private Composite _dataViewer
;
80 private TimeGraphControl _stateCtrl
;
81 private TimeGraphScale _timeScaleCtrl
;
82 private Slider _verticalScrollBar
;
83 private TimeGraphTooltipHandler _threadTip
;
84 private TimeGraphColorScheme _colors
;
85 private ITimeGraphPresentationProvider fTimeGraphProvider
;
87 ArrayList
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
88 ArrayList
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
89 ArrayList
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
91 // Calender Time format, using Epoch reference or Relative time
93 private boolean calendarTimeFormat
= false;
94 private int borderWidth
= 0;
95 private int timeScaleHeight
= 22;
97 private Action resetScale
;
98 private Action showLegendAction
;
99 private Action nextEventAction
;
100 private Action prevEventAction
;
101 private Action nextItemAction
;
102 private Action previousItemAction
;
103 private Action zoomInAction
;
104 private Action zoomOutAction
;
107 * Standard constructor
110 * The parent UI composite object
114 public TimeGraphViewer(Composite parent
, int style
) {
115 createDataViewer(parent
, style
);
119 * Sets the timegraph provider used by this timegraph viewer.
121 * @param timeGraphProvider the timegraph provider
123 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
124 fTimeGraphProvider
= timeGraphProvider
;
125 _stateCtrl
.setTimeGraphProvider(timeGraphProvider
);
126 _threadTip
= new TimeGraphTooltipHandler(_dataViewer
.getShell(), fTimeGraphProvider
, this);
127 _threadTip
.activateHoverHelp(_stateCtrl
);
131 * Sets or clears the input for this time graph viewer.
132 * The input array should only contain top-level elements.
134 * @param input the input of this time graph viewer, or <code>null</code> if none
136 public void setInput(ITimeGraphEntry
[] input
) {
137 if (null != _stateCtrl
) {
139 input
= new ITimeGraphEntry
[0];
142 _verticalScrollBar
.setEnabled(true);
145 _selectedEntry
= null;
146 refreshAllData(input
);
153 public void refresh() {
154 setInput(_stateCtrl
.getTraces());
158 * Callback for when the control is moved
163 public void controlMoved(ControlEvent e
) {
167 * Callback for when the control is resized
172 public void controlResized(ControlEvent e
) {
177 * Handler for when the model is updated. Called from the display order in
181 * The traces in the model
186 * @param updateTimeBounds
187 * Should we updated the time bounds too
189 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
190 long end
, boolean updateTimeBounds
) {
191 if (null != _stateCtrl
) {
193 updateInternalData(traces
, start
, end
);
194 if (updateTimeBounds
) {
195 _timeRangeFixed
= true;
196 // set window to match limits
197 setStartFinishTime(_time0_
, _time1_
);
200 _timeScaleCtrl
.redraw();
205 protected String
getViewTypeStr() {
206 return "viewoption.threads"; //$NON-NLS-1$
209 int getMarginWidth(int idx
) {
213 int getMarginHeight(int idx
) {
218 _minTimeInterval
= 1;
220 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
221 _nameWidthPref
, _minNameWidth
, 1000);
225 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
228 protected Control
createDataViewer(Composite parent
, int style
) {
230 _colors
= new TimeGraphColorScheme();
231 _dataViewer
= new Composite(parent
, style
) {
233 public void redraw() {
234 _timeScaleCtrl
.redraw();
239 GridLayout gl
= new GridLayout(2, false);
240 gl
.marginHeight
= borderWidth
;
242 gl
.verticalSpacing
= 0;
243 gl
.horizontalSpacing
= 0;
244 _dataViewer
.setLayout(gl
);
246 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
247 _timeScaleCtrl
.setTimeProvider(this);
248 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
249 _timeScaleCtrl
.setHeight(timeScaleHeight
);
251 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
252 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
253 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
255 public void widgetSelected(SelectionEvent e
) {
256 setTopIndex(_verticalScrollBar
.getSelection());
259 _verticalScrollBar
.setEnabled(false);
261 _stateCtrl
= createTimeGraphControl();
263 _stateCtrl
.setTimeProvider(this);
264 _stateCtrl
.addSelectionListener(this);
265 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
266 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
268 public void mouseScrolled(MouseEvent e
) {
269 adjustVerticalScrollBar();
272 _stateCtrl
.addKeyListener(new KeyAdapter() {
274 public void keyPressed(KeyEvent e
) {
275 adjustVerticalScrollBar();
279 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
280 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
281 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
282 filler
.setLayoutData(gd
);
283 filler
.setLayout(new FillLayout());
285 _stateCtrl
.addControlListener(new ControlAdapter() {
287 public void controlResized(ControlEvent event
) {
292 _dataViewer
.update();
293 adjustVerticalScrollBar();
300 public void dispose() {
302 _stateCtrl
.dispose();
303 _dataViewer
.dispose();
307 protected TimeGraphControl
createTimeGraphControl() {
308 return new TimeGraphControl(_dataViewer
, _colors
);
312 * Resize the controls
314 public void resizeControls() {
315 Rectangle r
= _dataViewer
.getClientArea();
321 if (_nameWidth
> width
- _minNameWidth
) {
322 _nameWidth
= width
- _minNameWidth
;
324 if (_nameWidth
< _minNameWidth
) {
325 _nameWidth
= _minNameWidth
;
327 adjustVerticalScrollBar();
331 * Try to set most convenient time range for display.
334 * The traces in the model
336 public void setTimeRange(ITimeGraphEntry traces
[]) {
339 for (int i
= 0; i
< traces
.length
; i
++) {
340 ITimeGraphEntry entry
= traces
[i
];
341 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
342 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
343 _beginTime
= entry
.getStartTime();
345 if (entry
.getEndTime() > _endTime
) {
346 _endTime
= entry
.getEndTime();
351 if (_beginTime
< 0) {
357 * Recalculate the time bounds
359 public void setTimeBounds() {
360 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
361 _time0_
= _beginTime
;
365 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
367 // _time0_ = Math.floor(_time0_);
368 // _time1_ = Math.ceil(_time1_);
369 if (!_timeRangeFixed
) {
373 if (_time1
- _time0
< _minTimeInterval
) {
374 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
383 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
384 if (null == traces
) {
385 traces
= new ITimeGraphEntry
[0];
387 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
388 // Start and end time are unspecified and need to be determined from
389 // individual processes
390 setTimeRange(traces
);
396 refreshAllData(traces
);
402 private void refreshAllData(ITimeGraphEntry
[] traces
) {
404 if (_selectedTime
< _beginTime
) {
405 _selectedTime
= _beginTime
;
406 } else if (_selectedTime
> _endTime
) {
407 _selectedTime
= _endTime
;
409 _stateCtrl
.refreshData(traces
);
410 _timeScaleCtrl
.redraw();
411 adjustVerticalScrollBar();
415 * Callback for when this view is focused
417 public void setFocus() {
418 if (null != _stateCtrl
) {
419 _stateCtrl
.setFocus();
424 * Get the current focus status of this view.
426 * @return If the view is currently focused, or not
428 public boolean isInFocus() {
429 return _stateCtrl
.isInFocus();
433 * Get the view's current selection
435 * @return The entry that is selected
437 public ITimeGraphEntry
getSelection() {
438 return _stateCtrl
.getSelectedTrace();
442 * Get the index of the current selection
446 public int getSelectionIndex() {
447 return _stateCtrl
.getSelectedIndex();
451 public long getTime0() {
456 public long getTime1() {
461 public long getMinTimeInterval() {
462 return _minTimeInterval
;
466 public int getNameSpace() {
471 public void setNameSpace(int width
) {
473 width
= _stateCtrl
.getClientArea().width
;
474 if (_nameWidth
> width
- 6) {
475 _nameWidth
= width
- 6;
477 if (_nameWidth
< 6) {
480 _stateCtrl
.adjustScrolls();
482 _timeScaleCtrl
.redraw();
486 public int getTimeSpace() {
487 int w
= _stateCtrl
.getClientArea().width
;
488 return w
- _nameWidth
;
492 public long getSelectedTime() {
493 return _selectedTime
;
497 public long getBeginTime() {
502 public long getEndTime() {
507 public long getMaxTime() {
512 public long getMinTime() {
520 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
521 * #setStartFinishTimeNotify(long, long)
524 public void setStartFinishTimeNotify(long time0
, long time1
) {
525 setStartFinishTime(time0
, time1
);
526 notifyRangeListeners(time0
, time1
);
531 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
534 public void notifyStartFinishTime() {
535 notifyRangeListeners(_time0
, _time1
);
542 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
543 * #setStartFinishTime(long, long)
546 public void setStartFinishTime(long time0
, long time1
) {
548 if (_time0
< _time0_
) {
551 if (_time0
> _time1_
) {
555 if (_time1
< _time0_
) {
558 if (_time1
> _time1_
) {
561 if (_time1
- _time0
< _minTimeInterval
) {
562 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
564 _timeRangeFixed
= true;
565 _stateCtrl
.adjustScrolls();
567 _timeScaleCtrl
.redraw();
571 * Set the time bounds to the provided values
574 * The start time of the window
578 public void setTimeBounds(long beginTime
, long endTime
) {
579 _beginTime
= beginTime
;
583 _stateCtrl
.adjustScrolls();
587 public void resetStartFinishTime() {
588 setStartFinishTimeNotify(_time0_
, _time1_
);
589 _timeRangeFixed
= false;
593 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
594 setSelectedTimeInt(time
, ensureVisible
, true);
598 public void setSelectedTime(long time
, boolean ensureVisible
) {
599 setSelectedTimeInt(time
, ensureVisible
, false);
602 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
606 long timeSpace
= (long) ((_time1
- _time0
) * .02);
607 long timeMid
= (long) ((_time1
- _time0
) * .5);
608 if (time
< _time0
+ timeSpace
) {
609 long dt
= _time0
- time
+ timeMid
;
612 } else if (time
> _time1
- timeSpace
) {
613 long dt
= time
- _time1
+ timeMid
;
617 if (_time0
< _time0_
) {
618 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
620 } else if (_time1
> _time1_
) {
621 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
625 if (_time1
- _time0
< _minTimeInterval
) {
626 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
628 _stateCtrl
.adjustScrolls();
630 _timeScaleCtrl
.redraw();
633 boolean notifySelectedTime
= (time
!= _selectedTime
);
634 _selectedTime
= time
;
636 if (doNotify
&& ((time0
!= _time0
) || (time1
!= _time1
))) {
637 notifyRangeListeners(_time0
, _time1
);
640 if (doNotify
&& notifySelectedTime
) {
641 notifyTimeListeners(_selectedTime
);
646 public void widgetDefaultSelected(SelectionEvent e
) {
647 if (_selectedEntry
!= getSelection()) {
648 _selectedEntry
= getSelection();
649 notifySelectionListeners(_selectedEntry
);
654 public void widgetSelected(SelectionEvent e
) {
655 if (_selectedEntry
!= getSelection()) {
656 _selectedEntry
= getSelection();
657 notifySelectionListeners(_selectedEntry
);
662 * Callback for when the next event is selected
664 public void selectNextEvent() {
665 _stateCtrl
.selectNextEvent();
666 adjustVerticalScrollBar();
670 * Callback for when the previous event is selected
672 public void selectPrevEvent() {
673 _stateCtrl
.selectPrevEvent();
674 adjustVerticalScrollBar();
678 * Callback for when the next item is selected
680 public void selectNextItem() {
681 _stateCtrl
.selectNextTrace();
682 adjustVerticalScrollBar();
686 * Callback for when the previous item is selected
688 public void selectPrevItem() {
689 _stateCtrl
.selectPrevTrace();
690 adjustVerticalScrollBar();
694 * Callback for the show legend action
696 public void showLegend() {
697 if (_dataViewer
== null || _dataViewer
.isDisposed()) {
701 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
705 * Callback for the Zoom In action
707 public void zoomIn() {
712 * Callback for the Zoom Out action
714 public void zoomOut() {
715 _stateCtrl
.zoomOut();
718 private String
getPreferenceString(String string
) {
719 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
723 * Add a selection listener
726 * The listener to add
728 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
729 fSelectionListeners
.add(listener
);
733 * Remove a selection listener
736 * The listener to remove
738 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
739 fSelectionListeners
.remove(listener
);
742 private void notifySelectionListeners(ITimeGraphEntry selection
) {
743 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
745 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
746 listener
.selectionChanged(event
);
751 * Add a time listener
754 * The listener to add
756 public void addTimeListener(ITimeGraphTimeListener listener
) {
757 fTimeListeners
.add(listener
);
761 * Remove a time listener
764 * The listener to remove
766 public void removeTimeListener(ITimeGraphTimeListener listener
) {
767 fTimeListeners
.remove(listener
);
770 private void notifyTimeListeners(long time
) {
771 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
773 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
774 listener
.timeSelected(event
);
779 * Add a range listener
782 * The listener to add
784 public void addRangeListener(ITimeGraphRangeListener listener
) {
785 fRangeListeners
.add(listener
);
789 * Remove a range listener
792 * The listener to remove
794 public void removeRangeListener(ITimeGraphRangeListener listener
) {
795 fRangeListeners
.remove(listener
);
798 private void notifyRangeListeners(long startTime
, long endTime
) {
799 // Check if the time has actually changed from last notification
800 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
801 // Notify Time Scale Selection Listeners
802 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
804 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
805 listener
.timeRangeUpdated(event
);
808 // update external synch timers
809 updateExtSynchTimers();
814 * Callback to set a selected event in the view
817 * The event that was selected
819 * The source of this selection event
821 public void setSelectedEvent(ITimeEvent event
, Object source
) {
822 if (event
== null || source
== this) {
825 _selectedEntry
= event
.getEntry();
826 _stateCtrl
.selectItem(_selectedEntry
, false);
828 setSelectedTimeInt(event
.getTime(), true, true);
829 adjustVerticalScrollBar();
833 * Set the seeked time of a trace
836 * The trace that was seeked
840 * The source of this seek event
842 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
843 if (trace
== null || source
== this) {
846 _selectedEntry
= trace
;
847 _stateCtrl
.selectItem(trace
, false);
849 setSelectedTimeInt(time
, true, true);
853 * Callback for a trace selection
856 * The trace that was selected
858 public void setSelection(ITimeGraphEntry trace
) {
859 _selectedEntry
= trace
;
860 _stateCtrl
.selectItem(trace
, false);
861 adjustVerticalScrollBar();
865 * Callback for a time window selection
868 * Start time of the range
870 * End time of the range
872 * Source of the event
874 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
875 if (source
== this) {
879 setStartFinishTime(time0
, time1
);
881 // update notification time values since we are now in synch with the
882 // external application
883 updateExtSynchTimers();
887 * update the cache timers used to identify the need to send a time window
888 * update to external registered listeners
890 private void updateExtSynchTimers() {
891 // last time notification cache
892 _time0_extSynch
= _time0
;
893 _time1_extSynch
= _time1
;
897 * Set the calendar format
899 * @param toAbsoluteCaltime
900 * True for absolute time, false for relative
902 public void setTimeCalendarFormat(boolean toAbsoluteCaltime
) {
903 calendarTimeFormat
= toAbsoluteCaltime
;
907 public boolean isCalendarFormat() {
908 return calendarTimeFormat
;
912 * Retrieve the border width
916 public int getBorderWidth() {
921 * Set the border width
926 public void setBorderWidth(int borderWidth
) {
927 if (borderWidth
> -1) {
928 this.borderWidth
= borderWidth
;
929 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
930 gl
.marginHeight
= borderWidth
;
935 * Retrieve the height of the header
939 public int getHeaderHeight() {
940 return timeScaleHeight
;
944 * Set the height of the header
946 * @param headerHeight
949 public void setHeaderHeight(int headerHeight
) {
950 if (headerHeight
> -1) {
951 this.timeScaleHeight
= headerHeight
;
952 _timeScaleCtrl
.setHeight(headerHeight
);
957 * Retrieve the height of an item row
961 public int getItemHeight() {
962 if (_stateCtrl
!= null) {
963 return _stateCtrl
.getItemHeight();
969 * Set the height of an item row
974 public void setItemHeight(int rowHeight
) {
975 if (_stateCtrl
!= null) {
976 _stateCtrl
.setItemHeight(rowHeight
);
981 * Set the minimum item width
986 public void setMinimumItemWidth(int width
) {
987 if (_stateCtrl
!= null) {
988 _stateCtrl
.setMinimumItemWidth(width
);
993 * Set the width for the name column
995 * @param width The width
997 public void setNameWidthPref(int width
) {
998 _nameWidthPref
= width
;
1006 * Retrieve the configure width for the name column
1012 public int getNameWidthPref(int width
) {
1013 return _nameWidthPref
;
1017 * Returns the primary control associated with this viewer.
1019 * @return the SWT control which displays this viewer's content
1021 public Control
getControl() {
1026 * Returns the time graph control associated with this viewer.
1028 * @return the time graph control
1030 TimeGraphControl
getTimeGraphControl() {
1035 * Returns the time graph scale associated with this viewer.
1037 * @return the time graph scale
1039 TimeGraphScale
getTimeGraphScale() {
1040 return _timeScaleCtrl
;
1044 * Get the selection provider
1046 * @return the selection provider
1048 public ISelectionProvider
getSelectionProvider() {
1053 * Wait for the cursor
1056 * Wait indefinitely?
1058 public void waitCursor(boolean waitInd
) {
1059 _stateCtrl
.waitCursor(waitInd
);
1063 * Get the horizontal scroll bar object
1065 * @return The scroll bar
1067 public ScrollBar
getHorizontalBar() {
1068 return _stateCtrl
.getHorizontalBar();
1072 * Get the vertical scroll bar object
1074 * @return The scroll bar
1076 public Slider
getVerticalBar() {
1077 return _verticalScrollBar
;
1081 * Set the given index as the top one
1084 * The index that will go to the top
1086 public void setTopIndex(int index
) {
1087 _stateCtrl
.setTopIndex(index
);
1088 adjustVerticalScrollBar();
1092 * Retrieve the current top index
1094 * @return The top index
1096 public int getTopIndex() {
1097 return _stateCtrl
.getTopIndex();
1101 * Set the expanded state of an entry
1104 * The entry to expand/collapse
1106 * True for expanded, false for collapsed
1108 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
1109 _stateCtrl
.setExpandedState(entry
, expanded
);
1110 adjustVerticalScrollBar();
1114 * Collapses all nodes of the viewer's tree, starting with the root.
1118 public void collapseAll() {
1119 _stateCtrl
.collapseAll();
1120 adjustVerticalScrollBar();
1124 * Expands all nodes of the viewer's tree, starting with the root.
1128 public void expandAll() {
1129 _stateCtrl
.expandAll();
1130 adjustVerticalScrollBar();
1134 * Get the number of sub-elements when expanded
1136 * @return The element count
1138 public int getExpandedElementCount() {
1139 return _stateCtrl
.getExpandedElementCount();
1143 * Get the sub-elements
1145 * @return The array of entries that are below this one
1147 public ITimeGraphEntry
[] getExpandedElements() {
1148 return _stateCtrl
.getExpandedElements();
1152 * Add a tree listener
1155 * The listener to add
1157 public void addTreeListener(ITimeGraphTreeListener listener
) {
1158 _stateCtrl
.addTreeListener(listener
);
1162 * Remove a tree listener
1165 * The listener to remove
1167 public void removeTreeListener(ITimeGraphTreeListener listener
) {
1168 _stateCtrl
.removeTreeListener(listener
);
1172 * Get the reset scale action.
1174 * @return The Action object
1176 public Action
getResetScaleAction() {
1177 if (resetScale
== null) {
1179 resetScale
= new Action() {
1182 resetStartFinishTime();
1185 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
1186 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
1187 resetScale
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
1193 * Get the show legend action.
1195 * @return The Action object
1197 public Action
getShowLegendAction() {
1198 if (showLegendAction
== null) {
1200 showLegendAction
= new Action() {
1206 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
1207 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
1208 showLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
1211 return showLegendAction
;
1215 * Get the the next event action.
1217 * @return The action object
1219 public Action
getNextEventAction() {
1220 if (nextEventAction
== null) {
1221 nextEventAction
= new Action() {
1228 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1229 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1230 nextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1233 return nextEventAction
;
1237 * Get the previous event action.
1239 * @return The Action object
1241 public Action
getPreviousEventAction() {
1242 if (prevEventAction
== null) {
1243 prevEventAction
= new Action() {
1250 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1251 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1252 prevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1255 return prevEventAction
;
1259 * Get the next item action.
1261 * @return The Action object
1263 public Action
getNextItemAction() {
1264 if (nextItemAction
== null) {
1266 nextItemAction
= new Action() {
1272 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1273 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1274 nextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
1276 return nextItemAction
;
1280 * Get the previous item action.
1282 * @return The Action object
1284 public Action
getPreviousItemAction() {
1285 if (previousItemAction
== null) {
1287 previousItemAction
= new Action() {
1293 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1294 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1295 previousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
1297 return previousItemAction
;
1301 * Get the zoom in action
1303 * @return The Action object
1305 public Action
getZoomInAction() {
1306 if (zoomInAction
== null) {
1307 zoomInAction
= new Action() {
1313 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
1314 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
1315 zoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
1317 return zoomInAction
;
1321 * Get the zoom out action
1323 * @return The Action object
1325 public Action
getZoomOutAction() {
1326 if (zoomOutAction
== null) {
1327 zoomOutAction
= new Action() {
1333 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1334 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1335 zoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1337 return zoomOutAction
;
1341 private void adjustVerticalScrollBar() {
1342 int topIndex
= _stateCtrl
.getTopIndex();
1343 int countPerPage
= _stateCtrl
.countPerPage();
1344 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
1345 if (topIndex
+ countPerPage
> expandedElementCount
) {
1346 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1349 int selection
= _stateCtrl
.getTopIndex();
1351 int max
= Math
.max(1, expandedElementCount
- 1);
1352 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1354 int pageIncrement
= Math
.max(1, countPerPage
);
1355 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);