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