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
.ITmfImageConstants
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
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
;
54 public class TimeGraphViewer
implements ITimeDataProvider
, SelectionListener
{
57 private long _minTimeInterval
;
58 private long _selectedTime
;
59 private ITimeGraphEntry _selectedEntry
;
60 private long _beginTime
;
61 private long _endTime
;
66 private long _time0_extSynch
= 0;
67 private long _time1_extSynch
= 0;
68 private boolean _timeRangeFixed
;
69 private int _nameWidthPref
= 200;
70 private int _minNameWidth
= 6;
71 private int _nameWidth
;
72 private Composite _dataViewer
;
74 private TimeGraphControl _stateCtrl
;
75 private TimeGraphScale _timeScaleCtrl
;
76 private Slider _verticalScrollBar
;
77 private TimeGraphTooltipHandler _threadTip
;
78 private TimeGraphColorScheme _colors
;
79 private ITimeGraphPresentationProvider fTimeGraphProvider
;
81 ArrayList
<ITimeGraphSelectionListener
> fSelectionListeners
= new ArrayList
<ITimeGraphSelectionListener
>();
82 ArrayList
<ITimeGraphTimeListener
> fTimeListeners
= new ArrayList
<ITimeGraphTimeListener
>();
83 ArrayList
<ITimeGraphRangeListener
> fRangeListeners
= new ArrayList
<ITimeGraphRangeListener
>();
85 // Calender Time format, using Epoch reference or Relative time
87 private boolean calendarTimeFormat
= false;
88 private int borderWidth
= 4;
89 private int timeScaleHeight
= 22;
91 private Action resetScale
;
92 private Action showLegendAction
;
93 private Action nextEventAction
;
94 private Action prevEventAction
;
95 private Action nextItemAction
;
96 private Action previousItemAction
;
97 private Action zoomInAction
;
98 private Action zoomOutAction
;
101 public TimeGraphViewer(Composite parent
, int style
) {
102 createDataViewer(parent
, style
);
106 * Sets the timegraph provider used by this timegraph viewer.
108 * @param timeGraphProvider the timegraph provider
110 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
111 fTimeGraphProvider
= timeGraphProvider
;
112 _stateCtrl
.setTimeGraphProvider(timeGraphProvider
);
113 _threadTip
= new TimeGraphTooltipHandler(_dataViewer
.getShell(), fTimeGraphProvider
, this);
114 _threadTip
.activateHoverHelp(_stateCtrl
);
118 * Sets or clears the input for this time graph viewer.
119 * The input array should only contain top-level elements.
121 * @param input the input of this time graph viewer, or <code>null</code> if none
123 public void setInput(ITimeGraphEntry
[] input
) {
124 if (null != _stateCtrl
) {
126 input
= new ITimeGraphEntry
[0];
129 _verticalScrollBar
.setEnabled(true);
131 refreshAllData(input
);
135 public void refresh() {
136 setInput(_stateCtrl
.getTraces());
139 public void controlMoved(ControlEvent e
) {
142 public void controlResized(ControlEvent e
) {
146 // called from the display order in the API
147 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
148 long end
, boolean updateTimeBounds
) {
149 if (null != _stateCtrl
) {
151 updateInternalData(traces
, start
, end
);
152 if (updateTimeBounds
) {
153 _timeRangeFixed
= true;
154 // set window to match limits
155 setStartFinishTime(_time0_
, _time1_
);
158 _timeScaleCtrl
.redraw();
163 protected String
getViewTypeStr() {
164 return "viewoption.threads"; //$NON-NLS-1$
167 int getMarginWidth(int idx
) {
171 int getMarginHeight(int idx
) {
176 _minTimeInterval
= 1;
178 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
179 _nameWidthPref
, _minNameWidth
, 1000);
183 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
186 protected Control
createDataViewer(Composite parent
, int style
) {
188 _colors
= new TimeGraphColorScheme();
189 _dataViewer
= new Composite(parent
, style
) {
191 public void redraw() {
196 GridLayout gl
= new GridLayout(2, false);
197 gl
.marginHeight
= borderWidth
;
199 gl
.verticalSpacing
= 0;
200 gl
.horizontalSpacing
= 0;
201 _dataViewer
.setLayout(gl
);
203 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
204 _timeScaleCtrl
.setTimeProvider(this);
205 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
206 _timeScaleCtrl
.setHeight(timeScaleHeight
);
208 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
209 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
210 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
212 public void widgetSelected(SelectionEvent e
) {
213 setTopIndex(_verticalScrollBar
.getSelection());
216 _verticalScrollBar
.setEnabled(false);
218 _stateCtrl
= createTimeGraphControl();
220 _stateCtrl
.setTimeProvider(this);
221 _stateCtrl
.addSelectionListener(this);
222 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
223 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
225 public void mouseScrolled(MouseEvent e
) {
226 adjustVerticalScrollBar();
229 _stateCtrl
.addKeyListener(new KeyAdapter() {
231 public void keyPressed(KeyEvent e
) {
232 adjustVerticalScrollBar();
236 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
237 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
238 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
239 filler
.setLayoutData(gd
);
240 filler
.setLayout(new FillLayout());
242 _stateCtrl
.addControlListener(new ControlAdapter() {
244 public void controlResized(ControlEvent event
) {
249 _dataViewer
.update();
250 adjustVerticalScrollBar();
254 public void dispose() {
256 _stateCtrl
.dispose();
257 _dataViewer
.dispose();
261 protected TimeGraphControl
createTimeGraphControl() {
262 return new TimeGraphControl(_dataViewer
, _colors
);
265 public void resizeControls() {
266 Rectangle r
= _dataViewer
.getClientArea();
271 if (_nameWidth
> width
- _minNameWidth
)
272 _nameWidth
= width
- _minNameWidth
;
273 if (_nameWidth
< _minNameWidth
)
274 _nameWidth
= _minNameWidth
;
275 adjustVerticalScrollBar();
278 /** Tries to set most convenient time range for display. */
279 public void setTimeRange(ITimeGraphEntry traces
[]) {
282 for (int i
= 0; i
< traces
.length
; i
++) {
283 ITimeGraphEntry entry
= traces
[i
];
284 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
285 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
286 _beginTime
= entry
.getStartTime();
288 if (entry
.getEndTime() > _endTime
) {
289 _endTime
= entry
.getEndTime();
294 if (_beginTime
< 0) {
299 public void setTimeBounds() {
300 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
301 _time0_
= _beginTime
;
304 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
306 // _time0_ = Math.floor(_time0_);
307 // _time1_ = Math.ceil(_time1_);
308 if (!_timeRangeFixed
) {
312 if (_time1
- _time0
< _minTimeInterval
) {
313 _time1
= _time0
+ _minTimeInterval
;
322 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
324 traces
= new ITimeGraphEntry
[0];
325 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
326 // Start and end time are unspecified and need to be determined from
327 // individual processes
328 setTimeRange(traces
);
334 refreshAllData(traces
);
340 private void refreshAllData(ITimeGraphEntry
[] traces
) {
342 if (_selectedTime
< _beginTime
) {
343 _selectedTime
= _beginTime
;
344 } else if (_selectedTime
> _endTime
) {
345 _selectedTime
= _endTime
;
347 _stateCtrl
.refreshData(traces
);
348 _timeScaleCtrl
.redraw();
349 adjustVerticalScrollBar();
352 public void setFocus() {
353 if (null != _stateCtrl
)
354 _stateCtrl
.setFocus();
357 public boolean isInFocus() {
358 return _stateCtrl
.isInFocus();
361 public ITimeGraphEntry
getSelection() {
362 return _stateCtrl
.getSelectedTrace();
365 public int getSelectionIndex() {
366 return _stateCtrl
.getSelectedIndex();
370 public long getTime0() {
375 public long getTime1() {
380 public long getMinTimeInterval() {
381 return _minTimeInterval
;
385 public int getNameSpace() {
390 public void setNameSpace(int width
) {
392 width
= _stateCtrl
.getClientArea().width
;
393 if (_nameWidth
> width
- 6)
394 _nameWidth
= width
- 6;
397 _stateCtrl
.adjustScrolls();
399 _timeScaleCtrl
.redraw();
403 public int getTimeSpace() {
404 int w
= _stateCtrl
.getClientArea().width
;
405 return w
- _nameWidth
;
409 public long getSelectedTime() {
410 return _selectedTime
;
414 public long getBeginTime() {
419 public long getEndTime() {
424 public long getMaxTime() {
429 public long getMinTime() {
437 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
438 * #setStartFinishTimeNotify(long, long)
441 public void setStartFinishTimeNotify(long time0
, long time1
) {
442 setStartFinishTime(time0
, time1
);
443 notifyRangeListeners(time0
, time1
);
448 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
451 public void notifyStartFinishTime() {
452 notifyRangeListeners(_time0
, _time1
);
459 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
460 * #setStartFinishTime(long, long)
463 public void setStartFinishTime(long time0
, long time1
) {
465 if (_time0
< _time0_
)
467 if (_time0
> _time1_
)
470 if (_time1
< _time0_
)
472 if (_time1
> _time1_
)
474 if (_time1
- _time0
< _minTimeInterval
)
475 _time1
= _time0
+ _minTimeInterval
;
476 _timeRangeFixed
= true;
477 _stateCtrl
.adjustScrolls();
479 _timeScaleCtrl
.redraw();
482 public void setTimeBounds(long beginTime
, long endTime
) {
483 _beginTime
= beginTime
;
487 _stateCtrl
.adjustScrolls();
491 public void resetStartFinishTime() {
492 setStartFinishTimeNotify(_time0_
, _time1_
);
493 _timeRangeFixed
= false;
497 public void setSelectedTimeInt(long time
, boolean ensureVisible
) {
501 double timeSpace
= (_time1
- _time0
) * .02;
502 double timeMid
= (_time1
- _time0
) * .1;
503 if (time
< _time0
+ timeSpace
) {
504 long dt
= (long) (_time0
- time
+ timeMid
);
507 } else if (time
> _time1
- timeSpace
) {
508 long dt
= (long) (time
- _time1
+ timeMid
);
512 if (_time0
< _time0_
) {
513 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
515 } else if (_time1
> _time1_
) {
516 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
520 if (_time1
- _time0
< _minTimeInterval
) {
521 _time1
= _time0
+ _minTimeInterval
;
523 _stateCtrl
.adjustScrolls();
525 _timeScaleCtrl
.redraw();
526 if (time0
!= _time0
|| time1
!= _time1
) {
527 notifyRangeListeners(_time0
, _time1
);
529 if (time
!= _selectedTime
) {
530 _selectedTime
= time
;
531 notifyTimeListeners(_selectedTime
);
536 public void widgetDefaultSelected(SelectionEvent e
) {
537 if (_selectedEntry
!= getSelection()) {
538 _selectedEntry
= getSelection();
539 notifySelectionListeners(_selectedEntry
);
544 public void widgetSelected(SelectionEvent e
) {
545 if (_selectedEntry
!= getSelection()) {
546 _selectedEntry
= getSelection();
547 notifySelectionListeners(_selectedEntry
);
551 public void selectNextEvent() {
552 _stateCtrl
.selectNextEvent();
553 adjustVerticalScrollBar();
556 public void selectPrevEvent() {
557 _stateCtrl
.selectPrevEvent();
558 adjustVerticalScrollBar();
561 public void selectNextItem() {
562 _stateCtrl
.selectNextTrace();
563 adjustVerticalScrollBar();
566 public void selectPrevItem() {
567 _stateCtrl
.selectPrevTrace();
568 adjustVerticalScrollBar();
571 public void showLegend() {
572 if (_dataViewer
== null || _dataViewer
.isDisposed())
575 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
578 public void zoomIn() {
582 public void zoomOut() {
583 _stateCtrl
.zoomOut();
586 private String
getPreferenceString(String string
) {
587 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
590 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
591 fSelectionListeners
.add(listener
);
594 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
595 fSelectionListeners
.remove(listener
);
598 private void notifySelectionListeners(ITimeGraphEntry selection
) {
599 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
601 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
602 listener
.selectionChanged(event
);
606 public void addTimeListener(ITimeGraphTimeListener listener
) {
607 fTimeListeners
.add(listener
);
610 public void removeTimeListener(ITimeGraphTimeListener listener
) {
611 fTimeListeners
.remove(listener
);
614 private void notifyTimeListeners(long time
) {
615 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
617 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
618 listener
.timeSelected(event
);
622 public void addRangeListener(ITimeGraphRangeListener listener
) {
623 fRangeListeners
.add(listener
);
626 public void removeRangeListener(ITimeGraphRangeListener listener
) {
627 fRangeListeners
.remove(listener
);
630 private void notifyRangeListeners(long startTime
, long endTime
) {
631 // Check if the time has actually changed from last notification
632 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
633 // Notify Time Scale Selection Listeners
634 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
636 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
637 listener
.timeRangeUpdated(event
);
640 // update external synch timers
641 updateExtSynchTimers();
645 public void setSelectedTime(long time
, boolean ensureVisible
, Object source
) {
646 if (this == source
) {
650 setSelectedTimeInt(time
, ensureVisible
);
653 public void setSelectedEvent(ITimeEvent event
, Object source
) {
654 if (event
== null || source
== this) {
657 _selectedEntry
= event
.getEntry();
658 _stateCtrl
.selectItem(_selectedEntry
, false);
660 setSelectedTimeInt(event
.getTime(), true);
661 adjustVerticalScrollBar();
664 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
665 if (trace
== null || source
== this) {
668 _selectedEntry
= trace
;
669 _stateCtrl
.selectItem(trace
, false);
671 setSelectedTimeInt(time
, true);
674 public void setSelection(ITimeGraphEntry trace
) {
675 _selectedEntry
= trace
;
676 _stateCtrl
.selectItem(trace
, false);
677 adjustVerticalScrollBar();
680 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
681 if (source
== this) {
685 setStartFinishTime(time0
, time1
);
687 // update notification time values since we are now in synch with the
688 // external application
689 updateExtSynchTimers();
693 * update the cache timers used to identify the need to send a time window
694 * update to external registered listeners
696 private void updateExtSynchTimers() {
697 // last time notification cache
698 _time0_extSynch
= _time0
;
699 _time1_extSynch
= _time1
;
702 public void setTimeCalendarFormat(boolean toAbsoluteCaltime
) {
703 calendarTimeFormat
= toAbsoluteCaltime
;
707 public boolean isCalendarFormat() {
708 return calendarTimeFormat
;
711 public int getBorderWidth() {
715 public void setBorderWidth(int borderWidth
) {
716 if (borderWidth
> -1) {
717 this.borderWidth
= borderWidth
;
718 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
719 gl
.marginHeight
= borderWidth
;
723 public int getHeaderHeight() {
724 return timeScaleHeight
;
727 public void setHeaderHeight(int headerHeight
) {
728 if (headerHeight
> -1) {
729 this.timeScaleHeight
= headerHeight
;
730 _timeScaleCtrl
.setHeight(headerHeight
);
734 public int getItemHeight() {
735 if (_stateCtrl
!= null) {
736 return _stateCtrl
.getItemHeight();
741 public void setItemHeight(int rowHeight
) {
742 if (_stateCtrl
!= null) {
743 _stateCtrl
.setItemHeight(rowHeight
);
747 public void setMinimumItemWidth(int width
) {
748 if (_stateCtrl
!= null) {
749 _stateCtrl
.setMinimumItemWidth(width
);
753 public void setNameWidthPref(int width
) {
754 _nameWidthPref
= width
;
761 public int getNameWidthPref(int width
) {
762 return _nameWidthPref
;
766 * Returns the primary control associated with this viewer.
768 * @return the SWT control which displays this viewer's content
770 public Control
getControl() {
775 * Returns the time graph control associated with this viewer.
777 * @return the time graph control
779 TimeGraphControl
getTimeGraphControl() {
784 * Get the selection provider
786 * @return the selection provider
788 public ISelectionProvider
getSelectionProvider() {
796 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer
797 * #waitCursor(boolean)
799 public void waitCursor(boolean waitInd
) {
800 _stateCtrl
.waitCursor(waitInd
);
803 public ScrollBar
getHorizontalBar() {
804 return _stateCtrl
.getHorizontalBar();
807 public Slider
getVerticalBar() {
808 return _verticalScrollBar
;
811 public void setTopIndex(int index
) {
812 _stateCtrl
.setTopIndex(index
);
813 adjustVerticalScrollBar();
816 public int getTopIndex() {
817 return _stateCtrl
.getTopIndex();
820 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
821 _stateCtrl
.setExpandedState(entry
, expanded
);
822 adjustVerticalScrollBar();
825 public void addTreeListener(ITimeGraphTreeListener listener
) {
826 _stateCtrl
.addTreeListener(listener
);
829 public void removeTreeListener(ITimeGraphTreeListener listener
) {
830 _stateCtrl
.removeTreeListener(listener
);
833 public Action
getResetScaleAction() {
834 if (resetScale
== null) {
836 resetScale
= new Action() {
839 resetStartFinishTime();
842 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
843 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
844 resetScale
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
849 public Action
getShowLegendAction() {
850 if (showLegendAction
== null) {
852 showLegendAction
= new Action() {
858 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
859 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
860 showLegendAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
863 return showLegendAction
;
866 public Action
getNextEventAction() {
867 if (nextEventAction
== null) {
868 nextEventAction
= new Action() {
875 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
876 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
877 nextEventAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
880 return nextEventAction
;
883 public Action
getPreviousEventAction() {
884 if (prevEventAction
== null) {
885 prevEventAction
= new Action() {
892 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
893 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
894 prevEventAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
897 return prevEventAction
;
900 public Action
getNextItemAction() {
901 if (nextItemAction
== null) {
903 nextItemAction
= new Action() {
909 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
910 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
911 nextItemAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
913 return nextItemAction
;
916 public Action
getPreviousItemAction() {
917 if (previousItemAction
== null) {
919 previousItemAction
= new Action() {
925 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
926 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
927 previousItemAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
929 return previousItemAction
;
932 public Action
getZoomInAction() {
933 if (zoomInAction
== null) {
934 zoomInAction
= new Action() {
940 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
941 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
942 zoomInAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
947 public Action
getZoomOutAction() {
948 if (zoomOutAction
== null) {
949 zoomOutAction
= new Action() {
955 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
956 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
957 zoomOutAction
.setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
959 return zoomOutAction
;
963 private void adjustVerticalScrollBar() {
964 int topIndex
= _stateCtrl
.getTopIndex();
965 int countPerPage
= _stateCtrl
.countPerPage();
966 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
967 if (topIndex
+ countPerPage
> expandedElementCount
) {
968 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
971 int selection
= _stateCtrl
.getTopIndex();
973 int max
= Math
.max(1, expandedElementCount
- 1);
974 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
976 int pageIncrement
= Math
.max(1, countPerPage
);
977 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);