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 public TimeGraphViewer(Composite parent
, int style
) {
108 createDataViewer(parent
, style
);
112 * Sets the timegraph provider used by this timegraph viewer.
114 * @param timeGraphProvider the timegraph provider
116 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
117 fTimeGraphProvider
= timeGraphProvider
;
118 _stateCtrl
.setTimeGraphProvider(timeGraphProvider
);
119 _threadTip
= new TimeGraphTooltipHandler(_dataViewer
.getShell(), fTimeGraphProvider
, this);
120 _threadTip
.activateHoverHelp(_stateCtrl
);
124 * Sets or clears the input for this time graph viewer.
125 * The input array should only contain top-level elements.
127 * @param input the input of this time graph viewer, or <code>null</code> if none
129 public void setInput(ITimeGraphEntry
[] input
) {
130 if (null != _stateCtrl
) {
132 input
= new ITimeGraphEntry
[0];
135 _verticalScrollBar
.setEnabled(true);
138 refreshAllData(input
);
142 public void refresh() {
143 setInput(_stateCtrl
.getTraces());
146 public void controlMoved(ControlEvent e
) {
149 public void controlResized(ControlEvent e
) {
153 // called from the display order in the API
154 public void modelUpdate(ITimeGraphEntry
[] traces
, long start
,
155 long end
, boolean updateTimeBounds
) {
156 if (null != _stateCtrl
) {
158 updateInternalData(traces
, start
, end
);
159 if (updateTimeBounds
) {
160 _timeRangeFixed
= true;
161 // set window to match limits
162 setStartFinishTime(_time0_
, _time1_
);
165 _timeScaleCtrl
.redraw();
170 protected String
getViewTypeStr() {
171 return "viewoption.threads"; //$NON-NLS-1$
174 int getMarginWidth(int idx
) {
178 int getMarginHeight(int idx
) {
183 _minTimeInterval
= 1;
185 _nameWidth
= Utils
.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
186 _nameWidthPref
, _minNameWidth
, 1000);
190 Utils
.saveIntOption(getPreferenceString("namewidth"), _nameWidth
); //$NON-NLS-1$
193 protected Control
createDataViewer(Composite parent
, int style
) {
195 _colors
= new TimeGraphColorScheme();
196 _dataViewer
= new Composite(parent
, style
) {
198 public void redraw() {
199 _timeScaleCtrl
.redraw();
204 GridLayout gl
= new GridLayout(2, false);
205 gl
.marginHeight
= borderWidth
;
207 gl
.verticalSpacing
= 0;
208 gl
.horizontalSpacing
= 0;
209 _dataViewer
.setLayout(gl
);
211 _timeScaleCtrl
= new TimeGraphScale(_dataViewer
, _colors
);
212 _timeScaleCtrl
.setTimeProvider(this);
213 _timeScaleCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.DEFAULT
, true, false));
214 _timeScaleCtrl
.setHeight(timeScaleHeight
);
216 _verticalScrollBar
= new Slider(_dataViewer
, SWT
.VERTICAL
| SWT
.NO_FOCUS
);
217 _verticalScrollBar
.setLayoutData(new GridData(SWT
.DEFAULT
, SWT
.FILL
, false, true, 1, 2));
218 _verticalScrollBar
.addSelectionListener(new SelectionAdapter() {
220 public void widgetSelected(SelectionEvent e
) {
221 setTopIndex(_verticalScrollBar
.getSelection());
224 _verticalScrollBar
.setEnabled(false);
226 _stateCtrl
= createTimeGraphControl();
228 _stateCtrl
.setTimeProvider(this);
229 _stateCtrl
.addSelectionListener(this);
230 _stateCtrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 2));
231 _stateCtrl
.addMouseWheelListener(new MouseWheelListener() {
233 public void mouseScrolled(MouseEvent e
) {
234 adjustVerticalScrollBar();
237 _stateCtrl
.addKeyListener(new KeyAdapter() {
239 public void keyPressed(KeyEvent e
) {
240 adjustVerticalScrollBar();
244 Composite filler
= new Composite(_dataViewer
, SWT
.NONE
);
245 GridData gd
= new GridData(SWT
.DEFAULT
, SWT
.DEFAULT
, false, false);
246 gd
.heightHint
= _stateCtrl
.getHorizontalBar().getSize().y
;
247 filler
.setLayoutData(gd
);
248 filler
.setLayout(new FillLayout());
250 _stateCtrl
.addControlListener(new ControlAdapter() {
252 public void controlResized(ControlEvent event
) {
257 _dataViewer
.update();
258 adjustVerticalScrollBar();
262 public void dispose() {
264 _stateCtrl
.dispose();
265 _dataViewer
.dispose();
269 protected TimeGraphControl
createTimeGraphControl() {
270 return new TimeGraphControl(_dataViewer
, _colors
);
273 public void resizeControls() {
274 Rectangle r
= _dataViewer
.getClientArea();
280 if (_nameWidth
> width
- _minNameWidth
) {
281 _nameWidth
= width
- _minNameWidth
;
283 if (_nameWidth
< _minNameWidth
) {
284 _nameWidth
= _minNameWidth
;
286 adjustVerticalScrollBar();
289 /** Tries to set most convenient time range for display. */
290 public void setTimeRange(ITimeGraphEntry traces
[]) {
293 for (int i
= 0; i
< traces
.length
; i
++) {
294 ITimeGraphEntry entry
= traces
[i
];
295 if (entry
.getEndTime() >= entry
.getStartTime() && entry
.getEndTime() > 0) {
296 if (_beginTime
< 0 || entry
.getStartTime() < _beginTime
) {
297 _beginTime
= entry
.getStartTime();
299 if (entry
.getEndTime() > _endTime
) {
300 _endTime
= entry
.getEndTime();
305 if (_beginTime
< 0) {
310 public void setTimeBounds() {
311 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
312 _time0_
= _beginTime
;
316 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
318 // _time0_ = Math.floor(_time0_);
319 // _time1_ = Math.ceil(_time1_);
320 if (!_timeRangeFixed
) {
324 if (_time1
- _time0
< _minTimeInterval
) {
325 _time1
= _time0
+ _minTimeInterval
;
334 void updateInternalData(ITimeGraphEntry
[] traces
, long start
, long end
) {
335 if (null == traces
) {
336 traces
= new ITimeGraphEntry
[0];
338 if ((start
== 0 && end
== 0) || start
< 0 || end
< 0) {
339 // Start and end time are unspecified and need to be determined from
340 // individual processes
341 setTimeRange(traces
);
347 refreshAllData(traces
);
353 private void refreshAllData(ITimeGraphEntry
[] traces
) {
355 if (_selectedTime
< _beginTime
) {
356 _selectedTime
= _beginTime
;
357 } else if (_selectedTime
> _endTime
) {
358 _selectedTime
= _endTime
;
360 _stateCtrl
.refreshData(traces
);
361 _timeScaleCtrl
.redraw();
362 adjustVerticalScrollBar();
365 public void setFocus() {
366 if (null != _stateCtrl
) {
367 _stateCtrl
.setFocus();
371 public boolean isInFocus() {
372 return _stateCtrl
.isInFocus();
375 public ITimeGraphEntry
getSelection() {
376 return _stateCtrl
.getSelectedTrace();
379 public int getSelectionIndex() {
380 return _stateCtrl
.getSelectedIndex();
384 public long getTime0() {
389 public long getTime1() {
394 public long getMinTimeInterval() {
395 return _minTimeInterval
;
399 public int getNameSpace() {
404 public void setNameSpace(int width
) {
406 width
= _stateCtrl
.getClientArea().width
;
407 if (_nameWidth
> width
- 6) {
408 _nameWidth
= width
- 6;
410 if (_nameWidth
< 6) {
413 _stateCtrl
.adjustScrolls();
415 _timeScaleCtrl
.redraw();
419 public int getTimeSpace() {
420 int w
= _stateCtrl
.getClientArea().width
;
421 return w
- _nameWidth
;
425 public long getSelectedTime() {
426 return _selectedTime
;
430 public long getBeginTime() {
435 public long getEndTime() {
440 public long getMaxTime() {
445 public long getMinTime() {
453 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
454 * #setStartFinishTimeNotify(long, long)
457 public void setStartFinishTimeNotify(long time0
, long time1
) {
458 setStartFinishTime(time0
, time1
);
459 notifyRangeListeners(time0
, time1
);
464 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
467 public void notifyStartFinishTime() {
468 notifyRangeListeners(_time0
, _time1
);
475 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
476 * #setStartFinishTime(long, long)
479 public void setStartFinishTime(long time0
, long time1
) {
481 if (_time0
< _time0_
) {
484 if (_time0
> _time1_
) {
488 if (_time1
< _time0_
) {
491 if (_time1
> _time1_
) {
494 if (_time1
- _time0
< _minTimeInterval
) {
495 _time1
= Math
.min(_time1_
, _time0
+ _minTimeInterval
);
497 _timeRangeFixed
= true;
498 _stateCtrl
.adjustScrolls();
500 _timeScaleCtrl
.redraw();
503 public void setTimeBounds(long beginTime
, long endTime
) {
504 _beginTime
= beginTime
;
508 _stateCtrl
.adjustScrolls();
512 public void resetStartFinishTime() {
513 setStartFinishTimeNotify(_time0_
, _time1_
);
514 _timeRangeFixed
= false;
518 public void setSelectedTimeNotify(long time
, boolean ensureVisible
) {
519 setSelectedTimeInt(time
, ensureVisible
, true);
523 public void setSelectedTime(long time
, boolean ensureVisible
) {
524 setSelectedTimeInt(time
, ensureVisible
, false);
527 private void setSelectedTimeInt(long time
, boolean ensureVisible
, boolean doNotify
) {
531 long timeSpace
= (long) ((_time1
- _time0
) * .02);
532 long timeMid
= (long) ((_time1
- _time0
) * .5);
533 if (time
< _time0
+ timeSpace
) {
534 long dt
= _time0
- time
+ timeMid
;
537 } else if (time
> _time1
- timeSpace
) {
538 long dt
= time
- _time1
+ timeMid
;
542 if (_time0
< _time0_
) {
543 _time1
= Math
.min(_time1_
, _time1
+ (_time0_
- _time0
));
545 } else if (_time1
> _time1_
) {
546 _time0
= Math
.max(_time0_
, _time0
- (_time1
- _time1_
));
550 if (_time1
- _time0
< _minTimeInterval
) {
551 _time1
= _time0
+ _minTimeInterval
;
553 _stateCtrl
.adjustScrolls();
555 _timeScaleCtrl
.redraw();
558 boolean notifySelectedTime
= (time
!= _selectedTime
);
559 _selectedTime
= time
;
561 if (doNotify
&& ((time0
!= _time0
) || (time1
!= _time1
))) {
562 notifyRangeListeners(_time0
, _time1
);
565 if (doNotify
&& notifySelectedTime
) {
566 notifyTimeListeners(_selectedTime
);
571 public void widgetDefaultSelected(SelectionEvent e
) {
572 if (_selectedEntry
!= getSelection()) {
573 _selectedEntry
= getSelection();
574 notifySelectionListeners(_selectedEntry
);
579 public void widgetSelected(SelectionEvent e
) {
580 if (_selectedEntry
!= getSelection()) {
581 _selectedEntry
= getSelection();
582 notifySelectionListeners(_selectedEntry
);
586 public void selectNextEvent() {
587 _stateCtrl
.selectNextEvent();
588 adjustVerticalScrollBar();
591 public void selectPrevEvent() {
592 _stateCtrl
.selectPrevEvent();
593 adjustVerticalScrollBar();
596 public void selectNextItem() {
597 _stateCtrl
.selectNextTrace();
598 adjustVerticalScrollBar();
601 public void selectPrevItem() {
602 _stateCtrl
.selectPrevTrace();
603 adjustVerticalScrollBar();
606 public void showLegend() {
607 if (_dataViewer
== null || _dataViewer
.isDisposed()) {
611 TimeGraphLegend
.open(_dataViewer
.getShell(), fTimeGraphProvider
);
614 public void zoomIn() {
618 public void zoomOut() {
619 _stateCtrl
.zoomOut();
622 private String
getPreferenceString(String string
) {
623 return getViewTypeStr() + "." + string
; //$NON-NLS-1$
626 public void addSelectionListener(ITimeGraphSelectionListener listener
) {
627 fSelectionListeners
.add(listener
);
630 public void removeSelectionListener(ITimeGraphSelectionListener listener
) {
631 fSelectionListeners
.remove(listener
);
634 private void notifySelectionListeners(ITimeGraphEntry selection
) {
635 TimeGraphSelectionEvent event
= new TimeGraphSelectionEvent(this, selection
);
637 for (ITimeGraphSelectionListener listener
: fSelectionListeners
) {
638 listener
.selectionChanged(event
);
642 public void addTimeListener(ITimeGraphTimeListener listener
) {
643 fTimeListeners
.add(listener
);
646 public void removeTimeListener(ITimeGraphTimeListener listener
) {
647 fTimeListeners
.remove(listener
);
650 private void notifyTimeListeners(long time
) {
651 TimeGraphTimeEvent event
= new TimeGraphTimeEvent(this, time
);
653 for (ITimeGraphTimeListener listener
: fTimeListeners
) {
654 listener
.timeSelected(event
);
658 public void addRangeListener(ITimeGraphRangeListener listener
) {
659 fRangeListeners
.add(listener
);
662 public void removeRangeListener(ITimeGraphRangeListener listener
) {
663 fRangeListeners
.remove(listener
);
666 private void notifyRangeListeners(long startTime
, long endTime
) {
667 // Check if the time has actually changed from last notification
668 if (startTime
!= _time0_extSynch
|| endTime
!= _time1_extSynch
) {
669 // Notify Time Scale Selection Listeners
670 TimeGraphRangeUpdateEvent event
= new TimeGraphRangeUpdateEvent(this, startTime
, endTime
);
672 for (ITimeGraphRangeListener listener
: fRangeListeners
) {
673 listener
.timeRangeUpdated(event
);
676 // update external synch timers
677 updateExtSynchTimers();
681 public void setSelectedEvent(ITimeEvent event
, Object source
) {
682 if (event
== null || source
== this) {
685 _selectedEntry
= event
.getEntry();
686 _stateCtrl
.selectItem(_selectedEntry
, false);
688 setSelectedTimeInt(event
.getTime(), true, true);
689 adjustVerticalScrollBar();
692 public void setSelectedTraceTime(ITimeGraphEntry trace
, long time
, Object source
) {
693 if (trace
== null || source
== this) {
696 _selectedEntry
= trace
;
697 _stateCtrl
.selectItem(trace
, false);
699 setSelectedTimeInt(time
, true, true);
702 public void setSelection(ITimeGraphEntry trace
) {
703 _selectedEntry
= trace
;
704 _stateCtrl
.selectItem(trace
, false);
705 adjustVerticalScrollBar();
708 public void setSelectVisTimeWindow(long time0
, long time1
, Object source
) {
709 if (source
== this) {
713 setStartFinishTime(time0
, time1
);
715 // update notification time values since we are now in synch with the
716 // external application
717 updateExtSynchTimers();
721 * update the cache timers used to identify the need to send a time window
722 * update to external registered listeners
724 private void updateExtSynchTimers() {
725 // last time notification cache
726 _time0_extSynch
= _time0
;
727 _time1_extSynch
= _time1
;
730 public void setTimeCalendarFormat(boolean toAbsoluteCaltime
) {
731 calendarTimeFormat
= toAbsoluteCaltime
;
735 public boolean isCalendarFormat() {
736 return calendarTimeFormat
;
739 public int getBorderWidth() {
743 public void setBorderWidth(int borderWidth
) {
744 if (borderWidth
> -1) {
745 this.borderWidth
= borderWidth
;
746 GridLayout gl
= (GridLayout
)_dataViewer
.getLayout();
747 gl
.marginHeight
= borderWidth
;
751 public int getHeaderHeight() {
752 return timeScaleHeight
;
755 public void setHeaderHeight(int headerHeight
) {
756 if (headerHeight
> -1) {
757 this.timeScaleHeight
= headerHeight
;
758 _timeScaleCtrl
.setHeight(headerHeight
);
762 public int getItemHeight() {
763 if (_stateCtrl
!= null) {
764 return _stateCtrl
.getItemHeight();
769 public void setItemHeight(int rowHeight
) {
770 if (_stateCtrl
!= null) {
771 _stateCtrl
.setItemHeight(rowHeight
);
775 public void setMinimumItemWidth(int width
) {
776 if (_stateCtrl
!= null) {
777 _stateCtrl
.setMinimumItemWidth(width
);
781 public void setNameWidthPref(int width
) {
782 _nameWidthPref
= width
;
789 public int getNameWidthPref(int width
) {
790 return _nameWidthPref
;
794 * Returns the primary control associated with this viewer.
796 * @return the SWT control which displays this viewer's content
798 public Control
getControl() {
803 * Returns the time graph control associated with this viewer.
805 * @return the time graph control
807 TimeGraphControl
getTimeGraphControl() {
812 * Returns the time graph scale associated with this viewer.
814 * @return the time graph scale
816 TimeGraphScale
getTimeGraphScale() {
817 return _timeScaleCtrl
;
821 * Get the selection provider
823 * @return the selection provider
825 public ISelectionProvider
getSelectionProvider() {
833 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer
834 * #waitCursor(boolean)
836 public void waitCursor(boolean waitInd
) {
837 _stateCtrl
.waitCursor(waitInd
);
840 public ScrollBar
getHorizontalBar() {
841 return _stateCtrl
.getHorizontalBar();
844 public Slider
getVerticalBar() {
845 return _verticalScrollBar
;
848 public void setTopIndex(int index
) {
849 _stateCtrl
.setTopIndex(index
);
850 adjustVerticalScrollBar();
853 public int getTopIndex() {
854 return _stateCtrl
.getTopIndex();
857 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
858 _stateCtrl
.setExpandedState(entry
, expanded
);
859 adjustVerticalScrollBar();
862 public int getExpandedElementCount() {
863 return _stateCtrl
.getExpandedElementCount();
866 public ITimeGraphEntry
[] getExpandedElements() {
867 return _stateCtrl
.getExpandedElements();
870 public void addTreeListener(ITimeGraphTreeListener listener
) {
871 _stateCtrl
.addTreeListener(listener
);
874 public void removeTreeListener(ITimeGraphTreeListener listener
) {
875 _stateCtrl
.removeTreeListener(listener
);
878 public Action
getResetScaleAction() {
879 if (resetScale
== null) {
881 resetScale
= new Action() {
884 resetStartFinishTime();
887 resetScale
.setText(Messages
.TmfTimeGraphViewer_ResetScaleActionNameText
);
888 resetScale
.setToolTipText(Messages
.TmfTimeGraphViewer_ResetScaleActionToolTipText
);
889 resetScale
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_HOME_MENU
));
894 public Action
getShowLegendAction() {
895 if (showLegendAction
== null) {
897 showLegendAction
= new Action() {
903 showLegendAction
.setText(Messages
.TmfTimeGraphViewer_LegendActionNameText
);
904 showLegendAction
.setToolTipText(Messages
.TmfTimeGraphViewer_LegendActionToolTipText
);
905 showLegendAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SHOW_LEGEND
));
908 return showLegendAction
;
911 public Action
getNextEventAction() {
912 if (nextEventAction
== null) {
913 nextEventAction
= new Action() {
920 nextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
921 nextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
922 nextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
925 return nextEventAction
;
928 public Action
getPreviousEventAction() {
929 if (prevEventAction
== null) {
930 prevEventAction
= new Action() {
937 prevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
938 prevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
939 prevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
942 return prevEventAction
;
945 public Action
getNextItemAction() {
946 if (nextItemAction
== null) {
948 nextItemAction
= new Action() {
954 nextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
955 nextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
956 nextItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_ITEM
));
958 return nextItemAction
;
961 public Action
getPreviousItemAction() {
962 if (previousItemAction
== null) {
964 previousItemAction
= new Action() {
970 previousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
971 previousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
972 previousItemAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_ITEM
));
974 return previousItemAction
;
977 public Action
getZoomInAction() {
978 if (zoomInAction
== null) {
979 zoomInAction
= new Action() {
985 zoomInAction
.setText(Messages
.TmfTimeGraphViewer_ZoomInActionNameText
);
986 zoomInAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomInActionToolTipText
);
987 zoomInAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_IN_MENU
));
992 public Action
getZoomOutAction() {
993 if (zoomOutAction
== null) {
994 zoomOutAction
= new Action() {
1000 zoomOutAction
.setText(Messages
.TmfTimeGraphViewer_ZoomOutActionNameText
);
1001 zoomOutAction
.setToolTipText(Messages
.TmfTimeGraphViewer_ZoomOutActionToolTipText
);
1002 zoomOutAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_ZOOM_OUT_MENU
));
1004 return zoomOutAction
;
1008 private void adjustVerticalScrollBar() {
1009 int topIndex
= _stateCtrl
.getTopIndex();
1010 int countPerPage
= _stateCtrl
.countPerPage();
1011 int expandedElementCount
= _stateCtrl
.getExpandedElementCount();
1012 if (topIndex
+ countPerPage
> expandedElementCount
) {
1013 _stateCtrl
.setTopIndex(Math
.max(0, expandedElementCount
- countPerPage
));
1016 int selection
= _stateCtrl
.getTopIndex();
1018 int max
= Math
.max(1, expandedElementCount
- 1);
1019 int thumb
= Math
.min(max
, Math
.max(1, countPerPage
- 1));
1021 int pageIncrement
= Math
.max(1, countPerPage
);
1022 _verticalScrollBar
.setValues(selection
, min
, max
, thumb
, increment
, pageIncrement
);