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