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