tmf: Bug 490400: Leaking widgets due to incorrect cleanup in dispose()
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / widgets / timegraph / TimeGraphViewer.java
1 /*****************************************************************************
2 * Copyright (c) 2007, 2016 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.tracecompass.tmf.ui.widgets.timegraph;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Comparator;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.eclipse.jface.action.Action;
28 import org.eclipse.jface.action.ActionContributionItem;
29 import org.eclipse.jface.action.IAction;
30 import org.eclipse.jface.action.IMenuCreator;
31 import org.eclipse.jface.action.IMenuListener;
32 import org.eclipse.jface.action.IMenuManager;
33 import org.eclipse.jface.action.MenuManager;
34 import org.eclipse.jface.dialogs.IDialogSettings;
35 import org.eclipse.jface.resource.ImageDescriptor;
36 import org.eclipse.jface.viewers.AbstractTreeViewer;
37 import org.eclipse.jface.viewers.ISelectionProvider;
38 import org.eclipse.jface.viewers.ITableLabelProvider;
39 import org.eclipse.jface.viewers.ITreeContentProvider;
40 import org.eclipse.jface.viewers.ViewerFilter;
41 import org.eclipse.jface.window.Window;
42 import org.eclipse.swt.SWT;
43 import org.eclipse.swt.events.ControlAdapter;
44 import org.eclipse.swt.events.ControlEvent;
45 import org.eclipse.swt.events.KeyAdapter;
46 import org.eclipse.swt.events.KeyEvent;
47 import org.eclipse.swt.events.MenuDetectListener;
48 import org.eclipse.swt.events.MouseEvent;
49 import org.eclipse.swt.events.MouseWheelListener;
50 import org.eclipse.swt.events.SelectionAdapter;
51 import org.eclipse.swt.events.SelectionEvent;
52 import org.eclipse.swt.events.SelectionListener;
53 import org.eclipse.swt.graphics.Point;
54 import org.eclipse.swt.graphics.RGBA;
55 import org.eclipse.swt.graphics.Rectangle;
56 import org.eclipse.swt.layout.FillLayout;
57 import org.eclipse.swt.layout.GridData;
58 import org.eclipse.swt.layout.GridLayout;
59 import org.eclipse.swt.widgets.Composite;
60 import org.eclipse.swt.widgets.Control;
61 import org.eclipse.swt.widgets.Display;
62 import org.eclipse.swt.widgets.Event;
63 import org.eclipse.swt.widgets.Listener;
64 import org.eclipse.swt.widgets.Menu;
65 import org.eclipse.swt.widgets.Slider;
66 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
67 import org.eclipse.tracecompass.internal.tmf.ui.ITmfImageConstants;
68 import org.eclipse.tracecompass.internal.tmf.ui.Messages;
69 import org.eclipse.tracecompass.internal.tmf.ui.dialogs.AddBookmarkDialog;
70 import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
71 import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned;
72 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.ShowFilterDialogAction;
73 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend;
74 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
75 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
76 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
77 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
78 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent;
79 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.IMarkerAxisListener;
80 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
81 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeDataProviderCyclesConverter;
82 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
83 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
84 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphMarkerAxis;
85 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
86 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler;
87 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
88 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
89 import org.eclipse.ui.PlatformUI;
90
91 /**
92 * Generic time graph viewer implementation
93 *
94 * @author Patrick Tasse, and others
95 */
96 public class TimeGraphViewer implements ITimeDataProvider, IMarkerAxisListener, SelectionListener {
97
98 /** Constant indicating that all levels of the time graph should be expanded */
99 public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
100
101 private static final int DEFAULT_NAME_WIDTH = 200;
102 private static final int MIN_NAME_WIDTH = 6;
103 private static final int MAX_NAME_WIDTH = 1000;
104 private static final int DEFAULT_HEIGHT = 22;
105 private static final String HIDE_ARROWS_KEY = "hide.arrows"; //$NON-NLS-1$
106 private static final long DEFAULT_FREQUENCY = 1000000000L;
107 private static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
108
109 private static final ImageDescriptor ADD_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ADD_BOOKMARK);
110 private static final ImageDescriptor NEXT_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_BOOKMARK);
111 private static final ImageDescriptor PREVIOUS_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREVIOUS_BOOKMARK);
112 private static final ImageDescriptor REMOVE_BOOKMARK = Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_REMOVE_BOOKMARK);
113
114 private long fMinTimeInterval;
115 private ITimeGraphEntry fSelectedEntry;
116 private long fBeginTime = SWT.DEFAULT; // The user-specified bounds start time
117 private long fEndTime = SWT.DEFAULT; // The user-specified bounds end time
118 private long fTime0 = SWT.DEFAULT; // The current window start time
119 private long fTime1 = SWT.DEFAULT; // The current window end time
120 private long fSelectionBegin = SWT.DEFAULT;
121 private long fSelectionEnd = SWT.DEFAULT;
122 private long fTime0Bound = SWT.DEFAULT; // The bounds start time
123 private long fTime1Bound = SWT.DEFAULT; // The bounds end time
124 private long fTime0ExtSynch = SWT.DEFAULT;
125 private long fTime1ExtSynch = SWT.DEFAULT;
126 private boolean fTimeRangeFixed;
127 private int fNameWidthPref = DEFAULT_NAME_WIDTH;
128 private int fMinNameWidth = MIN_NAME_WIDTH;
129 private int fNameWidth;
130 private Composite fDataViewer;
131
132 private TimeGraphControl fTimeGraphCtrl;
133 private TimeGraphScale fTimeScaleCtrl;
134 private TimeGraphMarkerAxis fMarkerAxisCtrl;
135 private Slider fHorizontalScrollBar;
136 private Slider fVerticalScrollBar;
137 private @NonNull TimeGraphColorScheme fColorScheme = new TimeGraphColorScheme();
138 private Object fInputElement;
139 private ITimeGraphContentProvider fTimeGraphContentProvider;
140 private ITimeGraphPresentationProvider fTimeGraphProvider;
141 private @NonNull ITimeDataProvider fTimeDataProvider = this;
142 private TimeGraphTooltipHandler fToolTipHandler;
143
144 private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<>();
145 private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<>();
146 private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<>();
147 private List<ITimeGraphBookmarkListener> fBookmarkListeners = new ArrayList<>();
148
149 // Time format, using Epoch reference, Relative time format(default),
150 // Number, or Cycles
151 private TimeFormat fTimeFormat = TimeFormat.RELATIVE;
152 // Clock frequency to use for Cycles time format
153 private long fClockFrequency = DEFAULT_FREQUENCY;
154 private int fBorderWidth = 0;
155 private int fTimeScaleHeight = DEFAULT_HEIGHT;
156
157 private Action fResetScaleAction;
158 private Action fShowLegendAction;
159 private Action fNextEventAction;
160 private Action fPrevEventAction;
161 private Action fNextItemAction;
162 private Action fPreviousItemAction;
163 private Action fZoomInAction;
164 private Action fZoomOutAction;
165 private Action fHideArrowsAction;
166 private Action fFollowArrowFwdAction;
167 private Action fFollowArrowBwdAction;
168 private ShowFilterDialogAction fShowFilterDialogAction;
169 private Action fToggleBookmarkAction;
170 private Action fNextMarkerAction;
171 private Action fPreviousMarkerAction;
172 private MenuManager fMarkersMenu;
173
174 /** The list of bookmarks */
175 private final List<IMarkerEvent> fBookmarks = new ArrayList<>();
176
177 /** The list of marker categories */
178 private final List<String> fMarkerCategories = new ArrayList<>();
179
180 /** The set of hidden marker categories */
181 private final Set<String> fHiddenMarkerCategories = new HashSet<>();
182
183 /** The set of skipped marker categories */
184 private final Set<String> fSkippedMarkerCategories = new HashSet<>();
185
186 /** The list of markers */
187 private final List<IMarkerEvent> fMarkers = new ArrayList<>();
188
189 private ListenerNotifier fListenerNotifier;
190
191 private Composite fTimeAlignedComposite;
192
193 private class ListenerNotifier extends Thread {
194 private static final long DELAY = 400L;
195 private static final long POLLING_INTERVAL = 10L;
196 private long fLastUpdateTime = Long.MAX_VALUE;
197 private boolean fSelectionChanged = false;
198 private boolean fTimeRangeUpdated = false;
199 private boolean fTimeSelected = false;
200
201 @Override
202 public void run() {
203 while ((System.currentTimeMillis() - fLastUpdateTime) < DELAY) {
204 try {
205 Thread.sleep(POLLING_INTERVAL);
206 } catch (Exception e) {
207 return;
208 }
209 }
210 Display.getDefault().asyncExec(new Runnable() {
211 @Override
212 public void run() {
213 if (fListenerNotifier != ListenerNotifier.this) {
214 return;
215 }
216 fListenerNotifier = null;
217 if (ListenerNotifier.this.isInterrupted() || fDataViewer.isDisposed()) {
218 return;
219 }
220 if (fSelectionChanged) {
221 fireSelectionChanged(fSelectedEntry);
222 }
223 if (fTimeRangeUpdated) {
224 fireTimeRangeUpdated(fTime0, fTime1);
225 }
226 if (fTimeSelected) {
227 fireTimeSelected(fSelectionBegin, fSelectionEnd);
228 }
229 }
230 });
231 }
232
233 public void selectionChanged() {
234 fSelectionChanged = true;
235 fLastUpdateTime = System.currentTimeMillis();
236 }
237
238 public void timeRangeUpdated() {
239 fTimeRangeUpdated = true;
240 fLastUpdateTime = System.currentTimeMillis();
241 }
242
243 public void timeSelected() {
244 fTimeSelected = true;
245 fLastUpdateTime = System.currentTimeMillis();
246 }
247
248 public boolean hasSelectionChanged() {
249 return fSelectionChanged;
250 }
251
252 public boolean hasTimeRangeUpdated() {
253 return fTimeRangeUpdated;
254 }
255
256 public boolean hasTimeSelected() {
257 return fTimeSelected;
258 }
259 }
260
261 private final static class MarkerComparator implements Comparator<IMarkerEvent> {
262 @Override
263 public int compare(IMarkerEvent o1, IMarkerEvent o2) {
264 int res = Long.compare(o1.getTime(), o2.getTime());
265 if (res != 0) {
266 return res;
267 }
268 return Long.compare(o1.getDuration(), o2.getDuration());
269 }
270 }
271
272 /**
273 * Standard constructor.
274 * <p>
275 * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
276 *
277 * @param parent
278 * The parent UI composite object
279 * @param style
280 * The style to use
281 */
282 public TimeGraphViewer(Composite parent, int style) {
283 createDataViewer(parent, style);
284 fTimeGraphContentProvider = new TimeGraphContentProvider();
285 }
286
287 /**
288 * Sets the timegraph content provider used by this timegraph viewer.
289 *
290 * @param timeGraphContentProvider
291 * the timegraph content provider
292 */
293 public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) {
294 fTimeGraphContentProvider = timeGraphContentProvider;
295 }
296
297 /**
298 * Gets the timegraph content provider used by this timegraph viewer.
299 *
300 * @return the timegraph content provider
301 */
302 public ITimeGraphContentProvider getTimeGraphContentProvider() {
303 return fTimeGraphContentProvider;
304 }
305
306 /**
307 * Sets the timegraph presentation provider used by this timegraph viewer.
308 *
309 * @param timeGraphProvider
310 * the timegraph provider
311 */
312 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
313 fTimeGraphProvider = timeGraphProvider;
314 fTimeGraphCtrl.setTimeGraphProvider(timeGraphProvider);
315 fToolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, fTimeDataProvider);
316 fToolTipHandler.activateHoverHelp(fTimeGraphCtrl);
317 }
318
319 /**
320 * Sets the tree columns for this time graph combo's filter dialog.
321 *
322 * @param columnNames the tree column names
323 * @since 2.0
324 */
325 public void setFilterColumns(String[] columnNames) {
326 getShowFilterDialogAction().getFilterDialog().setColumnNames(columnNames);
327 }
328
329 /**
330 * Sets the tree content provider used by the filter dialog
331 *
332 * @param contentProvider the tree content provider
333 * @since 2.0
334 */
335 public void setFilterContentProvider(ITreeContentProvider contentProvider) {
336 getShowFilterDialogAction().getFilterDialog().setContentProvider(contentProvider);
337 }
338
339 /**
340 * Sets the tree label provider used by the filter dialog
341 *
342 * @param labelProvider the tree label provider
343 * @since 2.0
344 */
345 public void setFilterLabelProvider(ITableLabelProvider labelProvider) {
346 getShowFilterDialogAction().getFilterDialog().setLabelProvider(labelProvider);
347 }
348
349 /**
350 * Sets or clears the input for this time graph viewer.
351 *
352 * @param inputElement
353 * The input of this time graph viewer, or <code>null</code> if
354 * none
355 */
356 public void setInput(Object inputElement) {
357 fInputElement = inputElement;
358 ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(inputElement);
359 fListenerNotifier = null;
360 if (fTimeGraphCtrl != null) {
361 setTimeRange(input);
362 setTopIndex(0);
363 fSelectionBegin = SWT.DEFAULT;
364 fSelectionEnd = SWT.DEFAULT;
365 updateMarkerActions();
366 fSelectedEntry = null;
367 refreshAllData(input);
368 }
369 }
370
371 /**
372 * Gets the input for this time graph viewer.
373 *
374 * @return The input of this time graph viewer, or <code>null</code> if none
375 */
376 public Object getInput() {
377 return fInputElement;
378 }
379
380 /**
381 * Sets (or clears if null) the list of links to display on this combo
382 *
383 * @param links
384 * the links to display in this time graph combo
385 */
386 public void setLinks(List<ILinkEvent> links) {
387 if (fTimeGraphCtrl != null) {
388 fTimeGraphCtrl.refreshArrows(links);
389 }
390 }
391
392 /**
393 * Refresh the view
394 */
395 public void refresh() {
396 ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(fInputElement);
397 setTimeRange(input);
398 refreshAllData(input);
399 }
400
401 /**
402 * Callback for when the control is moved
403 *
404 * @param e
405 * The caller event
406 */
407 public void controlMoved(ControlEvent e) {
408 }
409
410 /**
411 * Callback for when the control is resized
412 *
413 * @param e
414 * The caller event
415 */
416 public void controlResized(ControlEvent e) {
417 resizeControls();
418 }
419
420 /**
421 * @return The string representing the view type
422 */
423 protected String getViewTypeStr() {
424 return "viewoption.threads"; //$NON-NLS-1$
425 }
426
427 int getMarginWidth() {
428 return 0;
429 }
430
431 int getMarginHeight() {
432 return 0;
433 }
434
435 void loadOptions() {
436 fMinTimeInterval = 1;
437 fSelectionBegin = SWT.DEFAULT;
438 fSelectionEnd = SWT.DEFAULT;
439 fNameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
440 fNameWidthPref, fMinNameWidth, MAX_NAME_WIDTH);
441 }
442
443 void saveOptions() {
444 Utils.saveIntOption(getPreferenceString("namewidth"), fNameWidth); //$NON-NLS-1$
445 }
446
447 /**
448 * Create a data viewer.
449 *
450 * @param parent
451 * Parent composite
452 * @param style
453 * Style to use
454 * @return The new data viewer
455 */
456 protected Control createDataViewer(Composite parent, int style) {
457 loadOptions();
458 fDataViewer = new Composite(parent, style) {
459 @Override
460 public void redraw() {
461 fTimeScaleCtrl.redraw();
462 fTimeGraphCtrl.redraw();
463 fMarkerAxisCtrl.redraw();
464 super.redraw();
465 }
466 };
467 fDataViewer.addDisposeListener((e) -> {
468 if (fMarkersMenu != null) {
469 fMarkersMenu.dispose();
470 }
471 });
472 GridLayout gl = new GridLayout(2, false);
473 gl.marginHeight = fBorderWidth;
474 gl.marginWidth = 0;
475 gl.verticalSpacing = 0;
476 gl.horizontalSpacing = 0;
477 fDataViewer.setLayout(gl);
478
479 fTimeAlignedComposite = new Composite(fDataViewer, style) {
480 @Override
481 public void redraw() {
482 fDataViewer.redraw();
483 super.redraw();
484 }
485 };
486 GridLayout gl2 = new GridLayout(1, false);
487 gl2.marginHeight = fBorderWidth;
488 gl2.marginWidth = 0;
489 gl2.verticalSpacing = 0;
490 gl2.horizontalSpacing = 0;
491 fTimeAlignedComposite.setLayout(gl2);
492 fTimeAlignedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
493
494 fTimeScaleCtrl = new TimeGraphScale(fTimeAlignedComposite, fColorScheme);
495 fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
496 fTimeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
497 fTimeScaleCtrl.setHeight(fTimeScaleHeight);
498 fTimeScaleCtrl.addMouseWheelListener(new MouseWheelListener() {
499 @Override
500 public void mouseScrolled(MouseEvent e) {
501 if (e.count == 0) {
502 return;
503 }
504 if ((e.stateMask & SWT.CTRL) != 0) {
505 fTimeGraphCtrl.zoom(e.count > 0);
506 } else {
507 fTimeGraphCtrl.horizontalScroll(e.count > 0);
508 }
509 }
510 });
511
512 fTimeGraphCtrl = createTimeGraphControl(fTimeAlignedComposite, fColorScheme);
513
514 fTimeGraphCtrl.setTimeProvider(this);
515 fTimeGraphCtrl.setTimeGraphScale(fTimeScaleCtrl);
516 fTimeGraphCtrl.addSelectionListener(this);
517 fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
518 fTimeGraphCtrl.addMouseWheelListener(new MouseWheelListener() {
519 @Override
520 public void mouseScrolled(MouseEvent e) {
521 if (e.count == 0) {
522 return;
523 }
524 /*
525 * On some platforms the mouse scroll event is sent to the
526 * control that has focus even if it is not under the cursor.
527 * Handle the event only if not over the time graph control.
528 */
529 Point ctrlParentCoords = fTimeAlignedComposite.toControl(fTimeGraphCtrl.toDisplay(e.x, e.y));
530 Point scrollBarParentCoords = fDataViewer.toControl(fTimeGraphCtrl.toDisplay(e.x, e.y));
531 if (fTimeGraphCtrl.getBounds().contains(ctrlParentCoords)) {
532 /* the time graph control handles the event */
533 adjustVerticalScrollBar();
534 } else if (fTimeScaleCtrl.getBounds().contains(ctrlParentCoords)
535 || fMarkerAxisCtrl.getBounds().contains(ctrlParentCoords)
536 || fHorizontalScrollBar.getBounds().contains(scrollBarParentCoords)) {
537 if ((e.stateMask & SWT.CTRL) != 0) {
538 fTimeGraphCtrl.zoom(e.count > 0);
539 } else {
540 fTimeGraphCtrl.horizontalScroll(e.count > 0);
541 }
542 } else {
543 /* over the vertical scroll bar or outside of the viewer */
544 setTopIndex(getTopIndex() - e.count);
545 }
546 }
547 });
548 fTimeGraphCtrl.addKeyListener(new KeyAdapter() {
549 @Override
550 public void keyPressed(KeyEvent e) {
551 if ((e.character == '+' || e.character == '=') && ((e.stateMask & SWT.CTRL) == 0)) {
552 zoomIn();
553 } else if (e.character == '-' && ((e.stateMask & SWT.CTRL) == 0)) {
554 zoomOut();
555 } else if (e.keyCode == '.') {
556 boolean extend = (e.stateMask & SWT.SHIFT) != 0;
557 if (extend) {
558 extendToNextMarker();
559 } else {
560 selectNextMarker();
561 }
562 } else if (e.keyCode == ',') {
563 boolean extend = (e.stateMask & SWT.SHIFT) != 0;
564 if (extend) {
565 extendToPrevMarker();
566 } else {
567 selectPrevMarker();
568 }
569 }
570 adjustVerticalScrollBar();
571 }
572 });
573
574 fMarkerAxisCtrl = createTimeGraphMarkerAxis(fTimeAlignedComposite, fColorScheme, this);
575 fMarkerAxisCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
576 fMarkerAxisCtrl.addMarkerAxisListener(this);
577 fMarkerAxisCtrl.addMouseWheelListener(new MouseWheelListener() {
578 @Override
579 public void mouseScrolled(MouseEvent e) {
580 if (e.count == 0) {
581 return;
582 }
583 if ((e.stateMask & SWT.CTRL) != 0) {
584 fTimeGraphCtrl.zoom(e.count > 0);
585 } else {
586 fTimeGraphCtrl.horizontalScroll(e.count > 0);
587 }
588 }
589 });
590
591 fVerticalScrollBar = new Slider(fDataViewer, SWT.VERTICAL | SWT.NO_FOCUS);
592 fVerticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 1));
593 fVerticalScrollBar.addSelectionListener(new SelectionAdapter() {
594 @Override
595 public void widgetSelected(SelectionEvent e) {
596 setTopIndex(fVerticalScrollBar.getSelection());
597 }
598 });
599
600 fHorizontalScrollBar = new Slider(fDataViewer, SWT.HORIZONTAL | SWT.NO_FOCUS);
601 fHorizontalScrollBar.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
602 fHorizontalScrollBar.addListener(SWT.MouseWheel, new Listener() {
603 @Override
604 public void handleEvent(Event event) {
605 // don't handle the immediately following SWT.Selection event
606 event.doit = false;
607 if (event.count == 0) {
608 return;
609 }
610 if ((event.stateMask & SWT.CTRL) != 0) {
611 fTimeGraphCtrl.zoom(event.count > 0);
612 } else {
613 fTimeGraphCtrl.horizontalScroll(event.count > 0);
614 }
615 }
616 });
617 fHorizontalScrollBar.addListener(SWT.Selection, new Listener() {
618 @Override
619 public void handleEvent(Event event) {
620 int start = fHorizontalScrollBar.getSelection();
621 long time0 = getTime0();
622 long time1 = getTime1();
623 long timeMin = getMinTime();
624 long timeMax = getMaxTime();
625 long delta = timeMax - timeMin;
626
627 long range = time1 - time0;
628 time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX));
629 time1 = time0 + range;
630
631 setStartFinishTimeNotify(time0, time1);
632 }
633 });
634
635 Composite filler = new Composite(fDataViewer, SWT.NONE);
636 GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
637 gd.heightHint = fHorizontalScrollBar.getSize().y;
638 filler.setLayoutData(gd);
639 filler.setLayout(new FillLayout());
640
641 fTimeGraphCtrl.addControlListener(new ControlAdapter() {
642 @Override
643 public void controlResized(ControlEvent event) {
644 resizeControls();
645 }
646 });
647 resizeControls();
648 fDataViewer.update();
649 adjustHorizontalScrollBar();
650 adjustVerticalScrollBar();
651
652 fDataViewer.addDisposeListener((e) -> {
653 saveOptions();
654 fColorScheme.dispose();
655 });
656
657 return fDataViewer;
658 }
659
660 /**
661 * Dispose the time graph viewer.
662 */
663 public void dispose() {
664 fDataViewer.dispose();
665 }
666
667 /**
668 * Create a new time graph control.
669 *
670 * @param parent
671 * The parent composite
672 * @param colors
673 * The color scheme
674 * @return The new TimeGraphControl
675 */
676 protected TimeGraphControl createTimeGraphControl(Composite parent,
677 TimeGraphColorScheme colors) {
678 return new TimeGraphControl(parent, colors);
679 }
680
681 /**
682 * Create a new time graph marker axis.
683 *
684 * @param parent
685 * The parent composite object
686 * @param colorScheme
687 * The color scheme to use
688 * @param timeProvider
689 * The time data provider
690 * @return The new TimeGraphMarkerAxis
691 * @since 2.0
692 */
693 protected TimeGraphMarkerAxis createTimeGraphMarkerAxis(Composite parent,
694 @NonNull TimeGraphColorScheme colorScheme, @NonNull ITimeDataProvider timeProvider) {
695 return new TimeGraphMarkerAxis(parent, colorScheme, timeProvider);
696 }
697
698 /**
699 * Resize the controls
700 */
701 public void resizeControls() {
702 Rectangle r = fDataViewer.getClientArea();
703 if (r.isEmpty()) {
704 return;
705 }
706
707 int width = r.width;
708 if (fNameWidth > width - fMinNameWidth) {
709 fNameWidth = width - fMinNameWidth;
710 }
711 if (fNameWidth < fMinNameWidth) {
712 fNameWidth = fMinNameWidth;
713 }
714 adjustHorizontalScrollBar();
715 adjustVerticalScrollBar();
716 }
717
718 /**
719 * Recalculate the time bounds based on the time graph entries,
720 * if the user-specified bound is set to SWT.DEFAULT.
721 *
722 * @param entries
723 * The root time graph entries in the model
724 */
725 public void setTimeRange(ITimeGraphEntry entries[]) {
726 fTime0Bound = (fBeginTime != SWT.DEFAULT ? fBeginTime : fEndTime);
727 fTime1Bound = (fEndTime != SWT.DEFAULT ? fEndTime : fBeginTime);
728 if (fBeginTime != SWT.DEFAULT && fEndTime != SWT.DEFAULT) {
729 return;
730 }
731 if (entries == null || entries.length == 0) {
732 return;
733 }
734 if (fTime0Bound == SWT.DEFAULT) {
735 fTime0Bound = Long.MAX_VALUE;
736 }
737 if (fTime1Bound == SWT.DEFAULT) {
738 fTime1Bound = Long.MIN_VALUE;
739 }
740 for (ITimeGraphEntry entry : entries) {
741 setTimeRange(entry);
742 }
743 }
744
745 private void setTimeRange(ITimeGraphEntry entry) {
746 if (fBeginTime == SWT.DEFAULT && entry.hasTimeEvents() && entry.getStartTime() != SWT.DEFAULT) {
747 fTime0Bound = Math.min(entry.getStartTime(), fTime0Bound);
748 }
749 if (fEndTime == SWT.DEFAULT && entry.hasTimeEvents() && entry.getEndTime() != SWT.DEFAULT) {
750 fTime1Bound = Math.max(entry.getEndTime(), fTime1Bound);
751 }
752 if (entry.hasChildren()) {
753 for (ITimeGraphEntry child : entry.getChildren()) {
754 setTimeRange(child);
755 }
756 }
757 }
758
759 /**
760 * Set the time bounds to the provided values.
761 *
762 * @param beginTime
763 * The bounds begin time, or SWT.DEFAULT to use the input bounds
764 * @param endTime
765 * The bounds end time, or SWT.DEFAULT to use the input bounds
766 */
767 public void setTimeBounds(long beginTime, long endTime) {
768 fBeginTime = beginTime;
769 fEndTime = endTime;
770 fTime0Bound = (fBeginTime != SWT.DEFAULT ? fBeginTime : fEndTime);
771 fTime1Bound = (fEndTime != SWT.DEFAULT ? fEndTime : fBeginTime);
772 if (fTime0Bound > fTime1Bound) {
773 // only possible if both are not default
774 fBeginTime = endTime;
775 fEndTime = beginTime;
776 fTime0Bound = fBeginTime;
777 fTime1Bound = fEndTime;
778 }
779 adjustHorizontalScrollBar();
780 }
781
782 /**
783 * Recalculate the current time window when bounds have changed.
784 */
785 public void setTimeBounds() {
786 if (!fTimeRangeFixed) {
787 fTime0 = fTime0Bound;
788 fTime1 = fTime1Bound;
789 }
790 fTime0 = Math.max(fTime0Bound, Math.min(fTime0, fTime1Bound));
791 fTime1 = Math.max(fTime0Bound, Math.min(fTime1, fTime1Bound));
792 if (fTime1 - fTime0 < fMinTimeInterval) {
793 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
794 }
795 }
796
797 /**
798 * @param traces
799 */
800 private void refreshAllData(ITimeGraphEntry[] traces) {
801 setTimeBounds();
802 if (fSelectionBegin < fBeginTime) {
803 fSelectionBegin = fBeginTime;
804 } else if (fSelectionBegin > fEndTime) {
805 fSelectionBegin = fEndTime;
806 }
807 if (fSelectionEnd < fBeginTime) {
808 fSelectionEnd = fBeginTime;
809 } else if (fSelectionEnd > fEndTime) {
810 fSelectionEnd = fEndTime;
811 }
812 fTimeGraphCtrl.refreshData(traces);
813 fTimeScaleCtrl.redraw();
814 fMarkerAxisCtrl.redraw();
815 updateMarkerActions();
816 adjustVerticalScrollBar();
817 }
818
819 /**
820 * Callback for when this view is focused
821 */
822 public void setFocus() {
823 if (null != fTimeGraphCtrl) {
824 fTimeGraphCtrl.setFocus();
825 }
826 }
827
828 /**
829 * Get the current focus status of this view.
830 *
831 * @return If the view is currently focused, or not
832 */
833 public boolean isInFocus() {
834 return fTimeGraphCtrl.isInFocus();
835 }
836
837 /**
838 * Get the view's current selection
839 *
840 * @return The entry that is selected
841 */
842 public ITimeGraphEntry getSelection() {
843 return fTimeGraphCtrl.getSelectedTrace();
844 }
845
846 /**
847 * Get the index of the current selection
848 *
849 * @return The index
850 */
851 public int getSelectionIndex() {
852 return fTimeGraphCtrl.getSelectedIndex();
853 }
854
855 @Override
856 public long getTime0() {
857 return fTime0;
858 }
859
860 @Override
861 public long getTime1() {
862 return fTime1;
863 }
864
865 @Override
866 public long getMinTimeInterval() {
867 return fMinTimeInterval;
868 }
869
870 @Override
871 public int getNameSpace() {
872 return fNameWidth;
873 }
874
875 @Override
876 public void setNameSpace(int width) {
877 fNameWidth = width;
878 int w = fTimeGraphCtrl.getClientArea().width;
879 if (fNameWidth > w - MIN_NAME_WIDTH) {
880 fNameWidth = w - MIN_NAME_WIDTH;
881 }
882 if (fNameWidth < MIN_NAME_WIDTH) {
883 fNameWidth = MIN_NAME_WIDTH;
884 }
885 fTimeGraphCtrl.redraw();
886 fTimeScaleCtrl.redraw();
887 fMarkerAxisCtrl.redraw();
888 /* force update the controls to keep them aligned */
889 fTimeScaleCtrl.update();
890 fMarkerAxisCtrl.update();
891 fTimeGraphCtrl.update();
892 }
893
894 @Override
895 public int getTimeSpace() {
896 int w = fTimeGraphCtrl.getClientArea().width;
897 return w - fNameWidth;
898 }
899
900 @Override
901 public long getBeginTime() {
902 return fBeginTime;
903 }
904
905 @Override
906 public long getEndTime() {
907 return fEndTime;
908 }
909
910 @Override
911 public long getMaxTime() {
912 return fTime1Bound;
913 }
914
915 @Override
916 public long getMinTime() {
917 return fTime0Bound;
918 }
919
920 @Override
921 public long getSelectionBegin() {
922 return fSelectionBegin;
923 }
924
925 @Override
926 public long getSelectionEnd() {
927 return fSelectionEnd;
928 }
929
930 @Override
931 public void setStartFinishTimeNotify(long time0, long time1) {
932 setStartFinishTimeInt(time0, time1);
933 notifyRangeListeners();
934 }
935
936 @Override
937 public void notifyStartFinishTime() {
938 notifyRangeListeners();
939 }
940
941 @Override
942 public void setStartFinishTime(long time0, long time1) {
943 /* if there is a pending time range, ignore this one */
944 if (fListenerNotifier != null && fListenerNotifier.hasTimeRangeUpdated()) {
945 return;
946 }
947 setStartFinishTimeInt(time0, time1);
948 updateExtSynchValues();
949 }
950
951 private void setStartFinishTimeInt(long time0, long time1) {
952 fTime0 = time0;
953 if (fTime0 < fTime0Bound) {
954 fTime0 = fTime0Bound;
955 }
956 if (fTime0 > fTime1Bound) {
957 fTime0 = fTime1Bound;
958 }
959 fTime1 = time1;
960 if (fTime1 < fTime0Bound) {
961 fTime1 = fTime0Bound;
962 }
963 if (fTime1 > fTime1Bound) {
964 fTime1 = fTime1Bound;
965 }
966 if (fTime1 - fTime0 < fMinTimeInterval) {
967 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
968 }
969 fTimeRangeFixed = true;
970 adjustHorizontalScrollBar();
971 fTimeGraphCtrl.redraw();
972 fTimeScaleCtrl.redraw();
973 fMarkerAxisCtrl.redraw();
974 /* force update the controls to keep them aligned */
975 fTimeScaleCtrl.update();
976 fMarkerAxisCtrl.update();
977 fTimeGraphCtrl.update();
978 }
979
980 @Override
981 public void resetStartFinishTime() {
982 setStartFinishTimeNotify(fTime0Bound, fTime1Bound);
983 fTimeRangeFixed = false;
984 }
985
986 @Override
987 public void setSelectedTimeNotify(long time, boolean ensureVisible) {
988 setSelectedTimeInt(time, ensureVisible, true);
989 }
990
991 @Override
992 public void setSelectedTime(long time, boolean ensureVisible) {
993 /* if there is a pending time selection, ignore this one */
994 if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) {
995 return;
996 }
997 setSelectedTimeInt(time, ensureVisible, false);
998 }
999
1000 private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
1001 setSelectionRangeInt(time, time, ensureVisible, doNotify);
1002 }
1003
1004 /**
1005 * @since 2.0
1006 */
1007 @Override
1008 public void setSelectionRangeNotify(long beginTime, long endTime, boolean ensureVisible) {
1009 setSelectionRangeInt(beginTime, endTime, ensureVisible, true);
1010 }
1011
1012 /**
1013 * @since 2.0
1014 */
1015 @Override
1016 public void setSelectionRange(long beginTime, long endTime, boolean ensureVisible) {
1017 /* if there is a pending time selection, ignore this one */
1018 if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) {
1019 return;
1020 }
1021 setSelectionRangeInt(beginTime, endTime, ensureVisible, false);
1022 }
1023
1024 private void setSelectionRangeInt(long beginTime, long endTime, boolean ensureVisible, boolean doNotify) {
1025 long time0 = fTime0;
1026 long time1 = fTime1;
1027 long selectionBegin = fSelectionBegin;
1028 long selectionEnd = fSelectionEnd;
1029 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
1030 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
1031 boolean changed = (selectionBegin != fSelectionBegin || selectionEnd != fSelectionEnd);
1032
1033 if (ensureVisible) {
1034 ensureVisible(selectionBegin != fSelectionBegin ? fSelectionBegin : fSelectionEnd);
1035 }
1036
1037 fTimeGraphCtrl.redraw();
1038 fTimeScaleCtrl.redraw();
1039 fMarkerAxisCtrl.redraw();
1040 updateMarkerActions();
1041
1042 if ((time0 != fTime0) || (time1 != fTime1)) {
1043 notifyRangeListeners();
1044 }
1045
1046 if (doNotify && changed) {
1047 notifyTimeListeners();
1048 }
1049 }
1050
1051 private void ensureVisible(long time) {
1052 long timeMid = (fTime1 - fTime0) / 2;
1053 if (time < fTime0) {
1054 long dt = fTime0 - time + timeMid;
1055 fTime0 -= dt;
1056 fTime1 -= dt;
1057 } else if (time > fTime1) {
1058 long dt = time - fTime1 + timeMid;
1059 fTime0 += dt;
1060 fTime1 += dt;
1061 }
1062 if (fTime0 < fTime0Bound) {
1063 fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0));
1064 fTime0 = fTime0Bound;
1065 } else if (fTime1 > fTime1Bound) {
1066 fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound));
1067 fTime1 = fTime1Bound;
1068 }
1069 if (fTime1 - fTime0 < fMinTimeInterval) {
1070 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
1071 }
1072 adjustHorizontalScrollBar();
1073 }
1074
1075 @Override
1076 public void widgetDefaultSelected(SelectionEvent e) {
1077 if (fSelectedEntry != getSelection()) {
1078 fSelectedEntry = getSelection();
1079 notifySelectionListeners();
1080 }
1081 }
1082
1083 @Override
1084 public void widgetSelected(SelectionEvent e) {
1085 if (fSelectedEntry != getSelection()) {
1086 fSelectedEntry = getSelection();
1087 notifySelectionListeners();
1088 }
1089 }
1090
1091 /**
1092 * Callback for when the next event is selected
1093 *
1094 * @param extend
1095 * true to extend selection range, false for single selection
1096 * @since 1.0
1097 */
1098 public void selectNextEvent(boolean extend) {
1099 fTimeGraphCtrl.selectNextEvent(extend);
1100 adjustVerticalScrollBar();
1101 }
1102
1103 /**
1104 * Callback for when the previous event is selected
1105 *
1106 * @param extend
1107 * true to extend selection range, false for single selection
1108 * @since 1.0
1109 */
1110 public void selectPrevEvent(boolean extend) {
1111 fTimeGraphCtrl.selectPrevEvent(extend);
1112 adjustVerticalScrollBar();
1113 }
1114
1115 /**
1116 * Callback for when the next item is selected
1117 */
1118 public void selectNextItem() {
1119 fTimeGraphCtrl.selectNextTrace();
1120 adjustVerticalScrollBar();
1121 }
1122
1123 /**
1124 * Callback for when the previous item is selected
1125 */
1126 public void selectPrevItem() {
1127 fTimeGraphCtrl.selectPrevTrace();
1128 adjustVerticalScrollBar();
1129 }
1130
1131 /**
1132 * Callback for the show legend action
1133 */
1134 public void showLegend() {
1135 if (fDataViewer == null || fDataViewer.isDisposed()) {
1136 return;
1137 }
1138
1139 TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider);
1140 }
1141
1142 /**
1143 * Callback for the Zoom In action
1144 */
1145 public void zoomIn() {
1146 fTimeGraphCtrl.zoomIn();
1147 }
1148
1149 /**
1150 * Callback for the Zoom Out action
1151 */
1152 public void zoomOut() {
1153 fTimeGraphCtrl.zoomOut();
1154 }
1155
1156 private String getPreferenceString(String string) {
1157 return getViewTypeStr() + "." + string; //$NON-NLS-1$
1158 }
1159
1160 /**
1161 * Add a selection listener
1162 *
1163 * @param listener
1164 * The listener to add
1165 */
1166 public void addSelectionListener(ITimeGraphSelectionListener listener) {
1167 fSelectionListeners.add(listener);
1168 }
1169
1170 /**
1171 * Remove a selection listener
1172 *
1173 * @param listener
1174 * The listener to remove
1175 */
1176 public void removeSelectionListener(ITimeGraphSelectionListener listener) {
1177 fSelectionListeners.remove(listener);
1178 }
1179
1180 private void notifySelectionListeners() {
1181 if (fListenerNotifier == null) {
1182 fListenerNotifier = new ListenerNotifier();
1183 fListenerNotifier.start();
1184 }
1185 fListenerNotifier.selectionChanged();
1186 }
1187
1188 private void fireSelectionChanged(ITimeGraphEntry selection) {
1189 TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);
1190
1191 for (ITimeGraphSelectionListener listener : fSelectionListeners) {
1192 listener.selectionChanged(event);
1193 }
1194 }
1195
1196 /**
1197 * Add a time listener
1198 *
1199 * @param listener
1200 * The listener to add
1201 */
1202 public void addTimeListener(ITimeGraphTimeListener listener) {
1203 fTimeListeners.add(listener);
1204 }
1205
1206 /**
1207 * Remove a time listener
1208 *
1209 * @param listener
1210 * The listener to remove
1211 */
1212 public void removeTimeListener(ITimeGraphTimeListener listener) {
1213 fTimeListeners.remove(listener);
1214 }
1215
1216 private void notifyTimeListeners() {
1217 if (fListenerNotifier == null) {
1218 fListenerNotifier = new ListenerNotifier();
1219 fListenerNotifier.start();
1220 }
1221 fListenerNotifier.timeSelected();
1222 }
1223
1224 private void fireTimeSelected(long startTime, long endTime) {
1225 TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime);
1226
1227 for (ITimeGraphTimeListener listener : fTimeListeners) {
1228 listener.timeSelected(event);
1229 }
1230 }
1231
1232 /**
1233 * Add a range listener
1234 *
1235 * @param listener
1236 * The listener to add
1237 */
1238 public void addRangeListener(ITimeGraphRangeListener listener) {
1239 fRangeListeners.add(listener);
1240 }
1241
1242 /**
1243 * Remove a range listener
1244 *
1245 * @param listener
1246 * The listener to remove
1247 */
1248 public void removeRangeListener(ITimeGraphRangeListener listener) {
1249 fRangeListeners.remove(listener);
1250 }
1251
1252 private void notifyRangeListeners() {
1253 if (fListenerNotifier == null) {
1254 fListenerNotifier = new ListenerNotifier();
1255 fListenerNotifier.start();
1256 }
1257 fListenerNotifier.timeRangeUpdated();
1258 }
1259
1260 private void fireTimeRangeUpdated(long startTime, long endTime) {
1261 // Check if the time has actually changed from last notification
1262 if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) {
1263 // Notify Time Scale Selection Listeners
1264 TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);
1265
1266 for (ITimeGraphRangeListener listener : fRangeListeners) {
1267 listener.timeRangeUpdated(event);
1268 }
1269
1270 // update external synch values
1271 updateExtSynchValues();
1272 }
1273 }
1274
1275 /**
1276 * Add a bookmark listener
1277 *
1278 * @param listener
1279 * The listener to add
1280 * @since 2.0
1281 */
1282 public void addBookmarkListener(ITimeGraphBookmarkListener listener) {
1283 fBookmarkListeners.add(listener);
1284 }
1285
1286 /**
1287 * Remove a bookmark listener
1288 *
1289 * @param listener
1290 * The listener to remove
1291 * @since 2.0
1292 */
1293 public void removeBookmarkListener(ITimeGraphBookmarkListener listener) {
1294 fBookmarkListeners.remove(listener);
1295 }
1296
1297 private void fireBookmarkAdded(IMarkerEvent bookmark) {
1298 TimeGraphBookmarkEvent event = new TimeGraphBookmarkEvent(this, bookmark);
1299
1300 for (ITimeGraphBookmarkListener listener : fBookmarkListeners) {
1301 listener.bookmarkAdded(event);
1302 }
1303 }
1304
1305 private void fireBookmarkRemoved(IMarkerEvent bookmark) {
1306 TimeGraphBookmarkEvent event = new TimeGraphBookmarkEvent(this, bookmark);
1307
1308 for (ITimeGraphBookmarkListener listener : fBookmarkListeners) {
1309 listener.bookmarkRemoved(event);
1310 }
1311 }
1312
1313 /**
1314 * Set the bookmarks list.
1315 *
1316 * @param bookmarks
1317 * The bookmarks list, or null
1318 * @since 2.0
1319 */
1320 public void setBookmarks(List<IMarkerEvent> bookmarks) {
1321 fBookmarks.clear();
1322 if (bookmarks != null) {
1323 fBookmarks.addAll(bookmarks);
1324 }
1325 updateMarkerList();
1326 updateMarkerActions();
1327 }
1328
1329 /**
1330 * Get the bookmarks list.
1331 *
1332 * @return The bookmarks list
1333 * @since 2.0
1334 */
1335 public List<IMarkerEvent> getBookmarks() {
1336 return Collections.unmodifiableList(fBookmarks);
1337 }
1338
1339 /**
1340 * Set the list of marker categories.
1341 *
1342 * @param categories
1343 * The list of marker categories, or null
1344 * @since 2.0
1345 */
1346 public void setMarkerCategories(List<String> categories) {
1347 fMarkerCategories.clear();
1348 if (categories != null) {
1349 fMarkerCategories.addAll(categories);
1350 }
1351 fMarkerCategories.add(IMarkerEvent.BOOKMARKS);
1352 fMarkerAxisCtrl.setMarkerCategories(fMarkerCategories);
1353 }
1354
1355 /**
1356 * @since 2.0
1357 */
1358 @Override
1359 public void setMarkerCategoryVisible(String category, boolean visible) {
1360 boolean changed = false;
1361 if (visible) {
1362 changed = fHiddenMarkerCategories.remove(category);
1363 } else {
1364 changed = fHiddenMarkerCategories.add(category);
1365 }
1366 if (changed) {
1367 updateMarkerList();
1368 updateMarkerActions();
1369 getControl().redraw();
1370 }
1371 }
1372
1373 /**
1374 * Set the markers list.
1375 *
1376 * @param markers
1377 * The markers list, or null
1378 * @since 2.0
1379 */
1380 public void setMarkers(List<IMarkerEvent> markers) {
1381 fMarkers.clear();
1382 if (markers != null) {
1383 fMarkers.addAll(markers);
1384 }
1385 updateMarkerList();
1386 updateMarkerActions();
1387 }
1388
1389 /**
1390 * Get the markers list.
1391 *
1392 * @return The markers list, or null
1393 * @since 2.0
1394 */
1395 public List<IMarkerEvent> getMarkers() {
1396 return Collections.unmodifiableList(fMarkers);
1397 }
1398
1399 /**
1400 * Callback to set a selected event in the view
1401 *
1402 * @param event
1403 * The event that was selected
1404 * @param source
1405 * The source of this selection event
1406 */
1407 public void setSelectedEvent(ITimeEvent event, Object source) {
1408 if (event == null || source == this) {
1409 return;
1410 }
1411 fSelectedEntry = event.getEntry();
1412 fTimeGraphCtrl.selectItem(fSelectedEntry, false);
1413
1414 setSelectedTimeInt(event.getTime(), true, true);
1415 adjustVerticalScrollBar();
1416 }
1417
1418 /**
1419 * Set the seeked time of a trace
1420 *
1421 * @param trace
1422 * The trace that was seeked
1423 * @param time
1424 * The target time
1425 * @param source
1426 * The source of this seek event
1427 */
1428 public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {
1429 if (trace == null || source == this) {
1430 return;
1431 }
1432 fSelectedEntry = trace;
1433 fTimeGraphCtrl.selectItem(trace, false);
1434
1435 setSelectedTimeInt(time, true, true);
1436 }
1437
1438 /**
1439 * Callback for a trace selection
1440 *
1441 * @param trace
1442 * The trace that was selected
1443 */
1444 public void setSelection(ITimeGraphEntry trace) {
1445 /* if there is a pending selection, ignore this one */
1446 if (fListenerNotifier != null && fListenerNotifier.hasSelectionChanged()) {
1447 return;
1448 }
1449 fSelectedEntry = trace;
1450 fTimeGraphCtrl.selectItem(trace, false);
1451 adjustVerticalScrollBar();
1452 }
1453
1454 /**
1455 * Callback for a time window selection
1456 *
1457 * @param time0
1458 * Start time of the range
1459 * @param time1
1460 * End time of the range
1461 * @param source
1462 * Source of the event
1463 */
1464 public void setSelectVisTimeWindow(long time0, long time1, Object source) {
1465 if (source == this) {
1466 return;
1467 }
1468
1469 setStartFinishTimeInt(time0, time1);
1470
1471 // update notification time values since we are now in synch with the
1472 // external application
1473 updateExtSynchValues();
1474 }
1475
1476 /**
1477 * update the cache values used to identify the need to send a time window
1478 * update to external registered listeners
1479 */
1480 private void updateExtSynchValues() {
1481 // last time notification cache
1482 fTime0ExtSynch = fTime0;
1483 fTime1ExtSynch = fTime1;
1484 }
1485
1486 @Override
1487 public TimeFormat getTimeFormat() {
1488 return fTimeFormat;
1489 }
1490
1491 /**
1492 * @param tf
1493 * the {@link TimeFormat} used to display timestamps
1494 */
1495 public void setTimeFormat(TimeFormat tf) {
1496 this.fTimeFormat = tf;
1497 if (tf == TimeFormat.CYCLES) {
1498 fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency);
1499 } else {
1500 fTimeDataProvider = this;
1501 }
1502 fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
1503 if (fToolTipHandler != null) {
1504 fToolTipHandler.setTimeProvider(fTimeDataProvider);
1505 }
1506 }
1507
1508 /**
1509 * Sets the clock frequency. Used when the time format is set to CYCLES.
1510 *
1511 * @param clockFrequency
1512 * the clock frequency in Hz
1513 */
1514 public void setClockFrequency(long clockFrequency) {
1515 fClockFrequency = clockFrequency;
1516 if (fTimeFormat == TimeFormat.CYCLES) {
1517 fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency);
1518 fTimeScaleCtrl.setTimeProvider(fTimeDataProvider);
1519 if (fToolTipHandler != null) {
1520 fToolTipHandler.setTimeProvider(fTimeDataProvider);
1521 }
1522 }
1523 }
1524
1525 /**
1526 * Retrieve the border width
1527 *
1528 * @return The width
1529 */
1530 public int getBorderWidth() {
1531 return fBorderWidth;
1532 }
1533
1534 /**
1535 * Set the border width
1536 *
1537 * @param borderWidth
1538 * The width
1539 */
1540 public void setBorderWidth(int borderWidth) {
1541 if (borderWidth > -1) {
1542 this.fBorderWidth = borderWidth;
1543 GridLayout gl = (GridLayout) fDataViewer.getLayout();
1544 gl.marginHeight = borderWidth;
1545 }
1546 }
1547
1548 /**
1549 * Retrieve the height of the header
1550 *
1551 * @return The height
1552 */
1553 public int getHeaderHeight() {
1554 return fTimeScaleHeight;
1555 }
1556
1557 /**
1558 * Set the height of the header
1559 *
1560 * @param headerHeight
1561 * The height to set
1562 */
1563 public void setHeaderHeight(int headerHeight) {
1564 if (headerHeight > -1) {
1565 this.fTimeScaleHeight = headerHeight;
1566 fTimeScaleCtrl.setHeight(headerHeight);
1567 }
1568 }
1569
1570 /**
1571 * Retrieve the height of an item row
1572 *
1573 * @return The height
1574 */
1575 public int getItemHeight() {
1576 if (fTimeGraphCtrl != null) {
1577 return fTimeGraphCtrl.getItemHeight();
1578 }
1579 return 0;
1580 }
1581
1582 /**
1583 * Set the height of an item row
1584 *
1585 * @param rowHeight
1586 * The height to set
1587 */
1588 public void setItemHeight(int rowHeight) {
1589 if (fTimeGraphCtrl != null) {
1590 fTimeGraphCtrl.setItemHeight(rowHeight);
1591 }
1592 }
1593
1594 /**
1595 * Set the minimum item width
1596 *
1597 * @param width
1598 * The min width
1599 */
1600 public void setMinimumItemWidth(int width) {
1601 if (fTimeGraphCtrl != null) {
1602 fTimeGraphCtrl.setMinimumItemWidth(width);
1603 }
1604 }
1605
1606 /**
1607 * Set the width for the name column
1608 *
1609 * @param width
1610 * The width
1611 */
1612 public void setNameWidthPref(int width) {
1613 fNameWidthPref = width;
1614 if (width == 0) {
1615 fMinNameWidth = 0;
1616 fNameWidth = 0;
1617 }
1618 }
1619
1620 /**
1621 * Retrieve the configure width for the name column
1622 *
1623 * @param width
1624 * Unused?
1625 * @return The width
1626 */
1627 public int getNameWidthPref(int width) {
1628 return fNameWidthPref;
1629 }
1630
1631 /**
1632 * Returns the primary control associated with this viewer.
1633 *
1634 * @return the SWT control which displays this viewer's content
1635 */
1636 public Control getControl() {
1637 return fDataViewer;
1638 }
1639
1640 /**
1641 * Returns the time graph control associated with this viewer.
1642 *
1643 * @return the time graph control
1644 */
1645 public TimeGraphControl getTimeGraphControl() {
1646 return fTimeGraphCtrl;
1647 }
1648
1649 /**
1650 * Returns the time graph scale associated with this viewer.
1651 *
1652 * @return the time graph scale
1653 */
1654 public TimeGraphScale getTimeGraphScale() {
1655 return fTimeScaleCtrl;
1656 }
1657
1658 /**
1659 * Returns the composite containing all the controls that are time aligned,
1660 * i.e. TimeGraphScale, TimeGraphControl.
1661 *
1662 * @return the time based composite
1663 * @since 1.0
1664 */
1665 public Composite getTimeAlignedComposite() {
1666 return fTimeAlignedComposite;
1667 }
1668
1669 /**
1670 * Return the x coordinate corresponding to a time
1671 *
1672 * @param time
1673 * the time
1674 * @return the x coordinate corresponding to the time
1675 */
1676 public int getXForTime(long time) {
1677 return fTimeGraphCtrl.getXForTime(time);
1678 }
1679
1680 /**
1681 * Return the time corresponding to an x coordinate
1682 *
1683 * @param x
1684 * the x coordinate
1685 * @return the time corresponding to the x coordinate
1686 */
1687 public long getTimeAtX(int x) {
1688 return fTimeGraphCtrl.getTimeAtX(x);
1689 }
1690
1691 /**
1692 * Get the selection provider
1693 *
1694 * @return the selection provider
1695 */
1696 public ISelectionProvider getSelectionProvider() {
1697 return fTimeGraphCtrl;
1698 }
1699
1700 /**
1701 * Wait for the cursor
1702 *
1703 * @param waitInd
1704 * Wait indefinitely?
1705 */
1706 public void waitCursor(boolean waitInd) {
1707 fTimeGraphCtrl.waitCursor(waitInd);
1708 }
1709
1710 /**
1711 * Get the horizontal scroll bar object
1712 *
1713 * @return The scroll bar
1714 */
1715 public Slider getHorizontalBar() {
1716 return fHorizontalScrollBar;
1717 }
1718
1719 /**
1720 * Get the vertical scroll bar object
1721 *
1722 * @return The scroll bar
1723 */
1724 public Slider getVerticalBar() {
1725 return fVerticalScrollBar;
1726 }
1727
1728 /**
1729 * Set the given index as the top one
1730 *
1731 * @param index
1732 * The index that will go to the top
1733 */
1734 public void setTopIndex(int index) {
1735 fTimeGraphCtrl.setTopIndex(index);
1736 adjustVerticalScrollBar();
1737 }
1738
1739 /**
1740 * Retrieve the current top index
1741 *
1742 * @return The top index
1743 */
1744 public int getTopIndex() {
1745 return fTimeGraphCtrl.getTopIndex();
1746 }
1747
1748 /**
1749 * Sets the auto-expand level to be used for new entries discovered when
1750 * calling {@link #setInput(Object)} or {@link #refresh()}. The value 0
1751 * means that there is no auto-expand; 1 means that top-level entries are
1752 * expanded, but not their children; 2 means that top-level entries are
1753 * expanded, and their children, but not grand-children; and so on.
1754 * <p>
1755 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
1756 * </p>
1757 *
1758 * @param level
1759 * non-negative level, or <code>ALL_LEVELS</code> to expand all
1760 * levels of the tree
1761 */
1762 public void setAutoExpandLevel(int level) {
1763 fTimeGraphCtrl.setAutoExpandLevel(level);
1764 }
1765
1766 /**
1767 * Returns the auto-expand level.
1768 *
1769 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
1770 * the tree are expanded automatically
1771 * @see #setAutoExpandLevel
1772 */
1773 public int getAutoExpandLevel() {
1774 return fTimeGraphCtrl.getAutoExpandLevel();
1775 }
1776
1777 /**
1778 * Get the expanded state of an entry.
1779 *
1780 * @param entry
1781 * The entry
1782 * @return true if the entry is expanded, false if collapsed
1783 * @since 1.1
1784 */
1785 public boolean getExpandedState(ITimeGraphEntry entry) {
1786 return fTimeGraphCtrl.getExpandedState(entry);
1787 }
1788
1789 /**
1790 * Set the expanded state of an entry
1791 *
1792 * @param entry
1793 * The entry to expand/collapse
1794 * @param expanded
1795 * True for expanded, false for collapsed
1796 */
1797 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
1798 fTimeGraphCtrl.setExpandedState(entry, expanded);
1799 adjustVerticalScrollBar();
1800 }
1801
1802 /**
1803 * Collapses all nodes of the viewer's tree, starting with the root.
1804 */
1805 public void collapseAll() {
1806 fTimeGraphCtrl.collapseAll();
1807 adjustVerticalScrollBar();
1808 }
1809
1810 /**
1811 * Expands all entries of the viewer's tree, starting with the root.
1812 */
1813 public void expandAll() {
1814 fTimeGraphCtrl.expandAll();
1815 adjustVerticalScrollBar();
1816 }
1817
1818 /**
1819 * Get the number of expanded (visible) time graph entries. This includes
1820 * leafs and does not include filtered-out entries.
1821 *
1822 * @return The number of expanded (visible) time graph entries
1823 */
1824 public int getExpandedElementCount() {
1825 return fTimeGraphCtrl.getExpandedElementCount();
1826 }
1827
1828 /**
1829 * Get the expanded (visible) time graph entries. This includes leafs and
1830 * does not include filtered-out entries.
1831 *
1832 * @return The array of expanded (visible) time graph entries
1833 */
1834 public ITimeGraphEntry[] getExpandedElements() {
1835 return fTimeGraphCtrl.getExpandedElements();
1836 }
1837
1838 /**
1839 * Add a tree listener
1840 *
1841 * @param listener
1842 * The listener to add
1843 */
1844 public void addTreeListener(ITimeGraphTreeListener listener) {
1845 fTimeGraphCtrl.addTreeListener(listener);
1846 }
1847
1848 /**
1849 * Remove a tree listener
1850 *
1851 * @param listener
1852 * The listener to remove
1853 */
1854 public void removeTreeListener(ITimeGraphTreeListener listener) {
1855 fTimeGraphCtrl.removeTreeListener(listener);
1856 }
1857
1858 /**
1859 * Get the reset scale action.
1860 *
1861 * @return The Action object
1862 */
1863 public Action getResetScaleAction() {
1864 if (fResetScaleAction == null) {
1865 // resetScale
1866 fResetScaleAction = new Action() {
1867 @Override
1868 public void run() {
1869 resetStartFinishTime();
1870 }
1871 };
1872 fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
1873 fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
1874 fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
1875 }
1876 return fResetScaleAction;
1877 }
1878
1879 /**
1880 * Get the show legend action.
1881 *
1882 * @return The Action object
1883 */
1884 public Action getShowLegendAction() {
1885 if (fShowLegendAction == null) {
1886 // showLegend
1887 fShowLegendAction = new Action() {
1888 @Override
1889 public void run() {
1890 showLegend();
1891 }
1892 };
1893 fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
1894 fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
1895 fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
1896 }
1897
1898 return fShowLegendAction;
1899 }
1900
1901 /**
1902 * Get the the next event action.
1903 *
1904 * @return The action object
1905 */
1906 public Action getNextEventAction() {
1907 if (fNextEventAction == null) {
1908 fNextEventAction = new Action() {
1909 @Override
1910 public void runWithEvent(Event event) {
1911 boolean extend = (event.stateMask & SWT.SHIFT) != 0;
1912 selectNextEvent(extend);
1913 }
1914 };
1915
1916 fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
1917 fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
1918 fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
1919 }
1920
1921 return fNextEventAction;
1922 }
1923
1924 /**
1925 * Get the previous event action.
1926 *
1927 * @return The Action object
1928 */
1929 public Action getPreviousEventAction() {
1930 if (fPrevEventAction == null) {
1931 fPrevEventAction = new Action() {
1932 @Override
1933 public void runWithEvent(Event event) {
1934 boolean extend = (event.stateMask & SWT.SHIFT) != 0;
1935 selectPrevEvent(extend);
1936 }
1937 };
1938
1939 fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
1940 fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
1941 fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
1942 }
1943
1944 return fPrevEventAction;
1945 }
1946
1947 /**
1948 * Get the next item action.
1949 *
1950 * @return The Action object
1951 */
1952 public Action getNextItemAction() {
1953 if (fNextItemAction == null) {
1954
1955 fNextItemAction = new Action() {
1956 @Override
1957 public void run() {
1958 selectNextItem();
1959 }
1960 };
1961 fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
1962 fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
1963 fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
1964 }
1965 return fNextItemAction;
1966 }
1967
1968 /**
1969 * Get the previous item action.
1970 *
1971 * @return The Action object
1972 */
1973 public Action getPreviousItemAction() {
1974 if (fPreviousItemAction == null) {
1975
1976 fPreviousItemAction = new Action() {
1977 @Override
1978 public void run() {
1979 selectPrevItem();
1980 }
1981 };
1982 fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
1983 fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
1984 fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
1985 }
1986 return fPreviousItemAction;
1987 }
1988
1989 /**
1990 * Get the zoom in action
1991 *
1992 * @return The Action object
1993 */
1994 public Action getZoomInAction() {
1995 if (fZoomInAction == null) {
1996 fZoomInAction = new Action() {
1997 @Override
1998 public void run() {
1999 zoomIn();
2000 }
2001 };
2002 fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
2003 fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
2004 fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
2005 }
2006 return fZoomInAction;
2007 }
2008
2009 /**
2010 * Get the zoom out action
2011 *
2012 * @return The Action object
2013 */
2014 public Action getZoomOutAction() {
2015 if (fZoomOutAction == null) {
2016 fZoomOutAction = new Action() {
2017 @Override
2018 public void run() {
2019 zoomOut();
2020 }
2021 };
2022 fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
2023 fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
2024 fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
2025 }
2026 return fZoomOutAction;
2027 }
2028
2029 /**
2030 * Get the hide arrows action
2031 *
2032 * @param dialogSettings
2033 * The dialog settings section where the state should be stored,
2034 * or null
2035 *
2036 * @return The Action object
2037 */
2038 public Action getHideArrowsAction(final IDialogSettings dialogSettings) {
2039 if (fHideArrowsAction == null) {
2040 fHideArrowsAction = new Action(Messages.TmfTimeGraphViewer_HideArrowsActionNameText, IAction.AS_CHECK_BOX) {
2041 @Override
2042 public void run() {
2043 boolean hideArrows = fHideArrowsAction.isChecked();
2044 fTimeGraphCtrl.hideArrows(hideArrows);
2045 refresh();
2046 if (dialogSettings != null) {
2047 dialogSettings.put(HIDE_ARROWS_KEY, hideArrows);
2048 }
2049 if (fFollowArrowFwdAction != null) {
2050 fFollowArrowFwdAction.setEnabled(!hideArrows);
2051 }
2052 if (fFollowArrowBwdAction != null) {
2053 fFollowArrowBwdAction.setEnabled(!hideArrows);
2054 }
2055 }
2056 };
2057 fHideArrowsAction.setToolTipText(Messages.TmfTimeGraphViewer_HideArrowsActionToolTipText);
2058 fHideArrowsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HIDE_ARROWS));
2059 if (dialogSettings != null) {
2060 boolean hideArrows = dialogSettings.getBoolean(HIDE_ARROWS_KEY);
2061 fTimeGraphCtrl.hideArrows(hideArrows);
2062 fHideArrowsAction.setChecked(hideArrows);
2063 if (fFollowArrowFwdAction != null) {
2064 fFollowArrowFwdAction.setEnabled(!hideArrows);
2065 }
2066 if (fFollowArrowBwdAction != null) {
2067 fFollowArrowBwdAction.setEnabled(!hideArrows);
2068 }
2069 }
2070 }
2071 return fHideArrowsAction;
2072 }
2073
2074 /**
2075 * Get the follow arrow forward action.
2076 *
2077 * @return The Action object
2078 */
2079 public Action getFollowArrowFwdAction() {
2080 if (fFollowArrowFwdAction == null) {
2081 fFollowArrowFwdAction = new Action() {
2082 @Override
2083 public void runWithEvent(Event event) {
2084 boolean extend = (event.stateMask & SWT.SHIFT) != 0;
2085 fTimeGraphCtrl.followArrowFwd(extend);
2086 adjustVerticalScrollBar();
2087 }
2088 };
2089 fFollowArrowFwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionNameText);
2090 fFollowArrowFwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText);
2091 fFollowArrowFwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_FORWARD));
2092 if (fHideArrowsAction != null) {
2093 fFollowArrowFwdAction.setEnabled(!fHideArrowsAction.isChecked());
2094 }
2095 }
2096 return fFollowArrowFwdAction;
2097 }
2098
2099 /**
2100 * Get the follow arrow backward action.
2101 *
2102 * @return The Action object
2103 */
2104 public Action getFollowArrowBwdAction() {
2105 if (fFollowArrowBwdAction == null) {
2106 fFollowArrowBwdAction = new Action() {
2107 @Override
2108 public void runWithEvent(Event event) {
2109 boolean extend = (event.stateMask & SWT.SHIFT) != 0;
2110 fTimeGraphCtrl.followArrowBwd(extend);
2111 adjustVerticalScrollBar();
2112 }
2113 };
2114 fFollowArrowBwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionNameText);
2115 fFollowArrowBwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText);
2116 fFollowArrowBwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_BACKWARD));
2117 if (fHideArrowsAction != null) {
2118 fFollowArrowBwdAction.setEnabled(!fHideArrowsAction.isChecked());
2119 }
2120 }
2121 return fFollowArrowBwdAction;
2122 }
2123
2124 /**
2125 * Get the show filter dialog action.
2126 *
2127 * @return The Action object
2128 * @since 2.0
2129 */
2130 public ShowFilterDialogAction getShowFilterDialogAction() {
2131 if (fShowFilterDialogAction == null) {
2132 fShowFilterDialogAction = new ShowFilterDialogAction(this);
2133 }
2134 return fShowFilterDialogAction;
2135 }
2136
2137 /**
2138 * Get the toggle bookmark action.
2139 *
2140 * @return The Action object
2141 * @since 2.0
2142 */
2143 public Action getToggleBookmarkAction() {
2144 if (fToggleBookmarkAction == null) {
2145 fToggleBookmarkAction = new Action() {
2146 @Override
2147 public void runWithEvent(Event event) {
2148 IMarkerEvent selectedBookmark = getBookmarkAtSelection();
2149 if (selectedBookmark == null) {
2150 final long time = Math.min(fSelectionBegin, fSelectionEnd);
2151 final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
2152 final AddBookmarkDialog dialog = new AddBookmarkDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
2153 if (dialog.open() == Window.OK) {
2154 final String label = dialog.getValue();
2155 final RGBA rgba = dialog.getColorValue();
2156 IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, rgba, label, true);
2157 fBookmarks.add(bookmark);
2158 updateMarkerList();
2159 updateMarkerActions();
2160 getControl().redraw();
2161 fireBookmarkAdded(bookmark);
2162 }
2163 } else {
2164 fBookmarks.remove(selectedBookmark);
2165 updateMarkerList();
2166 updateMarkerActions();
2167 getControl().redraw();
2168 fireBookmarkRemoved(selectedBookmark);
2169 }
2170 }
2171 };
2172 fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
2173 fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
2174 fToggleBookmarkAction.setImageDescriptor(ADD_BOOKMARK);
2175 }
2176 return fToggleBookmarkAction;
2177 }
2178
2179 /**
2180 * Get the next marker action.
2181 *
2182 * @return The Action object
2183 * @since 2.0
2184 */
2185 public Action getNextMarkerAction() {
2186 if (fNextMarkerAction == null) {
2187 fNextMarkerAction = new Action(Messages.TmfTimeGraphViewer_NextMarkerActionText, IAction.AS_DROP_DOWN_MENU) {
2188 @Override
2189 public void runWithEvent(Event event) {
2190 boolean extend = (event.stateMask & SWT.SHIFT) != 0;
2191 if (extend) {
2192 extendToNextMarker();
2193 } else {
2194 selectNextMarker();
2195 }
2196 }
2197 };
2198 fNextMarkerAction.setToolTipText(Messages.TmfTimeGraphViewer_NextMarkerActionText);
2199 fNextMarkerAction.setImageDescriptor(NEXT_BOOKMARK);
2200 fNextMarkerAction.setMenuCreator(new IMenuCreator () {
2201 Menu menu = null;
2202 @Override
2203 public void dispose() {
2204 if (menu != null) {
2205 menu.dispose();
2206 menu = null;
2207 }
2208 }
2209
2210 @Override
2211 public Menu getMenu(Control parent) {
2212 if (menu != null) {
2213 menu.dispose();
2214 }
2215 menu = new Menu(parent);
2216 for (String category : fMarkerCategories) {
2217 final Action action = new Action(category, IAction.AS_CHECK_BOX) {
2218 @Override
2219 public void runWithEvent(Event event) {
2220 if (isChecked()) {
2221 fSkippedMarkerCategories.remove(getText());
2222 } else {
2223 fSkippedMarkerCategories.add(getText());
2224 }
2225 updateMarkerActions();
2226 }
2227 };
2228 action.setEnabled(!fHiddenMarkerCategories.contains(category));
2229 action.setChecked(action.isEnabled() && !fSkippedMarkerCategories.contains(category));
2230 new ActionContributionItem(action).fill(menu, -1);
2231 }
2232 return menu;
2233 }
2234
2235 @Override
2236 public Menu getMenu(Menu parent) {
2237 return null;
2238 }
2239 });
2240 }
2241 return fNextMarkerAction;
2242 }
2243
2244 /**
2245 * Get the previous marker action.
2246 *
2247 * @return The Action object
2248 * @since 2.0
2249 */
2250 public Action getPreviousMarkerAction() {
2251 if (fPreviousMarkerAction == null) {
2252 fPreviousMarkerAction = new Action() {
2253 @Override
2254 public void runWithEvent(Event event) {
2255 boolean extend = (event.stateMask & SWT.SHIFT) != 0;
2256 if (extend) {
2257 extendToPrevMarker();
2258 } else {
2259 selectPrevMarker();
2260 }
2261 }
2262 };
2263 fPreviousMarkerAction.setText(Messages.TmfTimeGraphViewer_PreviousMarkerActionText);
2264 fPreviousMarkerAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousMarkerActionText);
2265 fPreviousMarkerAction.setImageDescriptor(PREVIOUS_BOOKMARK);
2266 }
2267 return fPreviousMarkerAction;
2268 }
2269
2270 /**
2271 * Get the show markers menu.
2272 *
2273 * @return The menu manager object
2274 * @since 2.0
2275 */
2276 public MenuManager getMarkersMenu() {
2277 if (fMarkersMenu == null) {
2278 fMarkersMenu = new MenuManager(Messages.TmfTimeGraphViewer_ShowMarkersMenuText);
2279 fMarkersMenu.setRemoveAllWhenShown(true);
2280 fMarkersMenu.addMenuListener(new IMenuListener() {
2281 @Override
2282 public void menuAboutToShow(IMenuManager manager) {
2283 for (String category : fMarkerCategories) {
2284 final Action action = new Action(category, IAction.AS_CHECK_BOX) {
2285 @Override
2286 public void runWithEvent(Event event) {
2287 setMarkerCategoryVisible(getText(), isChecked());
2288 }
2289 };
2290 action.setChecked(!fHiddenMarkerCategories.contains(category));
2291 manager.add(action);
2292 }
2293 }
2294 });
2295 }
2296 return fMarkersMenu;
2297 }
2298
2299 /**
2300 * Select the next marker that begins at or after the current selection
2301 * begin time. Markers that begin at the same time are ordered by end time.
2302 */
2303 private void selectNextMarker() {
2304 List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
2305 if (markers == null) {
2306 return;
2307 }
2308 for (IMarkerEvent marker : markers) {
2309 final long time = Math.min(fSelectionBegin, fSelectionEnd);
2310 final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
2311 if ((marker.getTime() > time ||
2312 (marker.getTime() == time && marker.getDuration() > duration))
2313 && !fSkippedMarkerCategories.contains(marker.getCategory())) {
2314 setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration(), false);
2315 ensureVisible(marker.getTime());
2316 notifyRangeListeners();
2317 fTimeGraphCtrl.updateStatusLine();
2318 return;
2319 }
2320 }
2321 }
2322
2323 /**
2324 * Select the previous marker that begins at or before the current selection
2325 * begin time. Markers that begin at the same time are ordered by end time.
2326 */
2327 private void selectPrevMarker() {
2328 List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
2329 if (markers == null) {
2330 return;
2331 }
2332 final long time = Math.min(fSelectionBegin, fSelectionEnd);
2333 final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
2334 for (int i = markers.size() - 1; i >= 0; i--) {
2335 IMarkerEvent marker = markers.get(i);
2336 if ((marker.getTime() < time ||
2337 (marker.getTime() == time && marker.getDuration() < duration))
2338 && !fSkippedMarkerCategories.contains(marker.getCategory())) {
2339 setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration(), false);
2340 ensureVisible(marker.getTime());
2341 notifyRangeListeners();
2342 fTimeGraphCtrl.updateStatusLine();
2343 return;
2344 }
2345 }
2346 }
2347
2348 /**
2349 * Extend the selection to the closest next marker end time.
2350 */
2351 private void extendToNextMarker() {
2352 List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
2353 if (markers == null) {
2354 return;
2355 }
2356 IMarkerEvent nextMarker = null;
2357 for (IMarkerEvent marker : markers) {
2358 if (marker.getTime() + marker.getDuration() > fSelectionEnd
2359 && !fSkippedMarkerCategories.contains(marker.getCategory())
2360 && (nextMarker == null || marker.getTime() + marker.getDuration() < nextMarker.getTime() + nextMarker.getDuration())) {
2361 nextMarker = marker;
2362 }
2363 }
2364 if (nextMarker != null) {
2365 setSelectionRangeNotify(fSelectionBegin, nextMarker.getTime() + nextMarker.getDuration(), true);
2366 fTimeGraphCtrl.updateStatusLine();
2367 }
2368 }
2369
2370 /**
2371 * Extend the selection to the closest previous marker start time.
2372 */
2373 private void extendToPrevMarker() {
2374 List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
2375 if (markers == null) {
2376 return;
2377 }
2378 for (int i = markers.size() - 1; i >= 0; i--) {
2379 IMarkerEvent marker = markers.get(i);
2380 if (marker.getTime() < fSelectionEnd
2381 && !fSkippedMarkerCategories.contains(marker.getCategory())) {
2382 setSelectionRangeNotify(fSelectionBegin, marker.getTime(), true);
2383 fTimeGraphCtrl.updateStatusLine();
2384 return;
2385 }
2386 }
2387 }
2388
2389 private IMarkerEvent getBookmarkAtSelection() {
2390 final long time = Math.min(fSelectionBegin, fSelectionEnd);
2391 final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
2392 for (IMarkerEvent bookmark : fBookmarks) {
2393 if (bookmark.getTime() == time && bookmark.getDuration() == duration) {
2394 return bookmark;
2395 }
2396 }
2397 return null;
2398 }
2399
2400 private void updateMarkerActions() {
2401 boolean enabled = fTime0Bound != SWT.DEFAULT || fTime1Bound != SWT.DEFAULT;
2402 if (fToggleBookmarkAction != null) {
2403 if (getBookmarkAtSelection() != null) {
2404 fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionRemoveText);
2405 fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionRemoveText);
2406 fToggleBookmarkAction.setImageDescriptor(REMOVE_BOOKMARK);
2407 } else {
2408 fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
2409 fToggleBookmarkAction.setToolTipText(Messages.TmfTimeGraphViewer_BookmarkActionAddText);
2410 fToggleBookmarkAction.setImageDescriptor(ADD_BOOKMARK);
2411 }
2412 fToggleBookmarkAction.setEnabled(enabled);
2413 }
2414 List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
2415 if (markers == null) {
2416 markers = Collections.emptyList();
2417 }
2418 if (fPreviousMarkerAction != null) {
2419 fPreviousMarkerAction.setEnabled(enabled && !markers.isEmpty());
2420 }
2421 if (fNextMarkerAction != null) {
2422 fNextMarkerAction.setEnabled(enabled && !markers.isEmpty());
2423 }
2424 }
2425
2426 private void updateMarkerList() {
2427 List<IMarkerEvent> markers = new ArrayList<>();
2428 for (IMarkerEvent marker : fMarkers) {
2429 if (!fHiddenMarkerCategories.contains(marker.getCategory())) {
2430 markers.add(marker);
2431 }
2432 }
2433 if (!fHiddenMarkerCategories.contains(IMarkerEvent.BOOKMARKS)) {
2434 markers.addAll(fBookmarks);
2435 }
2436 Collections.sort(markers, new MarkerComparator());
2437 fTimeGraphCtrl.setMarkers(markers);
2438 fMarkerAxisCtrl.setMarkers(markers);
2439 }
2440
2441 private void adjustHorizontalScrollBar() {
2442 long time0 = getTime0();
2443 long time1 = getTime1();
2444 long timeMin = getMinTime();
2445 long timeMax = getMaxTime();
2446 long delta = timeMax - timeMin;
2447 int timePos = 0;
2448 int thumb = H_SCROLLBAR_MAX;
2449 if (delta != 0) {
2450 // Thumb size (page size)
2451 thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));
2452 // At the beginning of visible window
2453 timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta));
2454 }
2455 fHorizontalScrollBar.setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb));
2456 }
2457
2458 private void adjustVerticalScrollBar() {
2459 int topIndex = fTimeGraphCtrl.getTopIndex();
2460 int countPerPage = fTimeGraphCtrl.countPerPage();
2461 int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount();
2462 if (topIndex + countPerPage > expandedElementCount) {
2463 fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
2464 }
2465
2466 int selection = fTimeGraphCtrl.getTopIndex();
2467 int min = 0;
2468 int max = Math.max(1, expandedElementCount - 1);
2469 int thumb = Math.min(max, Math.max(1, countPerPage - 1));
2470 int increment = 1;
2471 int pageIncrement = Math.max(1, countPerPage);
2472 fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
2473 }
2474
2475 /**
2476 * @param listener
2477 * a {@link MenuDetectListener}
2478 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2479 */
2480 public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
2481 fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener);
2482 }
2483
2484 /**
2485 * @param listener
2486 * a {@link MenuDetectListener}
2487 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
2488 */
2489 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
2490 fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener);
2491 }
2492
2493 /**
2494 * @param listener
2495 * a {@link MenuDetectListener}
2496 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2497 */
2498 public void addTimeEventMenuListener(MenuDetectListener listener) {
2499 fTimeGraphCtrl.addTimeEventMenuListener(listener);
2500 }
2501
2502 /**
2503 * @param listener
2504 * a {@link MenuDetectListener}
2505 * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
2506 */
2507 public void removeTimeEventMenuListener(MenuDetectListener listener) {
2508 fTimeGraphCtrl.removeTimeEventMenuListener(listener);
2509 }
2510
2511 /**
2512 * @param filter
2513 * The filter object to be attached to the view
2514 */
2515 public void addFilter(@NonNull ViewerFilter filter) {
2516 fTimeGraphCtrl.addFilter(filter);
2517 refresh();
2518 }
2519
2520 /**
2521 * @param filter
2522 * The filter object to be attached to the view
2523 */
2524 public void removeFilter(@NonNull ViewerFilter filter) {
2525 fTimeGraphCtrl.removeFilter(filter);
2526 refresh();
2527 }
2528
2529 /**
2530 * Returns this viewer's filters.
2531 *
2532 * @return an array of viewer filters
2533 * @since 2.0
2534 */
2535 public @NonNull ViewerFilter[] getFilters() {
2536 return fTimeGraphCtrl.getFilters();
2537 }
2538
2539 /**
2540 * Sets the filters, replacing any previous filters, and triggers
2541 * refiltering of the elements.
2542 *
2543 * @param filters
2544 * an array of viewer filters, or null
2545 * @since 2.0
2546 */
2547 public void setFilters(@NonNull ViewerFilter[] filters) {
2548 fTimeGraphCtrl.setFilters(filters);
2549 refresh();
2550 }
2551
2552 /**
2553 * Return the time alignment information
2554 *
2555 * @return the time alignment information
2556 *
2557 * @see ITmfTimeAligned
2558 *
2559 * @since 1.0
2560 */
2561 public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() {
2562 return fTimeGraphCtrl.getTimeViewAlignmentInfo();
2563 }
2564
2565 /**
2566 * Return the available width for the time-axis.
2567 *
2568 * @see ITmfTimeAligned
2569 *
2570 * @param requestedOffset
2571 * the requested offset
2572 * @return the available width for the time-axis
2573 *
2574 * @since 1.0
2575 */
2576 public int getAvailableWidth(int requestedOffset) {
2577 int totalWidth = fTimeAlignedComposite.getSize().x;
2578 return Math.min(totalWidth, Math.max(0, totalWidth - requestedOffset));
2579 }
2580
2581 /**
2582 * Perform the alignment operation.
2583 *
2584 * @param offset
2585 * the alignment offset
2586 * @param width
2587 * the alignment width
2588 *
2589 * @see ITmfTimeAligned
2590 *
2591 * @since 1.0
2592 */
2593 public void performAlign(int offset, int width) {
2594 fTimeGraphCtrl.performAlign(offset);
2595 int alignmentWidth = width;
2596 int size = fTimeAlignedComposite.getSize().x;
2597 GridLayout layout = (GridLayout) fTimeAlignedComposite.getLayout();
2598 int marginSize = size - alignmentWidth - offset;
2599 layout.marginRight = Math.max(0, marginSize);
2600 fTimeAlignedComposite.layout();
2601 }
2602
2603 }
This page took 0.092072 seconds and 6 git commands to generate.