tmf: Merge ITimeDataProvider2 back into ITimeDataProvider
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / TimeGraphViewer.java
1 /*****************************************************************************
2 * Copyright (c) 2007, 2014 Intel Corporation, Ericsson, others
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 * Geneviève Bastien - Add event links between entries
15 *****************************************************************************/
16
17 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.dialogs.IDialogSettings;
25 import org.eclipse.jface.viewers.ISelectionProvider;
26 import org.eclipse.jface.viewers.ViewerFilter;
27 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
28 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
29 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
30 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend;
31 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
32 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
33 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
34 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
35 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
36 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
37 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
38 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler;
39 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
40 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
41 import org.eclipse.swt.SWT;
42 import org.eclipse.swt.events.ControlAdapter;
43 import org.eclipse.swt.events.ControlEvent;
44 import org.eclipse.swt.events.KeyAdapter;
45 import org.eclipse.swt.events.KeyEvent;
46 import org.eclipse.swt.events.MenuDetectListener;
47 import org.eclipse.swt.events.MouseEvent;
48 import org.eclipse.swt.events.MouseWheelListener;
49 import org.eclipse.swt.events.SelectionAdapter;
50 import org.eclipse.swt.events.SelectionEvent;
51 import org.eclipse.swt.events.SelectionListener;
52 import org.eclipse.swt.graphics.Rectangle;
53 import org.eclipse.swt.layout.FillLayout;
54 import org.eclipse.swt.layout.GridData;
55 import org.eclipse.swt.layout.GridLayout;
56 import org.eclipse.swt.widgets.Composite;
57 import org.eclipse.swt.widgets.Control;
58 import org.eclipse.swt.widgets.ScrollBar;
59 import org.eclipse.swt.widgets.Slider;
60
61 /**
62 * Generic time graph viewer implementation
63 *
64 * @version 1.0
65 * @author Patrick Tasse, and others
66 */
67 public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
68
69 private static final int DEFAULT_NAME_WIDTH = 200;
70 private static final int MIN_NAME_WIDTH = 6;
71 private static final int MAX_NAME_WIDTH = 1000;
72 private static final int DEFAULT_HEIGHT = 22;
73 private static final long RECENTERING_MARGIN_FACTOR = 50;
74 private static final String HIDE_ARROWS_KEY = "hide.arrows"; //$NON-NLS-1$
75
76 private long fMinTimeInterval;
77 private ITimeGraphEntry fSelectedEntry;
78 private long fBeginTime;
79 private long fEndTime;
80 private long fTime0;
81 private long fTime1;
82 private long fSelectionBegin = 0;
83 private long fSelectionEnd = 0;
84 private long fTime0Bound;
85 private long fTime1Bound;
86 private long fTime0ExtSynch = 0;
87 private long fTime1ExtSynch = 0;
88 private boolean fTimeRangeFixed;
89 private int fNameWidthPref = DEFAULT_NAME_WIDTH;
90 private int fMinNameWidth = MIN_NAME_WIDTH;
91 private int fNameWidth;
92 private Composite fDataViewer;
93
94 private TimeGraphControl fTimeGraphCtrl;
95 private TimeGraphScale fTimeScaleCtrl;
96 private Slider fVerticalScrollBar;
97 private TimeGraphColorScheme fColorScheme;
98 private Object fInputElement;
99 private ITimeGraphContentProvider fTimeGraphContentProvider;
100 private ITimeGraphPresentationProvider fTimeGraphProvider;
101
102 private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<>();
103 private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<>();
104 private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<>();
105
106 // Time format, using Epoch reference, Relative time format(default) or
107 // Number
108 private TimeFormat fTimeFormat = TimeFormat.RELATIVE;
109 private int fBorderWidth = 0;
110 private int fTimeScaleHeight = DEFAULT_HEIGHT;
111
112 private Action fResetScaleAction;
113 private Action fShowLegendAction;
114 private Action fNextEventAction;
115 private Action fPrevEventAction;
116 private Action fNextItemAction;
117 private Action fPreviousItemAction;
118 private Action fZoomInAction;
119 private Action fZoomOutAction;
120 private Action fHideArrowsAction;
121 private Action fFollowArrowFwdAction;
122 private Action fFollowArrowBwdAction;
123
124 /**
125 * Standard constructor.
126 * <p>
127 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
128 *
129 * @param parent
130 * The parent UI composite object
131 * @param style
132 * The style to use
133 */
134 public TimeGraphViewer(Composite parent, int style) {
135 createDataViewer(parent, style);
136 fTimeGraphContentProvider = new ITimeGraphContentProvider() {
137 @Override
138 public ITimeGraphEntry[] getElements(Object inputElement) {
139 if (inputElement instanceof ITimeGraphEntry[]) {
140 return (ITimeGraphEntry[]) inputElement;
141 }
142 return new ITimeGraphEntry[0];
143 }
144 };
145 }
146
147 /**
148 * Sets the timegraph content provider used by this timegraph viewer.
149 *
150 * @param timeGraphContentProvider
151 * the timegraph content provider
152 *
153 * @since 3.0
154 */
155 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) {
156 fTimeGraphContentProvider = timeGraphContentProvider;
157 }
158
159 /**
160 * Gets the timegraph content provider used by this timegraph viewer.
161 *
162 * @return the timegraph content provider
163 *
164 * @since 3.0
165 */
166 public ITimeGraphContentProvider getTimeGraphContentProvider() {
167 return fTimeGraphContentProvider;
168 }
169
170 /**
171 * Sets the timegraph presentation provider used by this timegraph viewer.
172 *
173 * @param timeGraphProvider
174 * the timegraph provider
175 */
176 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
177 fTimeGraphProvider = timeGraphProvider;
178 fTimeGraphCtrl.setTimeGraphProvider(timeGraphProvider);
179 TimeGraphTooltipHandler toolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, this);
180 toolTipHandler.activateHoverHelp(fTimeGraphCtrl);
181 }
182
183 /**
184 * Sets or clears the input for this time graph viewer.
185 *
186 * @param inputElement
187 * The input of this time graph viewer, or <code>null</code> if
188 * none
189 *
190 * @since 3.0
191 */
192 public void setInput(Object inputElement) {
193 fInputElement = inputElement;
194 ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(inputElement);
195
196 if (fTimeGraphCtrl != null) {
197 setTimeRange(input);
198 fVerticalScrollBar.setEnabled(true);
199 setTopIndex(0);
200 fSelectionBegin = 0;
201 fSelectionEnd = 0;
202 fSelectedEntry = null;
203 refreshAllData(input);
204 }
205 }
206
207 /**
208 * Gets the input for this time graph viewer.
209 *
210 * @return The input of this time graph viewer, or <code>null</code> if none
211 *
212 * @since 3.0
213 */
214 public Object getInput() {
215 return fInputElement;
216 }
217
218 /**
219 * Sets (or clears if null) the list of links to display on this combo
220 *
221 * @param links
222 * the links to display in this time graph combo
223 * @since 2.1
224 */
225 public void setLinks(List<ILinkEvent> links) {
226 if (fTimeGraphCtrl != null) {
227 fTimeGraphCtrl.refreshArrows(links);
228 }
229 }
230
231 /**
232 * Refresh the view
233 */
234 public void refresh() {
235 ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(fInputElement);
236 setTimeRange(input);
237 fVerticalScrollBar.setEnabled(true);
238 refreshAllData(input);
239 }
240
241 /**
242 * Callback for when the control is moved
243 *
244 * @param e
245 * The caller event
246 */
247 public void controlMoved(ControlEvent e) {
248 }
249
250 /**
251 * Callback for when the control is resized
252 *
253 * @param e
254 * The caller event
255 */
256 public void controlResized(ControlEvent e) {
257 resizeControls();
258 }
259
260 /**
261 * Handler for when the model is updated. Called from the display order in
262 * the API
263 *
264 * @param traces
265 * The traces in the model
266 * @param start
267 * The start time
268 * @param end
269 * The end time
270 * @param updateTimeBounds
271 * Should we updated the time bounds too
272 */
273 public void modelUpdate(ITimeGraphEntry[] traces, long start,
274 long end, boolean updateTimeBounds) {
275 if (null != fTimeGraphCtrl) {
276 updateInternalData(traces, start, end);
277 if (updateTimeBounds) {
278 fTimeRangeFixed = true;
279 // set window to match limits
280 setStartFinishTime(fTime0Bound, fTime1Bound);
281 } else {
282 fTimeGraphCtrl.redraw();
283 fTimeScaleCtrl.redraw();
284 }
285 }
286 }
287
288 /**
289 * @return The string representing the view type
290 */
291 protected String getViewTypeStr() {
292 return "viewoption.threads"; //$NON-NLS-1$
293 }
294
295 int getMarginWidth() {
296 return 0;
297 }
298
299 int getMarginHeight() {
300 return 0;
301 }
302
303 void loadOptions() {
304 fMinTimeInterval = 1;
305 fSelectionBegin = -1;
306 fSelectionEnd = -1;
307 fNameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
308 fNameWidthPref, fMinNameWidth, MAX_NAME_WIDTH);
309 }
310
311 void saveOptions() {
312 Utils.saveIntOption(getPreferenceString("namewidth"), fNameWidth); //$NON-NLS-1$
313 }
314
315 /**
316 * Create a data viewer.
317 *
318 * @param parent
319 * Parent composite
320 * @param style
321 * Style to use
322 * @return The new data viewer
323 */
324 protected Control createDataViewer(Composite parent, int style) {
325 loadOptions();
326 fColorScheme = new TimeGraphColorScheme();
327 fDataViewer = new Composite(parent, style) {
328 @Override
329 public void redraw() {
330 fTimeScaleCtrl.redraw();
331 fTimeGraphCtrl.redraw();
332 super.redraw();
333 }
334 };
335 GridLayout gl = new GridLayout(2, false);
336 gl.marginHeight = fBorderWidth;
337 gl.marginWidth = 0;
338 gl.verticalSpacing = 0;
339 gl.horizontalSpacing = 0;
340 fDataViewer.setLayout(gl);
341
342 fTimeScaleCtrl = new TimeGraphScale(fDataViewer, fColorScheme);
343 fTimeScaleCtrl.setTimeProvider(this);
344 fTimeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
345 fTimeScaleCtrl.setHeight(fTimeScaleHeight);
346
347 fVerticalScrollBar = new Slider(fDataViewer, SWT.VERTICAL | SWT.NO_FOCUS);
348 fVerticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2));
349 fVerticalScrollBar.addSelectionListener(new SelectionAdapter() {
350 @Override
351 public void widgetSelected(SelectionEvent e) {
352 setTopIndex(fVerticalScrollBar.getSelection());
353 }
354 });
355 fVerticalScrollBar.setEnabled(false);
356
357 fTimeGraphCtrl = createTimeGraphControl(fDataViewer, fColorScheme);
358
359 fTimeGraphCtrl.setTimeProvider(this);
360 fTimeGraphCtrl.setTimeGraphScale(fTimeScaleCtrl);
361 fTimeGraphCtrl.addSelectionListener(this);
362 fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
363 fTimeGraphCtrl.addMouseWheelListener(new MouseWheelListener() {
364 @Override
365 public void mouseScrolled(MouseEvent e) {
366 adjustVerticalScrollBar();
367 }
368 });
369 fTimeGraphCtrl.addKeyListener(new KeyAdapter() {
370 @Override
371 public void keyPressed(KeyEvent e) {
372 adjustVerticalScrollBar();
373 }
374 });
375
376 Composite filler = new Composite(fDataViewer, SWT.NONE);
377 GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
378 gd.heightHint = fTimeGraphCtrl.getHorizontalBar().getSize().y;
379 filler.setLayoutData(gd);
380 filler.setLayout(new FillLayout());
381
382 fTimeGraphCtrl.addControlListener(new ControlAdapter() {
383 @Override
384 public void controlResized(ControlEvent event) {
385 resizeControls();
386 }
387 });
388 resizeControls();
389 fDataViewer.update();
390 adjustVerticalScrollBar();
391 return fDataViewer;
392 }
393
394 /**
395 * Dispose the view.
396 */
397 public void dispose() {
398 saveOptions();
399 fTimeGraphCtrl.dispose();
400 fDataViewer.dispose();
401 fColorScheme.dispose();
402 }
403
404 /**
405 * Create a new time graph control.
406 *
407 * @param parent
408 * The parent composite
409 * @param colors
410 * The color scheme
411 * @return The new TimeGraphControl
412 * @since 2.0
413 */
414 protected TimeGraphControl createTimeGraphControl(Composite parent,
415 TimeGraphColorScheme colors) {
416 return new TimeGraphControl(parent, colors);
417 }
418
419 /**
420 * Resize the controls
421 */
422 public void resizeControls() {
423 Rectangle r = fDataViewer.getClientArea();
424 if (r.isEmpty()) {
425 return;
426 }
427
428 int width = r.width;
429 if (fNameWidth > width - fMinNameWidth) {
430 fNameWidth = width - fMinNameWidth;
431 }
432 if (fNameWidth < fMinNameWidth) {
433 fNameWidth = fMinNameWidth;
434 }
435 adjustVerticalScrollBar();
436 }
437
438 /**
439 * Try to set most convenient time range for display.
440 *
441 * @param traces
442 * The traces in the model
443 */
444 public void setTimeRange(ITimeGraphEntry traces[]) {
445 fEndTime = 0;
446 fBeginTime = -1;
447 for (int i = 0; i < traces.length; i++) {
448 ITimeGraphEntry entry = traces[i];
449 if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) {
450 if (fBeginTime < 0 || entry.getStartTime() < fBeginTime) {
451 fBeginTime = entry.getStartTime();
452 }
453 if (entry.getEndTime() > fEndTime) {
454 fEndTime = entry.getEndTime();
455 }
456 }
457 }
458
459 if (fBeginTime < 0) {
460 fBeginTime = 0;
461 }
462 }
463
464 /**
465 * Recalculate the time bounds
466 */
467 public void setTimeBounds() {
468 fTime0Bound = fBeginTime;
469 if (fTime0Bound < 0) {
470 fTime0Bound = 0;
471 }
472 fTime1Bound = fEndTime;
473 if (!fTimeRangeFixed) {
474 fTime0 = fTime0Bound;
475 fTime1 = fTime1Bound;
476 }
477 fTime0 = Math.max(fTime0Bound, Math.min(fTime0, fTime1Bound));
478 fTime1 = Math.max(fTime0Bound, Math.min(fTime1, fTime1Bound));
479 if (fTime1 - fTime0 < fMinTimeInterval) {
480 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
481 }
482 }
483
484 /**
485 * @param traces
486 * @param start
487 * @param end
488 */
489 void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {
490 ITimeGraphEntry[] realTraces = traces;
491
492 if (null == realTraces) {
493 realTraces = new ITimeGraphEntry[0];
494 }
495 if ((start == 0 && end == 0) || start < 0 || end < 0) {
496 // Start and end time are unspecified and need to be determined from
497 // individual processes
498 setTimeRange(realTraces);
499 } else {
500 fBeginTime = start;
501 fEndTime = end;
502 }
503
504 refreshAllData(realTraces);
505 }
506
507 /**
508 * @param traces
509 */
510 private void refreshAllData(ITimeGraphEntry[] traces) {
511 setTimeBounds();
512 if (fSelectionBegin < fBeginTime) {
513 fSelectionBegin = fBeginTime;
514 } else if (fSelectionBegin > fEndTime) {
515 fSelectionBegin = fEndTime;
516 }
517 if (fSelectionEnd < fBeginTime) {
518 fSelectionEnd = fBeginTime;
519 } else if (fSelectionEnd > fEndTime) {
520 fSelectionEnd = fEndTime;
521 }
522 fTimeGraphCtrl.refreshData(traces);
523 fTimeScaleCtrl.redraw();
524 adjustVerticalScrollBar();
525 }
526
527 /**
528 * Callback for when this view is focused
529 */
530 public void setFocus() {
531 if (null != fTimeGraphCtrl) {
532 fTimeGraphCtrl.setFocus();
533 }
534 }
535
536 /**
537 * Get the current focus status of this view.
538 *
539 * @return If the view is currently focused, or not
540 */
541 public boolean isInFocus() {
542 return fTimeGraphCtrl.isInFocus();
543 }
544
545 /**
546 * Get the view's current selection
547 *
548 * @return The entry that is selected
549 */
550 public ITimeGraphEntry getSelection() {
551 return fTimeGraphCtrl.getSelectedTrace();
552 }
553
554 /**
555 * Get the index of the current selection
556 *
557 * @return The index
558 */
559 public int getSelectionIndex() {
560 return fTimeGraphCtrl.getSelectedIndex();
561 }
562
563 @Override
564 public long getTime0() {
565 return fTime0;
566 }
567
568 @Override
569 public long getTime1() {
570 return fTime1;
571 }
572
573 @Override
574 public long getMinTimeInterval() {
575 return fMinTimeInterval;
576 }
577
578 @Override
579 public int getNameSpace() {
580 return fNameWidth;
581 }
582
583 @Override
584 public void setNameSpace(int width) {
585 fNameWidth = width;
586 int w = fTimeGraphCtrl.getClientArea().width;
587 if (fNameWidth > w - MIN_NAME_WIDTH) {
588 fNameWidth = w - MIN_NAME_WIDTH;
589 }
590 if (fNameWidth < MIN_NAME_WIDTH) {
591 fNameWidth = MIN_NAME_WIDTH;
592 }
593 fTimeGraphCtrl.adjustScrolls();
594 fTimeGraphCtrl.redraw();
595 fTimeScaleCtrl.redraw();
596 }
597
598 @Override
599 public int getTimeSpace() {
600 int w = fTimeGraphCtrl.getClientArea().width;
601 return w - fNameWidth;
602 }
603
604 @Override
605 public long getBeginTime() {
606 return fBeginTime;
607 }
608
609 @Override
610 public long getEndTime() {
611 return fEndTime;
612 }
613
614 @Override
615 public long getMaxTime() {
616 return fTime1Bound;
617 }
618
619 @Override
620 public long getMinTime() {
621 return fTime0Bound;
622 }
623
624 /**
625 * @since 2.1
626 */
627 @Override
628 public long getSelectionBegin() {
629 return fSelectionBegin;
630 }
631
632 /**
633 * @since 2.1
634 */
635 @Override
636 public long getSelectionEnd() {
637 return fSelectionEnd;
638 }
639
640 @Override
641 public void setStartFinishTimeNotify(long time0, long time1) {
642 setStartFinishTime(time0, time1);
643 notifyRangeListeners(time0, time1);
644 }
645
646 @Override
647 public void notifyStartFinishTime() {
648 notifyRangeListeners(fTime0, fTime1);
649 }
650
651 @Override
652 public void setStartFinishTime(long time0, long time1) {
653 fTime0 = time0;
654 if (fTime0 < fTime0Bound) {
655 fTime0 = fTime0Bound;
656 }
657 if (fTime0 > fTime1Bound) {
658 fTime0 = fTime1Bound;
659 }
660 fTime1 = time1;
661 if (fTime1 < fTime0Bound) {
662 fTime1 = fTime0Bound;
663 }
664 if (fTime1 > fTime1Bound) {
665 fTime1 = fTime1Bound;
666 }
667 if (fTime1 - fTime0 < fMinTimeInterval) {
668 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
669 }
670 fTimeRangeFixed = true;
671 fTimeGraphCtrl.adjustScrolls();
672 fTimeGraphCtrl.redraw();
673 fTimeScaleCtrl.redraw();
674 }
675
676 /**
677 * Set the time bounds to the provided values
678 *
679 * @param beginTime
680 * The start time of the window
681 * @param endTime
682 * The end time
683 */
684 public void setTimeBounds(long beginTime, long endTime) {
685 if (endTime >= beginTime) {
686 fBeginTime = beginTime;
687 fEndTime = endTime;
688 fTime0Bound = beginTime;
689 fTime1Bound = endTime;
690 } else {
691 fBeginTime = 0;
692 fEndTime = 0;
693 fTime0Bound = 0;
694 fTime1Bound = 0;
695 }
696 fTimeGraphCtrl.adjustScrolls();
697 }
698
699 @Override
700 public void resetStartFinishTime() {
701 setStartFinishTime(fTime0Bound, fTime1Bound);
702 fTimeRangeFixed = false;
703 }
704
705 @Override
706 public void setSelectedTimeNotify(long time, boolean ensureVisible) {
707 setSelectedTimeInt(time, ensureVisible, true);
708 }
709
710 @Override
711 public void setSelectedTime(long time, boolean ensureVisible) {
712 setSelectedTimeInt(time, ensureVisible, false);
713 }
714
715 /**
716 * @since 2.1
717 */
718 @Override
719 public void setSelectionRangeNotify(long beginTime, long endTime) {
720 boolean changed = (beginTime != fSelectionBegin || endTime != fSelectionEnd);
721 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
722 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
723 fTimeGraphCtrl.redraw();
724 fTimeScaleCtrl.redraw();
725 if (changed) {
726 notifyTimeListeners(fSelectionBegin, fSelectionEnd);
727 }
728 }
729
730 /**
731 * @since 2.1
732 */
733 @Override
734 public void setSelectionRange(long beginTime, long endTime) {
735 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
736 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
737 fTimeGraphCtrl.redraw();
738 fTimeScaleCtrl.redraw();
739 }
740
741 private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
742 long time0 = fTime0;
743 long time1 = fTime1;
744 if (ensureVisible) {
745 long timeSpace = (fTime1 - fTime0) / RECENTERING_MARGIN_FACTOR;
746 long timeMid = (fTime1 - fTime0) / 2;
747 if (time < fTime0 + timeSpace) {
748 long dt = fTime0 - time + timeMid;
749 fTime0 -= dt;
750 fTime1 -= dt;
751 } else if (time > fTime1 - timeSpace) {
752 long dt = time - fTime1 + timeMid;
753 fTime0 += dt;
754 fTime1 += dt;
755 }
756 if (fTime0 < fTime0Bound) {
757 fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0));
758 fTime0 = fTime0Bound;
759 } else if (fTime1 > fTime1Bound) {
760 fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound));
761 fTime1 = fTime1Bound;
762 }
763 }
764 if (fTime1 - fTime0 < fMinTimeInterval) {
765 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
766 }
767 fTimeGraphCtrl.adjustScrolls();
768 fTimeGraphCtrl.redraw();
769 fTimeScaleCtrl.redraw();
770
771 boolean notifySelectedTime = (time != fSelectionBegin || time != fSelectionEnd);
772 fSelectionBegin = time;
773 fSelectionEnd = time;
774
775 if (doNotify && ((time0 != fTime0) || (time1 != fTime1))) {
776 notifyRangeListeners(fTime0, fTime1);
777 }
778
779 if (doNotify && notifySelectedTime) {
780 notifyTimeListeners(fSelectionBegin, fSelectionEnd);
781 }
782 }
783
784 @Override
785 public void widgetDefaultSelected(SelectionEvent e) {
786 if (fSelectedEntry != getSelection()) {
787 fSelectedEntry = getSelection();
788 notifySelectionListeners(fSelectedEntry);
789 }
790 }
791
792 @Override
793 public void widgetSelected(SelectionEvent e) {
794 if (fSelectedEntry != getSelection()) {
795 fSelectedEntry = getSelection();
796 notifySelectionListeners(fSelectedEntry);
797 }
798 }
799
800 /**
801 * Callback for when the next event is selected
802 */
803 public void selectNextEvent() {
804 fTimeGraphCtrl.selectNextEvent();
805 adjustVerticalScrollBar();
806 }
807
808 /**
809 * Callback for when the previous event is selected
810 */
811 public void selectPrevEvent() {
812 fTimeGraphCtrl.selectPrevEvent();
813 adjustVerticalScrollBar();
814 }
815
816 /**
817 * Callback for when the next item is selected
818 */
819 public void selectNextItem() {
820 fTimeGraphCtrl.selectNextTrace();
821 adjustVerticalScrollBar();
822 }
823
824 /**
825 * Callback for when the previous item is selected
826 */
827 public void selectPrevItem() {
828 fTimeGraphCtrl.selectPrevTrace();
829 adjustVerticalScrollBar();
830 }
831
832 /**
833 * Callback for the show legend action
834 */
835 public void showLegend() {
836 if (fDataViewer == null || fDataViewer.isDisposed()) {
837 return;
838 }
839
840 TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider);
841 }
842
843 /**
844 * Callback for the Zoom In action
845 */
846 public void zoomIn() {
847 fTimeGraphCtrl.zoomIn();
848 }
849
850 /**
851 * Callback for the Zoom Out action
852 */
853 public void zoomOut() {
854 fTimeGraphCtrl.zoomOut();
855 }
856
857 private String getPreferenceString(String string) {
858 return getViewTypeStr() + "." + string; //$NON-NLS-1$
859 }
860
861 /**
862 * Add a selection listener
863 *
864 * @param listener
865 * The listener to add
866 */
867 public void addSelectionListener(ITimeGraphSelectionListener listener) {
868 fSelectionListeners.add(listener);
869 }
870
871 /**
872 * Remove a selection listener
873 *
874 * @param listener
875 * The listener to remove
876 */
877 public void removeSelectionListener(ITimeGraphSelectionListener listener) {
878 fSelectionListeners.remove(listener);
879 }
880
881 private void notifySelectionListeners(ITimeGraphEntry selection) {
882 TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);
883
884 for (ITimeGraphSelectionListener listener : fSelectionListeners) {
885 listener.selectionChanged(event);
886 }
887 }
888
889 /**
890 * Add a time listener
891 *
892 * @param listener
893 * The listener to add
894 */
895 public void addTimeListener(ITimeGraphTimeListener listener) {
896 fTimeListeners.add(listener);
897 }
898
899 /**
900 * Remove a time listener
901 *
902 * @param listener
903 * The listener to remove
904 */
905 public void removeTimeListener(ITimeGraphTimeListener listener) {
906 fTimeListeners.remove(listener);
907 }
908
909 private void notifyTimeListeners(long startTime, long endTime) {
910 TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime);
911
912 for (ITimeGraphTimeListener listener : fTimeListeners) {
913 listener.timeSelected(event);
914 }
915 }
916
917 /**
918 * Add a range listener
919 *
920 * @param listener
921 * The listener to add
922 */
923 public void addRangeListener(ITimeGraphRangeListener listener) {
924 fRangeListeners.add(listener);
925 }
926
927 /**
928 * Remove a range listener
929 *
930 * @param listener
931 * The listener to remove
932 */
933 public void removeRangeListener(ITimeGraphRangeListener listener) {
934 fRangeListeners.remove(listener);
935 }
936
937 private void notifyRangeListeners(long startTime, long endTime) {
938 // Check if the time has actually changed from last notification
939 if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) {
940 // Notify Time Scale Selection Listeners
941 TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);
942
943 for (ITimeGraphRangeListener listener : fRangeListeners) {
944 listener.timeRangeUpdated(event);
945 }
946
947 // update external synch timers
948 updateExtSynchTimers();
949 }
950 }
951
952 /**
953 * Callback to set a selected event in the view
954 *
955 * @param event
956 * The event that was selected
957 * @param source
958 * The source of this selection event
959 */
960 public void setSelectedEvent(ITimeEvent event, Object source) {
961 if (event == null || source == this) {
962 return;
963 }
964 fSelectedEntry = event.getEntry();
965 fTimeGraphCtrl.selectItem(fSelectedEntry, false);
966
967 setSelectedTimeInt(event.getTime(), true, true);
968 adjustVerticalScrollBar();
969 }
970
971 /**
972 * Set the seeked time of a trace
973 *
974 * @param trace
975 * The trace that was seeked
976 * @param time
977 * The target time
978 * @param source
979 * The source of this seek event
980 */
981 public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {
982 if (trace == null || source == this) {
983 return;
984 }
985 fSelectedEntry = trace;
986 fTimeGraphCtrl.selectItem(trace, false);
987
988 setSelectedTimeInt(time, true, true);
989 }
990
991 /**
992 * Callback for a trace selection
993 *
994 * @param trace
995 * The trace that was selected
996 */
997 public void setSelection(ITimeGraphEntry trace) {
998 fSelectedEntry = trace;
999 fTimeGraphCtrl.selectItem(trace, false);
1000 adjustVerticalScrollBar();
1001 }
1002
1003 /**
1004 * Callback for a time window selection
1005 *
1006 * @param time0
1007 * Start time of the range
1008 * @param time1
1009 * End time of the range
1010 * @param source
1011 * Source of the event
1012 */
1013 public void setSelectVisTimeWindow(long time0, long time1, Object source) {
1014 if (source == this) {
1015 return;
1016 }
1017
1018 setStartFinishTime(time0, time1);
1019
1020 // update notification time values since we are now in synch with the
1021 // external application
1022 updateExtSynchTimers();
1023 }
1024
1025 /**
1026 * update the cache timers used to identify the need to send a time window
1027 * update to external registered listeners
1028 */
1029 private void updateExtSynchTimers() {
1030 // last time notification cache
1031 fTime0ExtSynch = fTime0;
1032 fTime1ExtSynch = fTime1;
1033 }
1034
1035 /**
1036 * @since 2.0
1037 */
1038 @Override
1039 public TimeFormat getTimeFormat() {
1040 return fTimeFormat;
1041 }
1042
1043 /**
1044 * @param tf
1045 * the {@link TimeFormat} used to display timestamps
1046 * @since 2.0
1047 */
1048 public void setTimeFormat(TimeFormat tf) {
1049 this.fTimeFormat = tf;
1050 }
1051
1052 /**
1053 * Retrieve the border width
1054 *
1055 * @return The width
1056 */
1057 public int getBorderWidth() {
1058 return fBorderWidth;
1059 }
1060
1061 /**
1062 * Set the border width
1063 *
1064 * @param borderWidth
1065 * The width
1066 */
1067 public void setBorderWidth(int borderWidth) {
1068 if (borderWidth > -1) {
1069 this.fBorderWidth = borderWidth;
1070 GridLayout gl = (GridLayout) fDataViewer.getLayout();
1071 gl.marginHeight = borderWidth;
1072 }
1073 }
1074
1075 /**
1076 * Retrieve the height of the header
1077 *
1078 * @return The height
1079 */
1080 public int getHeaderHeight() {
1081 return fTimeScaleHeight;
1082 }
1083
1084 /**
1085 * Set the height of the header
1086 *
1087 * @param headerHeight
1088 * The height to set
1089 */
1090 public void setHeaderHeight(int headerHeight) {
1091 if (headerHeight > -1) {
1092 this.fTimeScaleHeight = headerHeight;
1093 fTimeScaleCtrl.setHeight(headerHeight);
1094 }
1095 }
1096
1097 /**
1098 * Retrieve the height of an item row
1099 *
1100 * @return The height
1101 */
1102 public int getItemHeight() {
1103 if (fTimeGraphCtrl != null) {
1104 return fTimeGraphCtrl.getItemHeight();
1105 }
1106 return 0;
1107 }
1108
1109 /**
1110 * Set the height of an item row
1111 *
1112 * @param rowHeight
1113 * The height to set
1114 */
1115 public void setItemHeight(int rowHeight) {
1116 if (fTimeGraphCtrl != null) {
1117 fTimeGraphCtrl.setItemHeight(rowHeight);
1118 }
1119 }
1120
1121 /**
1122 * Set the minimum item width
1123 *
1124 * @param width
1125 * The min width
1126 */
1127 public void setMinimumItemWidth(int width) {
1128 if (fTimeGraphCtrl != null) {
1129 fTimeGraphCtrl.setMinimumItemWidth(width);
1130 }
1131 }
1132
1133 /**
1134 * Set the width for the name column
1135 *
1136 * @param width
1137 * The width
1138 */
1139 public void setNameWidthPref(int width) {
1140 fNameWidthPref = width;
1141 if (width == 0) {
1142 fMinNameWidth = 0;
1143 fNameWidth = 0;
1144 }
1145 }
1146
1147 /**
1148 * Retrieve the configure width for the name column
1149 *
1150 * @param width
1151 * Unused?
1152 * @return The width
1153 */
1154 public int getNameWidthPref(int width) {
1155 return fNameWidthPref;
1156 }
1157
1158 /**
1159 * Returns the primary control associated with this viewer.
1160 *
1161 * @return the SWT control which displays this viewer's content
1162 */
1163 public Control getControl() {
1164 return fDataViewer;
1165 }
1166
1167 /**
1168 * Returns the time graph control associated with this viewer.
1169 *
1170 * @return the time graph control
1171 * @since 2.0
1172 */
1173 public TimeGraphControl getTimeGraphControl() {
1174 return fTimeGraphCtrl;
1175 }
1176
1177 /**
1178 * Returns the time graph scale associated with this viewer.
1179 *
1180 * @return the time graph scale
1181 * @since 2.0
1182 */
1183 public TimeGraphScale getTimeGraphScale() {
1184 return fTimeScaleCtrl;
1185 }
1186
1187 /**
1188 * Return the x coordinate corresponding to a time
1189 *
1190 * @param time
1191 * the time
1192 * @return the x coordinate corresponding to the time
1193 *
1194 * @since 2.0
1195 */
1196 public int getXForTime(long time) {
1197 return fTimeGraphCtrl.getXForTime(time);
1198 }
1199
1200 /**
1201 * Return the time corresponding to an x coordinate
1202 *
1203 * @param x
1204 * the x coordinate
1205 * @return the time corresponding to the x coordinate
1206 *
1207 * @since 2.0
1208 */
1209 public long getTimeAtX(int x) {
1210 return fTimeGraphCtrl.getTimeAtX(x);
1211 }
1212
1213 /**
1214 * Get the selection provider
1215 *
1216 * @return the selection provider
1217 */
1218 public ISelectionProvider getSelectionProvider() {
1219 return fTimeGraphCtrl;
1220 }
1221
1222 /**
1223 * Wait for the cursor
1224 *
1225 * @param waitInd
1226 * Wait indefinitely?
1227 */
1228 public void waitCursor(boolean waitInd) {
1229 fTimeGraphCtrl.waitCursor(waitInd);
1230 }
1231
1232 /**
1233 * Get the horizontal scroll bar object
1234 *
1235 * @return The scroll bar
1236 */
1237 public ScrollBar getHorizontalBar() {
1238 return fTimeGraphCtrl.getHorizontalBar();
1239 }
1240
1241 /**
1242 * Get the vertical scroll bar object
1243 *
1244 * @return The scroll bar
1245 */
1246 public Slider getVerticalBar() {
1247 return fVerticalScrollBar;
1248 }
1249
1250 /**
1251 * Set the given index as the top one
1252 *
1253 * @param index
1254 * The index that will go to the top
1255 */
1256 public void setTopIndex(int index) {
1257 fTimeGraphCtrl.setTopIndex(index);
1258 adjustVerticalScrollBar();
1259 }
1260
1261 /**
1262 * Retrieve the current top index
1263 *
1264 * @return The top index
1265 */
1266 public int getTopIndex() {
1267 return fTimeGraphCtrl.getTopIndex();
1268 }
1269
1270 /**
1271 * Set the expanded state of an entry
1272 *
1273 * @param entry
1274 * The entry to expand/collapse
1275 * @param expanded
1276 * True for expanded, false for collapsed
1277 */
1278 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
1279 fTimeGraphCtrl.setExpandedState(entry, expanded);
1280 adjustVerticalScrollBar();
1281 }
1282
1283 /**
1284 * Collapses all nodes of the viewer's tree, starting with the root.
1285 *
1286 * @since 2.0
1287 */
1288 public void collapseAll() {
1289 fTimeGraphCtrl.collapseAll();
1290 adjustVerticalScrollBar();
1291 }
1292
1293 /**
1294 * Expands all nodes of the viewer's tree, starting with the root.
1295 *
1296 * @since 2.0
1297 */
1298 public void expandAll() {
1299 fTimeGraphCtrl.expandAll();
1300 adjustVerticalScrollBar();
1301 }
1302
1303 /**
1304 * Get the number of sub-elements when expanded
1305 *
1306 * @return The element count
1307 */
1308 public int getExpandedElementCount() {
1309 return fTimeGraphCtrl.getExpandedElementCount();
1310 }
1311
1312 /**
1313 * Get the sub-elements
1314 *
1315 * @return The array of entries that are below this one
1316 */
1317 public ITimeGraphEntry[] getExpandedElements() {
1318 return fTimeGraphCtrl.getExpandedElements();
1319 }
1320
1321 /**
1322 * Add a tree listener
1323 *
1324 * @param listener
1325 * The listener to add
1326 */
1327 public void addTreeListener(ITimeGraphTreeListener listener) {
1328 fTimeGraphCtrl.addTreeListener(listener);
1329 }
1330
1331 /**
1332 * Remove a tree listener
1333 *
1334 * @param listener
1335 * The listener to remove
1336 */
1337 public void removeTreeListener(ITimeGraphTreeListener listener) {
1338 fTimeGraphCtrl.removeTreeListener(listener);
1339 }
1340
1341 /**
1342 * Get the reset scale action.
1343 *
1344 * @return The Action object
1345 */
1346 public Action getResetScaleAction() {
1347 if (fResetScaleAction == null) {
1348 // resetScale
1349 fResetScaleAction = new Action() {
1350 @Override
1351 public void run() {
1352 resetStartFinishTime();
1353 notifyStartFinishTime();
1354 }
1355 };
1356 fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
1357 fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
1358 fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
1359 }
1360 return fResetScaleAction;
1361 }
1362
1363 /**
1364 * Get the show legend action.
1365 *
1366 * @return The Action object
1367 */
1368 public Action getShowLegendAction() {
1369 if (fShowLegendAction == null) {
1370 // showLegend
1371 fShowLegendAction = new Action() {
1372 @Override
1373 public void run() {
1374 showLegend();
1375 }
1376 };
1377 fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
1378 fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
1379 fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
1380 }
1381
1382 return fShowLegendAction;
1383 }
1384
1385 /**
1386 * Get the the next event action.
1387 *
1388 * @return The action object
1389 */
1390 public Action getNextEventAction() {
1391 if (fNextEventAction == null) {
1392 fNextEventAction = new Action() {
1393 @Override
1394 public void run() {
1395 selectNextEvent();
1396 }
1397 };
1398
1399 fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
1400 fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
1401 fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
1402 }
1403
1404 return fNextEventAction;
1405 }
1406
1407 /**
1408 * Get the previous event action.
1409 *
1410 * @return The Action object
1411 */
1412 public Action getPreviousEventAction() {
1413 if (fPrevEventAction == null) {
1414 fPrevEventAction = new Action() {
1415 @Override
1416 public void run() {
1417 selectPrevEvent();
1418 }
1419 };
1420
1421 fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
1422 fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
1423 fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
1424 }
1425
1426 return fPrevEventAction;
1427 }
1428
1429 /**
1430 * Get the next item action.
1431 *
1432 * @return The Action object
1433 */
1434 public Action getNextItemAction() {
1435 if (fNextItemAction == null) {
1436
1437 fNextItemAction = new Action() {
1438 @Override
1439 public void run() {
1440 selectNextItem();
1441 }
1442 };
1443 fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
1444 fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
1445 fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
1446 }
1447 return fNextItemAction;
1448 }
1449
1450 /**
1451 * Get the previous item action.
1452 *
1453 * @return The Action object
1454 */
1455 public Action getPreviousItemAction() {
1456 if (fPreviousItemAction == null) {
1457
1458 fPreviousItemAction = new Action() {
1459 @Override
1460 public void run() {
1461 selectPrevItem();
1462 }
1463 };
1464 fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
1465 fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
1466 fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
1467 }
1468 return fPreviousItemAction;
1469 }
1470
1471 /**
1472 * Get the zoom in action
1473 *
1474 * @return The Action object
1475 */
1476 public Action getZoomInAction() {
1477 if (fZoomInAction == null) {
1478 fZoomInAction = new Action() {
1479 @Override
1480 public void run() {
1481 zoomIn();
1482 }
1483 };
1484 fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
1485 fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
1486 fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
1487 }
1488 return fZoomInAction;
1489 }
1490
1491 /**
1492 * Get the zoom out action
1493 *
1494 * @return The Action object
1495 */
1496 public Action getZoomOutAction() {
1497 if (fZoomOutAction == null) {
1498 fZoomOutAction = new Action() {
1499 @Override
1500 public void run() {
1501 zoomOut();
1502 }
1503 };
1504 fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
1505 fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
1506 fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
1507 }
1508 return fZoomOutAction;
1509 }
1510
1511 /**
1512 * Get the hide arrows action
1513 *
1514 * @param dialogSettings
1515 * The dialog settings section where the state should be stored,
1516 * or null
1517 *
1518 * @return The Action object
1519 *
1520 * @since 2.1
1521 */
1522 public Action getHideArrowsAction(final IDialogSettings dialogSettings) {
1523 if (fHideArrowsAction == null) {
1524 fHideArrowsAction = new Action(Messages.TmfTimeGraphViewer_HideArrowsActionNameText, IAction.AS_CHECK_BOX) {
1525 @Override
1526 public void run() {
1527 boolean hideArrows = fHideArrowsAction.isChecked();
1528 fTimeGraphCtrl.hideArrows(hideArrows);
1529 refresh();
1530 if (dialogSettings != null) {
1531 dialogSettings.put(HIDE_ARROWS_KEY, hideArrows);
1532 }
1533 if (fFollowArrowFwdAction != null) {
1534 fFollowArrowFwdAction.setEnabled(!hideArrows);
1535 }
1536 if (fFollowArrowBwdAction != null) {
1537 fFollowArrowBwdAction.setEnabled(!hideArrows);
1538 }
1539 }
1540 };
1541 fHideArrowsAction.setToolTipText(Messages.TmfTimeGraphViewer_HideArrowsActionToolTipText);
1542 fHideArrowsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HIDE_ARROWS));
1543 if (dialogSettings != null) {
1544 boolean hideArrows = dialogSettings.getBoolean(HIDE_ARROWS_KEY);
1545 fTimeGraphCtrl.hideArrows(hideArrows);
1546 fHideArrowsAction.setChecked(hideArrows);
1547 if (fFollowArrowFwdAction != null) {
1548 fFollowArrowFwdAction.setEnabled(!hideArrows);
1549 }
1550 if (fFollowArrowBwdAction != null) {
1551 fFollowArrowBwdAction.setEnabled(!hideArrows);
1552 }
1553 }
1554 }
1555 return fHideArrowsAction;
1556 }
1557
1558 /**
1559 * Get the follow arrow forward action.
1560 *
1561 * @return The Action object
1562 *
1563 * @since 2.1
1564 */
1565 public Action getFollowArrowFwdAction() {
1566 if (fFollowArrowFwdAction == null) {
1567 fFollowArrowFwdAction = new Action() {
1568 @Override
1569 public void run() {
1570 fTimeGraphCtrl.followArrowFwd();
1571 adjustVerticalScrollBar();
1572 }
1573 };
1574 fFollowArrowFwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionNameText);
1575 fFollowArrowFwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText);
1576 fFollowArrowFwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_FORWARD));
1577 if (fHideArrowsAction != null) {
1578 fFollowArrowFwdAction.setEnabled(!fHideArrowsAction.isChecked());
1579 }
1580 }
1581 return fFollowArrowFwdAction;
1582 }
1583
1584 /**
1585 * Get the follow arrow backward action.
1586 *
1587 * @return The Action object
1588 *
1589 * @since 2.1
1590 */
1591 public Action getFollowArrowBwdAction() {
1592 if (fFollowArrowBwdAction == null) {
1593 fFollowArrowBwdAction = new Action() {
1594 @Override
1595 public void run() {
1596 fTimeGraphCtrl.followArrowBwd();
1597 adjustVerticalScrollBar();
1598 }
1599 };
1600 fFollowArrowBwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionNameText);
1601 fFollowArrowBwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText);
1602 fFollowArrowBwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_BACKWARD));
1603 if (fHideArrowsAction != null) {
1604 fFollowArrowBwdAction.setEnabled(!fHideArrowsAction.isChecked());
1605 }
1606 }
1607 return fFollowArrowBwdAction;
1608 }
1609
1610 private void adjustVerticalScrollBar() {
1611 int topIndex = fTimeGraphCtrl.getTopIndex();
1612 int countPerPage = fTimeGraphCtrl.countPerPage();
1613 int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount();
1614 if (topIndex + countPerPage > expandedElementCount) {
1615 fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
1616 }
1617
1618 int selection = fTimeGraphCtrl.getTopIndex();
1619 int min = 0;
1620 int max = Math.max(1, expandedElementCount - 1);
1621 int thumb = Math.min(max, Math.max(1, countPerPage - 1));
1622 int increment = 1;
1623 int pageIncrement = Math.max(1, countPerPage);
1624 fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
1625 }
1626
1627 /**
1628 * @param listener
1629 * a {@link MenuDetectListener}
1630 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1631 * @since 1.2
1632 */
1633 public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
1634 fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener);
1635 }
1636
1637 /**
1638 * @param listener
1639 * a {@link MenuDetectListener}
1640 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
1641 * @since 1.2
1642 */
1643 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
1644 fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener);
1645 }
1646
1647 /**
1648 * @param listener
1649 * a {@link MenuDetectListener}
1650 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1651 * @since 1.2
1652 */
1653 public void addTimeEventMenuListener(MenuDetectListener listener) {
1654 fTimeGraphCtrl.addTimeEventMenuListener(listener);
1655 }
1656
1657 /**
1658 * @param listener
1659 * a {@link MenuDetectListener}
1660 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
1661 * @since 1.2
1662 */
1663 public void removeTimeEventMenuListener(MenuDetectListener listener) {
1664 fTimeGraphCtrl.removeTimeEventMenuListener(listener);
1665 }
1666
1667 /**
1668 * @param filter
1669 * The filter object to be attached to the view
1670 * @since 2.0
1671 */
1672 public void addFilter(ViewerFilter filter) {
1673 fTimeGraphCtrl.addFilter(filter);
1674 refresh();
1675 }
1676
1677 /**
1678 * @param filter
1679 * The filter object to be attached to the view
1680 * @since 2.0
1681 */
1682 public void removeFilter(ViewerFilter filter) {
1683 fTimeGraphCtrl.removeFilter(filter);
1684 refresh();
1685 }
1686
1687 }
This page took 0.088664 seconds and 5 git commands to generate.