Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / TimeGraphViewer.java
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
7 *
8 * Contributors:
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alexander N. Alexeev, Intel - Add monitors statistics support
12 * Alvaro Sanchez-Leon - Adapted for TMF
13 * Patrick Tasse - Refactoring
14 *
15 *****************************************************************************/
16
17 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
18
19 import java.util.ArrayList;
20
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;
53
54 public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
55
56 /** vars */
57 private long _minTimeInterval;
58 private long _selectedTime;
59 private ITimeGraphEntry _selectedEntry;
60 private long _beginTime;
61 private long _endTime;
62 private long _time0;
63 private long _time1;
64 private long _time0_;
65 private long _time1_;
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;
73
74 private TimeGraphControl _stateCtrl;
75 private TimeGraphScale _timeScaleCtrl;
76 private Slider _verticalScrollBar;
77 private TimeGraphTooltipHandler _threadTip;
78 private TimeGraphColorScheme _colors;
79 private ITimeGraphPresentationProvider fTimeGraphProvider;
80
81 ArrayList<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<ITimeGraphSelectionListener>();
82 ArrayList<ITimeGraphTimeListener> fTimeListeners = new ArrayList<ITimeGraphTimeListener>();
83 ArrayList<ITimeGraphRangeListener> fRangeListeners = new ArrayList<ITimeGraphRangeListener>();
84
85 // Calender Time format, using Epoch reference or Relative time
86 // format(default
87 private boolean calendarTimeFormat = false;
88 private int borderWidth = 4;
89 private int timeScaleHeight = 22;
90
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;
99
100 /** ctor */
101 public TimeGraphViewer(Composite parent, int style) {
102 createDataViewer(parent, style);
103 }
104
105 /**
106 * Sets the timegraph provider used by this timegraph viewer.
107 *
108 * @param timeGraphProvider the timegraph provider
109 */
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);
115 }
116
117 /**
118 * Sets or clears the input for this time graph viewer.
119 * The input array should only contain top-level elements.
120 *
121 * @param input the input of this time graph viewer, or <code>null</code> if none
122 */
123 public void setInput(ITimeGraphEntry[] input) {
124 if (null != _stateCtrl) {
125 if (null == input) {
126 input = new ITimeGraphEntry[0];
127 }
128 setTimeRange(input);
129 _verticalScrollBar.setEnabled(true);
130 setTopIndex(0);
131 refreshAllData(input);
132 }
133 }
134
135 public void refresh() {
136 setInput(_stateCtrl.getTraces());
137 }
138
139 public void controlMoved(ControlEvent e) {
140 }
141
142 public void controlResized(ControlEvent e) {
143 resizeControls();
144 }
145
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) {
150 //loadOptions();
151 updateInternalData(traces, start, end);
152 if (updateTimeBounds) {
153 _timeRangeFixed = true;
154 // set window to match limits
155 setStartFinishTime(_time0_, _time1_);
156 } else {
157 _stateCtrl.redraw();
158 _timeScaleCtrl.redraw();
159 }
160 }
161 }
162
163 protected String getViewTypeStr() {
164 return "viewoption.threads"; //$NON-NLS-1$
165 }
166
167 int getMarginWidth(int idx) {
168 return 0;
169 }
170
171 int getMarginHeight(int idx) {
172 return 0;
173 }
174
175 void loadOptions() {
176 _minTimeInterval = 1;
177 _selectedTime = -1;
178 _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
179 _nameWidthPref, _minNameWidth, 1000);
180 }
181
182 void saveOptions() {
183 Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth); //$NON-NLS-1$
184 }
185
186 protected Control createDataViewer(Composite parent, int style) {
187 loadOptions();
188 _colors = new TimeGraphColorScheme();
189 _dataViewer = new Composite(parent, style) {
190 @Override
191 public void redraw() {
192 _stateCtrl.redraw();
193 super.redraw();
194 }
195 };
196 GridLayout gl = new GridLayout(2, false);
197 gl.marginHeight = borderWidth;
198 gl.marginWidth = 0;
199 gl.verticalSpacing = 0;
200 gl.horizontalSpacing = 0;
201 _dataViewer.setLayout(gl);
202
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);
207
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() {
211 @Override
212 public void widgetSelected(SelectionEvent e) {
213 setTopIndex(_verticalScrollBar.getSelection());
214 }
215 });
216 _verticalScrollBar.setEnabled(false);
217
218 _stateCtrl = createTimeGraphControl();
219
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() {
224 @Override
225 public void mouseScrolled(MouseEvent e) {
226 adjustVerticalScrollBar();
227 }
228 });
229 _stateCtrl.addKeyListener(new KeyAdapter() {
230 @Override
231 public void keyPressed(KeyEvent e) {
232 adjustVerticalScrollBar();
233 }
234 });
235
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());
241
242 _stateCtrl.addControlListener(new ControlAdapter() {
243 @Override
244 public void controlResized(ControlEvent event) {
245 resizeControls();
246 }
247 });
248 resizeControls();
249 _dataViewer.update();
250 adjustVerticalScrollBar();
251 return _dataViewer;
252 }
253
254 public void dispose() {
255 saveOptions();
256 _stateCtrl.dispose();
257 _dataViewer.dispose();
258 _colors.dispose();
259 }
260
261 protected TimeGraphControl createTimeGraphControl() {
262 return new TimeGraphControl(_dataViewer, _colors);
263 }
264
265 public void resizeControls() {
266 Rectangle r = _dataViewer.getClientArea();
267 if (r.isEmpty())
268 return;
269
270 int width = r.width;
271 if (_nameWidth > width - _minNameWidth)
272 _nameWidth = width - _minNameWidth;
273 if (_nameWidth < _minNameWidth)
274 _nameWidth = _minNameWidth;
275 adjustVerticalScrollBar();
276 }
277
278 /** Tries to set most convenient time range for display. */
279 public void setTimeRange(ITimeGraphEntry traces[]) {
280 _endTime = 0;
281 _beginTime = -1;
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();
287 }
288 if (entry.getEndTime() > _endTime) {
289 _endTime = entry.getEndTime();
290 }
291 }
292 }
293
294 if (_beginTime < 0) {
295 _beginTime = 0;
296 }
297 }
298
299 public void setTimeBounds() {
300 //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
301 _time0_ = _beginTime;
302 if (_time0_ < 0)
303 _time0_ = 0;
304 // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
305 _time1_ = _endTime;
306 // _time0_ = Math.floor(_time0_);
307 // _time1_ = Math.ceil(_time1_);
308 if (!_timeRangeFixed) {
309 _time0 = _time0_;
310 _time1 = _time1_;
311 }
312 if (_time1 - _time0 < _minTimeInterval) {
313 _time1 = _time0 + _minTimeInterval;
314 }
315 }
316
317 /**
318 * @param traces
319 * @param start
320 * @param end
321 */
322 void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {
323 if (null == traces)
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);
329 } else {
330 _beginTime = start;
331 _endTime = end;
332 }
333
334 refreshAllData(traces);
335 }
336
337 /**
338 * @param traces
339 */
340 private void refreshAllData(ITimeGraphEntry[] traces) {
341 setTimeBounds();
342 if (_selectedTime < _beginTime) {
343 _selectedTime = _beginTime;
344 } else if (_selectedTime > _endTime) {
345 _selectedTime = _endTime;
346 }
347 _stateCtrl.refreshData(traces);
348 _timeScaleCtrl.redraw();
349 adjustVerticalScrollBar();
350 }
351
352 public void setFocus() {
353 if (null != _stateCtrl)
354 _stateCtrl.setFocus();
355 }
356
357 public boolean isInFocus() {
358 return _stateCtrl.isInFocus();
359 }
360
361 public ITimeGraphEntry getSelection() {
362 return _stateCtrl.getSelectedTrace();
363 }
364
365 public int getSelectionIndex() {
366 return _stateCtrl.getSelectedIndex();
367 }
368
369 @Override
370 public long getTime0() {
371 return _time0;
372 }
373
374 @Override
375 public long getTime1() {
376 return _time1;
377 }
378
379 @Override
380 public long getMinTimeInterval() {
381 return _minTimeInterval;
382 }
383
384 @Override
385 public int getNameSpace() {
386 return _nameWidth;
387 }
388
389 @Override
390 public void setNameSpace(int width) {
391 _nameWidth = width;
392 width = _stateCtrl.getClientArea().width;
393 if (_nameWidth > width - 6)
394 _nameWidth = width - 6;
395 if (_nameWidth < 6)
396 _nameWidth = 6;
397 _stateCtrl.adjustScrolls();
398 _stateCtrl.redraw();
399 _timeScaleCtrl.redraw();
400 }
401
402 @Override
403 public int getTimeSpace() {
404 int w = _stateCtrl.getClientArea().width;
405 return w - _nameWidth;
406 }
407
408 @Override
409 public long getSelectedTime() {
410 return _selectedTime;
411 }
412
413 @Override
414 public long getBeginTime() {
415 return _beginTime;
416 }
417
418 @Override
419 public long getEndTime() {
420 return _endTime;
421 }
422
423 @Override
424 public long getMaxTime() {
425 return _time1_;
426 }
427
428 @Override
429 public long getMinTime() {
430 return _time0_;
431 }
432
433 /*
434 * (non-Javadoc)
435 *
436 * @see
437 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
438 * #setStartFinishTimeNotify(long, long)
439 */
440 @Override
441 public void setStartFinishTimeNotify(long time0, long time1) {
442 setStartFinishTime(time0, time1);
443 notifyRangeListeners(time0, time1);
444 }
445
446
447 /* (non-Javadoc)
448 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
449 */
450 @Override
451 public void notifyStartFinishTime() {
452 notifyRangeListeners(_time0, _time1);
453 }
454
455 /*
456 * (non-Javadoc)
457 *
458 * @see
459 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
460 * #setStartFinishTime(long, long)
461 */
462 @Override
463 public void setStartFinishTime(long time0, long time1) {
464 _time0 = time0;
465 if (_time0 < _time0_)
466 _time0 = _time0_;
467 if (_time0 > _time1_)
468 _time0 = _time1_;
469 _time1 = time1;
470 if (_time1 < _time0_)
471 _time1 = _time0_;
472 if (_time1 > _time1_)
473 _time1 = _time1_;
474 if (_time1 - _time0 < _minTimeInterval)
475 _time1 = _time0 + _minTimeInterval;
476 _timeRangeFixed = true;
477 _stateCtrl.adjustScrolls();
478 _stateCtrl.redraw();
479 _timeScaleCtrl.redraw();
480 }
481
482 public void setTimeBounds(long beginTime, long endTime) {
483 _beginTime = beginTime;
484 _endTime = endTime;
485 _time0_ = beginTime;
486 _time1_ = endTime;
487 _stateCtrl.adjustScrolls();
488 }
489
490 @Override
491 public void resetStartFinishTime() {
492 setStartFinishTimeNotify(_time0_, _time1_);
493 _timeRangeFixed = false;
494 }
495
496 @Override
497 public void setSelectedTimeInt(long time, boolean ensureVisible) {
498 long time0 = _time0;
499 long time1 = _time1;
500 if (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);
505 _time0 -= dt;
506 _time1 -= dt;
507 } else if (time > _time1 - timeSpace) {
508 long dt = (long) (time - _time1 + timeMid);
509 _time0 += dt;
510 _time1 += dt;
511 }
512 if (_time0 < _time0_) {
513 _time1 = Math.min(_time1_, _time1 + (_time0_ - _time0));
514 _time0 = _time0_;
515 } else if (_time1 > _time1_) {
516 _time0 = Math.max(_time0_, _time0 - (_time1 - _time1_));
517 _time1 = _time1_;
518 }
519 }
520 if (_time1 - _time0 < _minTimeInterval) {
521 _time1 = _time0 + _minTimeInterval;
522 }
523 _stateCtrl.adjustScrolls();
524 _stateCtrl.redraw();
525 _timeScaleCtrl.redraw();
526 if (time0 != _time0 || time1 != _time1) {
527 notifyRangeListeners(_time0, _time1);
528 }
529 if (time != _selectedTime) {
530 _selectedTime = time;
531 notifyTimeListeners(_selectedTime);
532 }
533 }
534
535 @Override
536 public void widgetDefaultSelected(SelectionEvent e) {
537 if (_selectedEntry != getSelection()) {
538 _selectedEntry = getSelection();
539 notifySelectionListeners(_selectedEntry);
540 }
541 }
542
543 @Override
544 public void widgetSelected(SelectionEvent e) {
545 if (_selectedEntry != getSelection()) {
546 _selectedEntry = getSelection();
547 notifySelectionListeners(_selectedEntry);
548 }
549 }
550
551 public void selectNextEvent() {
552 _stateCtrl.selectNextEvent();
553 adjustVerticalScrollBar();
554 }
555
556 public void selectPrevEvent() {
557 _stateCtrl.selectPrevEvent();
558 adjustVerticalScrollBar();
559 }
560
561 public void selectNextItem() {
562 _stateCtrl.selectNextTrace();
563 adjustVerticalScrollBar();
564 }
565
566 public void selectPrevItem() {
567 _stateCtrl.selectPrevTrace();
568 adjustVerticalScrollBar();
569 }
570
571 public void showLegend() {
572 if (_dataViewer == null || _dataViewer.isDisposed())
573 return;
574
575 TimeGraphLegend.open(_dataViewer.getShell(), fTimeGraphProvider);
576 }
577
578 public void zoomIn() {
579 _stateCtrl.zoomIn();
580 }
581
582 public void zoomOut() {
583 _stateCtrl.zoomOut();
584 }
585
586 private String getPreferenceString(String string) {
587 return getViewTypeStr() + "." + string; //$NON-NLS-1$
588 }
589
590 public void addSelectionListener(ITimeGraphSelectionListener listener) {
591 fSelectionListeners.add(listener);
592 }
593
594 public void removeSelectionListener(ITimeGraphSelectionListener listener) {
595 fSelectionListeners.remove(listener);
596 }
597
598 private void notifySelectionListeners(ITimeGraphEntry selection) {
599 TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);
600
601 for (ITimeGraphSelectionListener listener : fSelectionListeners) {
602 listener.selectionChanged(event);
603 }
604 }
605
606 public void addTimeListener(ITimeGraphTimeListener listener) {
607 fTimeListeners.add(listener);
608 }
609
610 public void removeTimeListener(ITimeGraphTimeListener listener) {
611 fTimeListeners.remove(listener);
612 }
613
614 private void notifyTimeListeners(long time) {
615 TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, time);
616
617 for (ITimeGraphTimeListener listener : fTimeListeners) {
618 listener.timeSelected(event);
619 }
620 }
621
622 public void addRangeListener(ITimeGraphRangeListener listener) {
623 fRangeListeners.add(listener);
624 }
625
626 public void removeRangeListener(ITimeGraphRangeListener listener) {
627 fRangeListeners.remove(listener);
628 }
629
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);
635
636 for (ITimeGraphRangeListener listener : fRangeListeners) {
637 listener.timeRangeUpdated(event);
638 }
639
640 // update external synch timers
641 updateExtSynchTimers();
642 }
643 }
644
645 public void setSelectedTime(long time, boolean ensureVisible, Object source) {
646 if (this == source) {
647 return;
648 }
649
650 setSelectedTimeInt(time, ensureVisible);
651 }
652
653 public void setSelectedEvent(ITimeEvent event, Object source) {
654 if (event == null || source == this) {
655 return;
656 }
657 _selectedEntry = event.getEntry();
658 _stateCtrl.selectItem(_selectedEntry, false);
659
660 setSelectedTimeInt(event.getTime(), true);
661 adjustVerticalScrollBar();
662 }
663
664 public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {
665 if (trace == null || source == this) {
666 return;
667 }
668 _selectedEntry = trace;
669 _stateCtrl.selectItem(trace, false);
670
671 setSelectedTimeInt(time, true);
672 }
673
674 public void setSelection(ITimeGraphEntry trace) {
675 _selectedEntry = trace;
676 _stateCtrl.selectItem(trace, false);
677 adjustVerticalScrollBar();
678 }
679
680 public void setSelectVisTimeWindow(long time0, long time1, Object source) {
681 if (source == this) {
682 return;
683 }
684
685 setStartFinishTime(time0, time1);
686
687 // update notification time values since we are now in synch with the
688 // external application
689 updateExtSynchTimers();
690 }
691
692 /**
693 * update the cache timers used to identify the need to send a time window
694 * update to external registered listeners
695 */
696 private void updateExtSynchTimers() {
697 // last time notification cache
698 _time0_extSynch = _time0;
699 _time1_extSynch = _time1;
700 }
701
702 public void setTimeCalendarFormat(boolean toAbsoluteCaltime) {
703 calendarTimeFormat = toAbsoluteCaltime;
704 }
705
706 @Override
707 public boolean isCalendarFormat() {
708 return calendarTimeFormat;
709 }
710
711 public int getBorderWidth() {
712 return borderWidth;
713 }
714
715 public void setBorderWidth(int borderWidth) {
716 if (borderWidth > -1) {
717 this.borderWidth = borderWidth;
718 GridLayout gl = (GridLayout)_dataViewer.getLayout();
719 gl.marginHeight = borderWidth;
720 }
721 }
722
723 public int getHeaderHeight() {
724 return timeScaleHeight;
725 }
726
727 public void setHeaderHeight(int headerHeight) {
728 if (headerHeight > -1) {
729 this.timeScaleHeight = headerHeight;
730 _timeScaleCtrl.setHeight(headerHeight);
731 }
732 }
733
734 public int getItemHeight() {
735 if (_stateCtrl != null) {
736 return _stateCtrl.getItemHeight();
737 }
738 return 0;
739 }
740
741 public void setItemHeight(int rowHeight) {
742 if (_stateCtrl != null) {
743 _stateCtrl.setItemHeight(rowHeight);
744 }
745 }
746
747 public void setMinimumItemWidth(int width) {
748 if (_stateCtrl != null) {
749 _stateCtrl.setMinimumItemWidth(width);
750 }
751 }
752
753 public void setNameWidthPref(int width) {
754 _nameWidthPref = width;
755 if (width == 0) {
756 _minNameWidth = 0;
757 _nameWidth = 0;
758 }
759 }
760
761 public int getNameWidthPref(int width) {
762 return _nameWidthPref;
763 }
764
765 /**
766 * Returns the primary control associated with this viewer.
767 *
768 * @return the SWT control which displays this viewer's content
769 */
770 public Control getControl() {
771 return _dataViewer;
772 }
773
774 /**
775 * Returns the time graph control associated with this viewer.
776 *
777 * @return the time graph control
778 */
779 TimeGraphControl getTimeGraphControl() {
780 return _stateCtrl;
781 }
782
783 /**
784 * Get the selection provider
785 *
786 * @return the selection provider
787 */
788 public ISelectionProvider getSelectionProvider() {
789 return _stateCtrl;
790 }
791
792 /*
793 * (non-Javadoc)
794 *
795 * @see
796 * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer
797 * #waitCursor(boolean)
798 */
799 public void waitCursor(boolean waitInd) {
800 _stateCtrl.waitCursor(waitInd);
801 }
802
803 public ScrollBar getHorizontalBar() {
804 return _stateCtrl.getHorizontalBar();
805 }
806
807 public Slider getVerticalBar() {
808 return _verticalScrollBar;
809 }
810
811 public void setTopIndex(int index) {
812 _stateCtrl.setTopIndex(index);
813 adjustVerticalScrollBar();
814 }
815
816 public int getTopIndex() {
817 return _stateCtrl.getTopIndex();
818 }
819
820 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
821 _stateCtrl.setExpandedState(entry, expanded);
822 adjustVerticalScrollBar();
823 }
824
825 public void addTreeListener(ITimeGraphTreeListener listener) {
826 _stateCtrl.addTreeListener(listener);
827 }
828
829 public void removeTreeListener(ITimeGraphTreeListener listener) {
830 _stateCtrl.removeTreeListener(listener);
831 }
832
833 public Action getResetScaleAction() {
834 if (resetScale == null) {
835 // resetScale
836 resetScale = new Action() {
837 @Override
838 public void run() {
839 resetStartFinishTime();
840 }
841 };
842 resetScale.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
843 resetScale.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
844 resetScale.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
845 }
846 return resetScale;
847 }
848
849 public Action getShowLegendAction() {
850 if (showLegendAction == null) {
851 // showLegend
852 showLegendAction = new Action() {
853 @Override
854 public void run() {
855 showLegend();
856 }
857 };
858 showLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
859 showLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
860 showLegendAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
861 }
862
863 return showLegendAction;
864 }
865
866 public Action getNextEventAction() {
867 if (nextEventAction == null) {
868 nextEventAction = new Action() {
869 @Override
870 public void run() {
871 selectNextEvent();
872 }
873 };
874
875 nextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
876 nextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
877 nextEventAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
878 }
879
880 return nextEventAction;
881 }
882
883 public Action getPreviousEventAction() {
884 if (prevEventAction == null) {
885 prevEventAction = new Action() {
886 @Override
887 public void run() {
888 selectPrevEvent();
889 }
890 };
891
892 prevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
893 prevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
894 prevEventAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
895 }
896
897 return prevEventAction;
898 }
899
900 public Action getNextItemAction() {
901 if (nextItemAction == null) {
902
903 nextItemAction = new Action() {
904 @Override
905 public void run() {
906 selectNextItem();
907 }
908 };
909 nextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
910 nextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
911 nextItemAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
912 }
913 return nextItemAction;
914 }
915
916 public Action getPreviousItemAction() {
917 if (previousItemAction == null) {
918
919 previousItemAction = new Action() {
920 @Override
921 public void run() {
922 selectPrevItem();
923 }
924 };
925 previousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
926 previousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
927 previousItemAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
928 }
929 return previousItemAction;
930 }
931
932 public Action getZoomInAction() {
933 if (zoomInAction == null) {
934 zoomInAction = new Action() {
935 @Override
936 public void run() {
937 zoomIn();
938 }
939 };
940 zoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
941 zoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
942 zoomInAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
943 }
944 return zoomInAction;
945 }
946
947 public Action getZoomOutAction() {
948 if (zoomOutAction == null) {
949 zoomOutAction = new Action() {
950 @Override
951 public void run() {
952 zoomOut();
953 }
954 };
955 zoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
956 zoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
957 zoomOutAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
958 }
959 return zoomOutAction;
960 }
961
962
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));
969 }
970
971 int selection = _stateCtrl.getTopIndex();
972 int min = 0;
973 int max = Math.max(1, expandedElementCount - 1);
974 int thumb = Math.min(max, Math.max(1, countPerPage - 1));
975 int increment = 1;
976 int pageIncrement = Math.max(1, countPerPage);
977 _verticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
978 }
979
980
981
982 }
This page took 0.089697 seconds and 5 git commands to generate.