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