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