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