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