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