ctf: make DeclarationScope.java more inline with coding style
[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;
0fcf3b09 34import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider2;
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 */
0fcf3b09 67public class TimeGraphViewer implements ITimeDataProvider2, 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) {
372 adjustVerticalScrollBar();
373 }
374 });
375
f1fae91f 376 Composite filler = new Composite(fDataViewer, SWT.NONE);
837a2f8c 377 GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
f1fae91f 378 gd.heightHint = fTimeGraphCtrl.getHorizontalBar().getSize().y;
837a2f8c
PT
379 filler.setLayoutData(gd);
380 filler.setLayout(new FillLayout());
381
f1fae91f 382 fTimeGraphCtrl.addControlListener(new ControlAdapter() {
837a2f8c
PT
383 @Override
384 public void controlResized(ControlEvent event) {
385 resizeControls();
386 }
387 });
388 resizeControls();
f1fae91f 389 fDataViewer.update();
837a2f8c 390 adjustVerticalScrollBar();
f1fae91f 391 return fDataViewer;
837a2f8c
PT
392 }
393
394 /**
395 * Dispose the view.
396 */
397 public void dispose() {
398 saveOptions();
f1fae91f
PT
399 fTimeGraphCtrl.dispose();
400 fDataViewer.dispose();
401 fColorScheme.dispose();
837a2f8c
PT
402 }
403
96d00a83 404 /**
a0a88f65
AM
405 * Create a new time graph control.
406 *
407 * @param parent
408 * The parent composite
409 * @param colors
410 * The color scheme
411 * @return The new TimeGraphControl
96d00a83
PT
412 * @since 2.0
413 */
a0a88f65
AM
414 protected TimeGraphControl createTimeGraphControl(Composite parent,
415 TimeGraphColorScheme colors) {
96d00a83 416 return new TimeGraphControl(parent, colors);
837a2f8c
PT
417 }
418
419 /**
420 * Resize the controls
421 */
422 public void resizeControls() {
f1fae91f 423 Rectangle r = fDataViewer.getClientArea();
837a2f8c
PT
424 if (r.isEmpty()) {
425 return;
426 }
427
428 int width = r.width;
f1fae91f
PT
429 if (fNameWidth > width - fMinNameWidth) {
430 fNameWidth = width - fMinNameWidth;
837a2f8c 431 }
f1fae91f
PT
432 if (fNameWidth < fMinNameWidth) {
433 fNameWidth = fMinNameWidth;
837a2f8c
PT
434 }
435 adjustVerticalScrollBar();
436 }
437
438 /**
439 * Try to set most convenient time range for display.
440 *
441 * @param traces
442 * The traces in the model
443 */
444 public void setTimeRange(ITimeGraphEntry traces[]) {
f1fae91f
PT
445 fEndTime = 0;
446 fBeginTime = -1;
837a2f8c
PT
447 for (int i = 0; i < traces.length; i++) {
448 ITimeGraphEntry entry = traces[i];
449 if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) {
f1fae91f
PT
450 if (fBeginTime < 0 || entry.getStartTime() < fBeginTime) {
451 fBeginTime = entry.getStartTime();
837a2f8c 452 }
f1fae91f
PT
453 if (entry.getEndTime() > fEndTime) {
454 fEndTime = entry.getEndTime();
837a2f8c
PT
455 }
456 }
457 }
458
f1fae91f
PT
459 if (fBeginTime < 0) {
460 fBeginTime = 0;
837a2f8c
PT
461 }
462 }
463
464 /**
465 * Recalculate the time bounds
466 */
467 public void setTimeBounds() {
f1fae91f
PT
468 fTime0Bound = fBeginTime;
469 if (fTime0Bound < 0) {
470 fTime0Bound = 0;
837a2f8c 471 }
f1fae91f
PT
472 fTime1Bound = fEndTime;
473 if (!fTimeRangeFixed) {
474 fTime0 = fTime0Bound;
475 fTime1 = fTime1Bound;
837a2f8c 476 }
407bfdd5
PT
477 fTime0 = Math.max(fTime0Bound, Math.min(fTime0, fTime1Bound));
478 fTime1 = Math.max(fTime0Bound, Math.min(fTime1, fTime1Bound));
f1fae91f
PT
479 if (fTime1 - fTime0 < fMinTimeInterval) {
480 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
837a2f8c
PT
481 }
482 }
483
484 /**
485 * @param traces
486 * @param start
487 * @param end
488 */
489 void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {
41b5c37f
AM
490 ITimeGraphEntry[] realTraces = traces;
491
492 if (null == realTraces) {
493 realTraces = new ITimeGraphEntry[0];
837a2f8c
PT
494 }
495 if ((start == 0 && end == 0) || start < 0 || end < 0) {
496 // Start and end time are unspecified and need to be determined from
497 // individual processes
41b5c37f 498 setTimeRange(realTraces);
837a2f8c 499 } else {
f1fae91f
PT
500 fBeginTime = start;
501 fEndTime = end;
837a2f8c
PT
502 }
503
41b5c37f 504 refreshAllData(realTraces);
837a2f8c
PT
505 }
506
507 /**
508 * @param traces
509 */
510 private void refreshAllData(ITimeGraphEntry[] traces) {
511 setTimeBounds();
0fcf3b09
PT
512 if (fSelectionBegin < fBeginTime) {
513 fSelectionBegin = fBeginTime;
514 } else if (fSelectionBegin > fEndTime) {
515 fSelectionBegin = fEndTime;
516 }
517 if (fSelectionEnd < fBeginTime) {
518 fSelectionEnd = fBeginTime;
519 } else if (fSelectionEnd > fEndTime) {
520 fSelectionEnd = fEndTime;
837a2f8c 521 }
f1fae91f
PT
522 fTimeGraphCtrl.refreshData(traces);
523 fTimeScaleCtrl.redraw();
837a2f8c
PT
524 adjustVerticalScrollBar();
525 }
526
527 /**
528 * Callback for when this view is focused
529 */
530 public void setFocus() {
f1fae91f
PT
531 if (null != fTimeGraphCtrl) {
532 fTimeGraphCtrl.setFocus();
837a2f8c
PT
533 }
534 }
535
536 /**
537 * Get the current focus status of this view.
538 *
539 * @return If the view is currently focused, or not
540 */
541 public boolean isInFocus() {
f1fae91f 542 return fTimeGraphCtrl.isInFocus();
837a2f8c
PT
543 }
544
545 /**
546 * Get the view's current selection
547 *
548 * @return The entry that is selected
549 */
550 public ITimeGraphEntry getSelection() {
f1fae91f 551 return fTimeGraphCtrl.getSelectedTrace();
837a2f8c
PT
552 }
553
554 /**
555 * Get the index of the current selection
556 *
557 * @return The index
558 */
559 public int getSelectionIndex() {
f1fae91f 560 return fTimeGraphCtrl.getSelectedIndex();
837a2f8c
PT
561 }
562
563 @Override
564 public long getTime0() {
f1fae91f 565 return fTime0;
837a2f8c
PT
566 }
567
568 @Override
569 public long getTime1() {
f1fae91f 570 return fTime1;
837a2f8c
PT
571 }
572
573 @Override
574 public long getMinTimeInterval() {
f1fae91f 575 return fMinTimeInterval;
837a2f8c
PT
576 }
577
578 @Override
579 public int getNameSpace() {
f1fae91f 580 return fNameWidth;
837a2f8c
PT
581 }
582
583 @Override
584 public void setNameSpace(int width) {
f1fae91f
PT
585 fNameWidth = width;
586 int w = fTimeGraphCtrl.getClientArea().width;
587 if (fNameWidth > w - MIN_NAME_WIDTH) {
588 fNameWidth = w - MIN_NAME_WIDTH;
837a2f8c 589 }
f1fae91f
PT
590 if (fNameWidth < MIN_NAME_WIDTH) {
591 fNameWidth = MIN_NAME_WIDTH;
837a2f8c 592 }
f1fae91f
PT
593 fTimeGraphCtrl.adjustScrolls();
594 fTimeGraphCtrl.redraw();
595 fTimeScaleCtrl.redraw();
837a2f8c
PT
596 }
597
598 @Override
599 public int getTimeSpace() {
f1fae91f
PT
600 int w = fTimeGraphCtrl.getClientArea().width;
601 return w - fNameWidth;
837a2f8c
PT
602 }
603
0fcf3b09
PT
604 @SuppressWarnings("deprecation")
605 @Deprecated
837a2f8c
PT
606 @Override
607 public long getSelectedTime() {
0fcf3b09 608 return fSelectionBegin;
837a2f8c
PT
609 }
610
611 @Override
612 public long getBeginTime() {
f1fae91f 613 return fBeginTime;
837a2f8c
PT
614 }
615
616 @Override
617 public long getEndTime() {
f1fae91f 618 return fEndTime;
837a2f8c
PT
619 }
620
621 @Override
622 public long getMaxTime() {
f1fae91f 623 return fTime1Bound;
837a2f8c
PT
624 }
625
626 @Override
627 public long getMinTime() {
f1fae91f 628 return fTime0Bound;
837a2f8c
PT
629 }
630
0fcf3b09
PT
631 /**
632 * @since 2.1
633 */
634 @Override
635 public long getSelectionBegin() {
636 return fSelectionBegin;
637 }
638
639 /**
640 * @since 2.1
641 */
642 @Override
643 public long getSelectionEnd() {
644 return fSelectionEnd;
645 }
646
837a2f8c
PT
647 @Override
648 public void setStartFinishTimeNotify(long time0, long time1) {
649 setStartFinishTime(time0, time1);
650 notifyRangeListeners(time0, time1);
651 }
652
837a2f8c
PT
653 @Override
654 public void notifyStartFinishTime() {
f1fae91f 655 notifyRangeListeners(fTime0, fTime1);
837a2f8c
PT
656 }
657
837a2f8c
PT
658 @Override
659 public void setStartFinishTime(long time0, long time1) {
f1fae91f
PT
660 fTime0 = time0;
661 if (fTime0 < fTime0Bound) {
662 fTime0 = fTime0Bound;
837a2f8c 663 }
f1fae91f
PT
664 if (fTime0 > fTime1Bound) {
665 fTime0 = fTime1Bound;
837a2f8c 666 }
f1fae91f
PT
667 fTime1 = time1;
668 if (fTime1 < fTime0Bound) {
669 fTime1 = fTime0Bound;
837a2f8c 670 }
f1fae91f
PT
671 if (fTime1 > fTime1Bound) {
672 fTime1 = fTime1Bound;
837a2f8c 673 }
f1fae91f
PT
674 if (fTime1 - fTime0 < fMinTimeInterval) {
675 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
837a2f8c 676 }
f1fae91f
PT
677 fTimeRangeFixed = true;
678 fTimeGraphCtrl.adjustScrolls();
679 fTimeGraphCtrl.redraw();
680 fTimeScaleCtrl.redraw();
837a2f8c
PT
681 }
682
683 /**
684 * Set the time bounds to the provided values
685 *
686 * @param beginTime
687 * The start time of the window
688 * @param endTime
689 * The end time
690 */
691 public void setTimeBounds(long beginTime, long endTime) {
407bfdd5
PT
692 if (endTime >= beginTime) {
693 fBeginTime = beginTime;
694 fEndTime = endTime;
695 fTime0Bound = beginTime;
696 fTime1Bound = endTime;
697 } else {
698 fBeginTime = 0;
699 fEndTime = 0;
700 fTime0Bound = 0;
701 fTime1Bound = 0;
702 }
f1fae91f 703 fTimeGraphCtrl.adjustScrolls();
837a2f8c
PT
704 }
705
706 @Override
707 public void resetStartFinishTime() {
f1fae91f
PT
708 setStartFinishTime(fTime0Bound, fTime1Bound);
709 fTimeRangeFixed = false;
837a2f8c
PT
710 }
711
712 @Override
713 public void setSelectedTimeNotify(long time, boolean ensureVisible) {
714 setSelectedTimeInt(time, ensureVisible, true);
715 }
716
717 @Override
718 public void setSelectedTime(long time, boolean ensureVisible) {
719 setSelectedTimeInt(time, ensureVisible, false);
720 }
721
0fcf3b09
PT
722 /**
723 * @since 2.1
724 */
725 @Override
726 public void setSelectionRangeNotify(long beginTime, long endTime) {
727 boolean changed = (beginTime != fSelectionBegin || endTime != fSelectionEnd);
728 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
729 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
730 fTimeGraphCtrl.redraw();
731 fTimeScaleCtrl.redraw();
732 if (changed) {
733 notifyTimeListeners(fSelectionBegin, fSelectionEnd);
734 }
735 }
736
737 /**
738 * @since 2.1
739 */
740 @Override
741 public void setSelectionRange(long beginTime, long endTime) {
742 fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
743 fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
744 fTimeGraphCtrl.redraw();
745 fTimeScaleCtrl.redraw();
746 }
747
837a2f8c 748 private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
f1fae91f
PT
749 long time0 = fTime0;
750 long time1 = fTime1;
837a2f8c 751 if (ensureVisible) {
f1fae91f
PT
752 long timeSpace = (fTime1 - fTime0) / RECENTERING_MARGIN_FACTOR;
753 long timeMid = (fTime1 - fTime0) / 2;
754 if (time < fTime0 + timeSpace) {
755 long dt = fTime0 - time + timeMid;
756 fTime0 -= dt;
757 fTime1 -= dt;
758 } else if (time > fTime1 - timeSpace) {
759 long dt = time - fTime1 + timeMid;
760 fTime0 += dt;
761 fTime1 += dt;
837a2f8c 762 }
f1fae91f
PT
763 if (fTime0 < fTime0Bound) {
764 fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0));
765 fTime0 = fTime0Bound;
766 } else if (fTime1 > fTime1Bound) {
767 fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound));
768 fTime1 = fTime1Bound;
837a2f8c
PT
769 }
770 }
f1fae91f
PT
771 if (fTime1 - fTime0 < fMinTimeInterval) {
772 fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
837a2f8c 773 }
f1fae91f
PT
774 fTimeGraphCtrl.adjustScrolls();
775 fTimeGraphCtrl.redraw();
776 fTimeScaleCtrl.redraw();
837a2f8c 777
0fcf3b09
PT
778 boolean notifySelectedTime = (time != fSelectionBegin || time != fSelectionEnd);
779 fSelectionBegin = time;
780 fSelectionEnd = time;
837a2f8c 781
f1fae91f
PT
782 if (doNotify && ((time0 != fTime0) || (time1 != fTime1))) {
783 notifyRangeListeners(fTime0, fTime1);
837a2f8c
PT
784 }
785
786 if (doNotify && notifySelectedTime) {
0fcf3b09 787 notifyTimeListeners(fSelectionBegin, fSelectionEnd);
837a2f8c
PT
788 }
789 }
790
791 @Override
792 public void widgetDefaultSelected(SelectionEvent e) {
f1fae91f
PT
793 if (fSelectedEntry != getSelection()) {
794 fSelectedEntry = getSelection();
795 notifySelectionListeners(fSelectedEntry);
837a2f8c
PT
796 }
797 }
798
799 @Override
800 public void widgetSelected(SelectionEvent e) {
f1fae91f
PT
801 if (fSelectedEntry != getSelection()) {
802 fSelectedEntry = getSelection();
803 notifySelectionListeners(fSelectedEntry);
837a2f8c
PT
804 }
805 }
806
807 /**
808 * Callback for when the next event is selected
809 */
810 public void selectNextEvent() {
f1fae91f 811 fTimeGraphCtrl.selectNextEvent();
837a2f8c
PT
812 adjustVerticalScrollBar();
813 }
814
815 /**
816 * Callback for when the previous event is selected
817 */
818 public void selectPrevEvent() {
f1fae91f 819 fTimeGraphCtrl.selectPrevEvent();
837a2f8c
PT
820 adjustVerticalScrollBar();
821 }
822
823 /**
824 * Callback for when the next item is selected
825 */
826 public void selectNextItem() {
f1fae91f 827 fTimeGraphCtrl.selectNextTrace();
837a2f8c
PT
828 adjustVerticalScrollBar();
829 }
830
831 /**
832 * Callback for when the previous item is selected
833 */
834 public void selectPrevItem() {
f1fae91f 835 fTimeGraphCtrl.selectPrevTrace();
837a2f8c
PT
836 adjustVerticalScrollBar();
837 }
838
839 /**
840 * Callback for the show legend action
841 */
842 public void showLegend() {
f1fae91f 843 if (fDataViewer == null || fDataViewer.isDisposed()) {
837a2f8c
PT
844 return;
845 }
846
f1fae91f 847 TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider);
837a2f8c
PT
848 }
849
850 /**
851 * Callback for the Zoom In action
852 */
853 public void zoomIn() {
f1fae91f 854 fTimeGraphCtrl.zoomIn();
837a2f8c
PT
855 }
856
857 /**
858 * Callback for the Zoom Out action
859 */
860 public void zoomOut() {
f1fae91f 861 fTimeGraphCtrl.zoomOut();
837a2f8c
PT
862 }
863
864 private String getPreferenceString(String string) {
865 return getViewTypeStr() + "." + string; //$NON-NLS-1$
866 }
867
868 /**
869 * Add a selection listener
870 *
871 * @param listener
872 * The listener to add
873 */
874 public void addSelectionListener(ITimeGraphSelectionListener listener) {
875 fSelectionListeners.add(listener);
876 }
877
878 /**
879 * Remove a selection listener
880 *
881 * @param listener
882 * The listener to remove
883 */
884 public void removeSelectionListener(ITimeGraphSelectionListener listener) {
885 fSelectionListeners.remove(listener);
886 }
887
888 private void notifySelectionListeners(ITimeGraphEntry selection) {
889 TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);
890
891 for (ITimeGraphSelectionListener listener : fSelectionListeners) {
892 listener.selectionChanged(event);
893 }
894 }
895
896 /**
897 * Add a time listener
898 *
899 * @param listener
900 * The listener to add
901 */
902 public void addTimeListener(ITimeGraphTimeListener listener) {
903 fTimeListeners.add(listener);
904 }
905
906 /**
907 * Remove a time listener
908 *
909 * @param listener
910 * The listener to remove
911 */
912 public void removeTimeListener(ITimeGraphTimeListener listener) {
913 fTimeListeners.remove(listener);
914 }
915
0fcf3b09
PT
916 private void notifyTimeListeners(long startTime, long endTime) {
917 TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime);
837a2f8c
PT
918
919 for (ITimeGraphTimeListener listener : fTimeListeners) {
920 listener.timeSelected(event);
921 }
922 }
923
924 /**
925 * Add a range listener
926 *
927 * @param listener
928 * The listener to add
929 */
930 public void addRangeListener(ITimeGraphRangeListener listener) {
931 fRangeListeners.add(listener);
932 }
933
934 /**
935 * Remove a range listener
936 *
937 * @param listener
938 * The listener to remove
939 */
940 public void removeRangeListener(ITimeGraphRangeListener listener) {
941 fRangeListeners.remove(listener);
942 }
943
944 private void notifyRangeListeners(long startTime, long endTime) {
945 // Check if the time has actually changed from last notification
f1fae91f 946 if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) {
837a2f8c
PT
947 // Notify Time Scale Selection Listeners
948 TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);
949
950 for (ITimeGraphRangeListener listener : fRangeListeners) {
951 listener.timeRangeUpdated(event);
952 }
953
954 // update external synch timers
955 updateExtSynchTimers();
956 }
957 }
958
959 /**
960 * Callback to set a selected event in the view
961 *
962 * @param event
963 * The event that was selected
964 * @param source
965 * The source of this selection event
966 */
967 public void setSelectedEvent(ITimeEvent event, Object source) {
968 if (event == null || source == this) {
969 return;
970 }
f1fae91f
PT
971 fSelectedEntry = event.getEntry();
972 fTimeGraphCtrl.selectItem(fSelectedEntry, false);
837a2f8c
PT
973
974 setSelectedTimeInt(event.getTime(), true, true);
975 adjustVerticalScrollBar();
976 }
977
978 /**
979 * Set the seeked time of a trace
980 *
981 * @param trace
982 * The trace that was seeked
983 * @param time
984 * The target time
985 * @param source
986 * The source of this seek event
987 */
988 public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {
989 if (trace == null || source == this) {
990 return;
991 }
f1fae91f
PT
992 fSelectedEntry = trace;
993 fTimeGraphCtrl.selectItem(trace, false);
837a2f8c
PT
994
995 setSelectedTimeInt(time, true, true);
996 }
997
998 /**
999 * Callback for a trace selection
1000 *
1001 * @param trace
1002 * The trace that was selected
1003 */
1004 public void setSelection(ITimeGraphEntry trace) {
f1fae91f
PT
1005 fSelectedEntry = trace;
1006 fTimeGraphCtrl.selectItem(trace, false);
837a2f8c
PT
1007 adjustVerticalScrollBar();
1008 }
1009
1010 /**
1011 * Callback for a time window selection
1012 *
1013 * @param time0
1014 * Start time of the range
1015 * @param time1
1016 * End time of the range
1017 * @param source
1018 * Source of the event
1019 */
1020 public void setSelectVisTimeWindow(long time0, long time1, Object source) {
1021 if (source == this) {
1022 return;
1023 }
1024
1025 setStartFinishTime(time0, time1);
1026
1027 // update notification time values since we are now in synch with the
1028 // external application
1029 updateExtSynchTimers();
1030 }
1031
1032 /**
1033 * update the cache timers used to identify the need to send a time window
1034 * update to external registered listeners
1035 */
1036 private void updateExtSynchTimers() {
1037 // last time notification cache
f1fae91f
PT
1038 fTime0ExtSynch = fTime0;
1039 fTime1ExtSynch = fTime1;
837a2f8c
PT
1040 }
1041
1042 /**
026664b7 1043 * @since 2.0
837a2f8c 1044 */
026664b7
XR
1045 @Override
1046 public TimeFormat getTimeFormat() {
f1fae91f 1047 return fTimeFormat;
837a2f8c
PT
1048 }
1049
026664b7 1050 /**
79ec0b89
PT
1051 * @param tf
1052 * the {@link TimeFormat} used to display timestamps
026664b7
XR
1053 * @since 2.0
1054 */
1055 public void setTimeFormat(TimeFormat tf) {
f1fae91f 1056 this.fTimeFormat = tf;
837a2f8c
PT
1057 }
1058
1059 /**
1060 * Retrieve the border width
1061 *
1062 * @return The width
1063 */
1064 public int getBorderWidth() {
f1fae91f 1065 return fBorderWidth;
837a2f8c
PT
1066 }
1067
1068 /**
1069 * Set the border width
1070 *
1071 * @param borderWidth
1072 * The width
1073 */
1074 public void setBorderWidth(int borderWidth) {
1075 if (borderWidth > -1) {
f1fae91f 1076 this.fBorderWidth = borderWidth;
79ec0b89 1077 GridLayout gl = (GridLayout) fDataViewer.getLayout();
837a2f8c
PT
1078 gl.marginHeight = borderWidth;
1079 }
1080 }
1081
1082 /**
1083 * Retrieve the height of the header
1084 *
1085 * @return The height
1086 */
1087 public int getHeaderHeight() {
f1fae91f 1088 return fTimeScaleHeight;
837a2f8c
PT
1089 }
1090
1091 /**
1092 * Set the height of the header
1093 *
1094 * @param headerHeight
1095 * The height to set
1096 */
1097 public void setHeaderHeight(int headerHeight) {
1098 if (headerHeight > -1) {
f1fae91f
PT
1099 this.fTimeScaleHeight = headerHeight;
1100 fTimeScaleCtrl.setHeight(headerHeight);
837a2f8c
PT
1101 }
1102 }
1103
1104 /**
1105 * Retrieve the height of an item row
1106 *
1107 * @return The height
1108 */
1109 public int getItemHeight() {
f1fae91f
PT
1110 if (fTimeGraphCtrl != null) {
1111 return fTimeGraphCtrl.getItemHeight();
837a2f8c
PT
1112 }
1113 return 0;
1114 }
1115
1116 /**
1117 * Set the height of an item row
1118 *
1119 * @param rowHeight
1120 * The height to set
1121 */
1122 public void setItemHeight(int rowHeight) {
f1fae91f
PT
1123 if (fTimeGraphCtrl != null) {
1124 fTimeGraphCtrl.setItemHeight(rowHeight);
837a2f8c
PT
1125 }
1126 }
1127
1128 /**
1129 * Set the minimum item width
1130 *
1131 * @param width
1132 * The min width
1133 */
1134 public void setMinimumItemWidth(int width) {
f1fae91f
PT
1135 if (fTimeGraphCtrl != null) {
1136 fTimeGraphCtrl.setMinimumItemWidth(width);
837a2f8c
PT
1137 }
1138 }
1139
1140 /**
1141 * Set the width for the name column
1142 *
79ec0b89
PT
1143 * @param width
1144 * The width
837a2f8c
PT
1145 */
1146 public void setNameWidthPref(int width) {
f1fae91f 1147 fNameWidthPref = width;
837a2f8c 1148 if (width == 0) {
f1fae91f
PT
1149 fMinNameWidth = 0;
1150 fNameWidth = 0;
837a2f8c
PT
1151 }
1152 }
1153
1154 /**
1155 * Retrieve the configure width for the name column
1156 *
1157 * @param width
1158 * Unused?
1159 * @return The width
1160 */
1161 public int getNameWidthPref(int width) {
f1fae91f 1162 return fNameWidthPref;
837a2f8c
PT
1163 }
1164
1165 /**
1166 * Returns the primary control associated with this viewer.
1167 *
1168 * @return the SWT control which displays this viewer's content
1169 */
1170 public Control getControl() {
f1fae91f 1171 return fDataViewer;
837a2f8c
PT
1172 }
1173
1174 /**
1175 * Returns the time graph control associated with this viewer.
1176 *
1177 * @return the time graph control
3e9a3685 1178 * @since 2.0
837a2f8c 1179 */
3e9a3685 1180 public TimeGraphControl getTimeGraphControl() {
f1fae91f 1181 return fTimeGraphCtrl;
837a2f8c
PT
1182 }
1183
1184 /**
1185 * Returns the time graph scale associated with this viewer.
1186 *
1187 * @return the time graph scale
3e9a3685 1188 * @since 2.0
837a2f8c 1189 */
3e9a3685 1190 public TimeGraphScale getTimeGraphScale() {
f1fae91f 1191 return fTimeScaleCtrl;
837a2f8c
PT
1192 }
1193
713a70ae
PT
1194 /**
1195 * Return the x coordinate corresponding to a time
1196 *
79ec0b89
PT
1197 * @param time
1198 * the time
713a70ae
PT
1199 * @return the x coordinate corresponding to the time
1200 *
1201 * @since 2.0
1202 */
1203 public int getXForTime(long time) {
f1fae91f 1204 return fTimeGraphCtrl.getXForTime(time);
713a70ae
PT
1205 }
1206
1207 /**
1208 * Return the time corresponding to an x coordinate
1209 *
79ec0b89
PT
1210 * @param x
1211 * the x coordinate
713a70ae
PT
1212 * @return the time corresponding to the x coordinate
1213 *
1214 * @since 2.0
1215 */
1216 public long getTimeAtX(int x) {
f1fae91f 1217 return fTimeGraphCtrl.getTimeAtX(x);
713a70ae
PT
1218 }
1219
837a2f8c
PT
1220 /**
1221 * Get the selection provider
1222 *
1223 * @return the selection provider
1224 */
1225 public ISelectionProvider getSelectionProvider() {
f1fae91f 1226 return fTimeGraphCtrl;
837a2f8c
PT
1227 }
1228
1229 /**
1230 * Wait for the cursor
1231 *
1232 * @param waitInd
1233 * Wait indefinitely?
1234 */
1235 public void waitCursor(boolean waitInd) {
f1fae91f 1236 fTimeGraphCtrl.waitCursor(waitInd);
837a2f8c
PT
1237 }
1238
1239 /**
1240 * Get the horizontal scroll bar object
1241 *
1242 * @return The scroll bar
1243 */
1244 public ScrollBar getHorizontalBar() {
f1fae91f 1245 return fTimeGraphCtrl.getHorizontalBar();
837a2f8c
PT
1246 }
1247
1248 /**
1249 * Get the vertical scroll bar object
1250 *
1251 * @return The scroll bar
1252 */
1253 public Slider getVerticalBar() {
f1fae91f 1254 return fVerticalScrollBar;
837a2f8c
PT
1255 }
1256
1257 /**
1258 * Set the given index as the top one
1259 *
1260 * @param index
1261 * The index that will go to the top
1262 */
1263 public void setTopIndex(int index) {
f1fae91f 1264 fTimeGraphCtrl.setTopIndex(index);
837a2f8c
PT
1265 adjustVerticalScrollBar();
1266 }
1267
1268 /**
1269 * Retrieve the current top index
1270 *
1271 * @return The top index
1272 */
1273 public int getTopIndex() {
f1fae91f 1274 return fTimeGraphCtrl.getTopIndex();
837a2f8c
PT
1275 }
1276
1277 /**
1278 * Set the expanded state of an entry
1279 *
1280 * @param entry
1281 * The entry to expand/collapse
1282 * @param expanded
1283 * True for expanded, false for collapsed
1284 */
1285 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
f1fae91f 1286 fTimeGraphCtrl.setExpandedState(entry, expanded);
837a2f8c
PT
1287 adjustVerticalScrollBar();
1288 }
1289
1290 /**
1291 * Collapses all nodes of the viewer's tree, starting with the root.
1292 *
1293 * @since 2.0
1294 */
1295 public void collapseAll() {
f1fae91f 1296 fTimeGraphCtrl.collapseAll();
837a2f8c
PT
1297 adjustVerticalScrollBar();
1298 }
1299
1300 /**
1301 * Expands all nodes of the viewer's tree, starting with the root.
1302 *
1303 * @since 2.0
1304 */
1305 public void expandAll() {
f1fae91f 1306 fTimeGraphCtrl.expandAll();
837a2f8c
PT
1307 adjustVerticalScrollBar();
1308 }
1309
1310 /**
1311 * Get the number of sub-elements when expanded
1312 *
1313 * @return The element count
1314 */
1315 public int getExpandedElementCount() {
f1fae91f 1316 return fTimeGraphCtrl.getExpandedElementCount();
837a2f8c
PT
1317 }
1318
1319 /**
1320 * Get the sub-elements
1321 *
1322 * @return The array of entries that are below this one
1323 */
1324 public ITimeGraphEntry[] getExpandedElements() {
f1fae91f 1325 return fTimeGraphCtrl.getExpandedElements();
837a2f8c
PT
1326 }
1327
1328 /**
1329 * Add a tree listener
1330 *
1331 * @param listener
1332 * The listener to add
1333 */
1334 public void addTreeListener(ITimeGraphTreeListener listener) {
f1fae91f 1335 fTimeGraphCtrl.addTreeListener(listener);
837a2f8c
PT
1336 }
1337
1338 /**
1339 * Remove a tree listener
1340 *
1341 * @param listener
1342 * The listener to remove
1343 */
1344 public void removeTreeListener(ITimeGraphTreeListener listener) {
f1fae91f 1345 fTimeGraphCtrl.removeTreeListener(listener);
837a2f8c
PT
1346 }
1347
1348 /**
1349 * Get the reset scale action.
1350 *
1351 * @return The Action object
1352 */
1353 public Action getResetScaleAction() {
f1fae91f 1354 if (fResetScaleAction == null) {
837a2f8c 1355 // resetScale
f1fae91f 1356 fResetScaleAction = new Action() {
837a2f8c
PT
1357 @Override
1358 public void run() {
1359 resetStartFinishTime();
894d6929 1360 notifyStartFinishTime();
837a2f8c
PT
1361 }
1362 };
f1fae91f
PT
1363 fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
1364 fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
1365 fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
837a2f8c 1366 }
f1fae91f 1367 return fResetScaleAction;
837a2f8c
PT
1368 }
1369
1370 /**
1371 * Get the show legend action.
1372 *
1373 * @return The Action object
1374 */
1375 public Action getShowLegendAction() {
f1fae91f 1376 if (fShowLegendAction == null) {
837a2f8c 1377 // showLegend
f1fae91f 1378 fShowLegendAction = new Action() {
837a2f8c
PT
1379 @Override
1380 public void run() {
1381 showLegend();
1382 }
1383 };
f1fae91f
PT
1384 fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
1385 fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
1386 fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
837a2f8c
PT
1387 }
1388
f1fae91f 1389 return fShowLegendAction;
837a2f8c
PT
1390 }
1391
1392 /**
1393 * Get the the next event action.
1394 *
1395 * @return The action object
1396 */
1397 public Action getNextEventAction() {
f1fae91f
PT
1398 if (fNextEventAction == null) {
1399 fNextEventAction = new Action() {
837a2f8c
PT
1400 @Override
1401 public void run() {
1402 selectNextEvent();
1403 }
1404 };
1405
f1fae91f
PT
1406 fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
1407 fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
1408 fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
837a2f8c
PT
1409 }
1410
f1fae91f 1411 return fNextEventAction;
837a2f8c
PT
1412 }
1413
1414 /**
1415 * Get the previous event action.
1416 *
1417 * @return The Action object
1418 */
1419 public Action getPreviousEventAction() {
f1fae91f
PT
1420 if (fPrevEventAction == null) {
1421 fPrevEventAction = new Action() {
837a2f8c
PT
1422 @Override
1423 public void run() {
1424 selectPrevEvent();
1425 }
1426 };
1427
f1fae91f
PT
1428 fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
1429 fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
1430 fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
837a2f8c
PT
1431 }
1432
f1fae91f 1433 return fPrevEventAction;
837a2f8c
PT
1434 }
1435
1436 /**
1437 * Get the next item action.
1438 *
1439 * @return The Action object
1440 */
1441 public Action getNextItemAction() {
f1fae91f 1442 if (fNextItemAction == null) {
837a2f8c 1443
f1fae91f 1444 fNextItemAction = new Action() {
837a2f8c
PT
1445 @Override
1446 public void run() {
1447 selectNextItem();
1448 }
1449 };
f1fae91f
PT
1450 fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
1451 fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
1452 fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
837a2f8c 1453 }
f1fae91f 1454 return fNextItemAction;
837a2f8c
PT
1455 }
1456
1457 /**
1458 * Get the previous item action.
1459 *
1460 * @return The Action object
1461 */
1462 public Action getPreviousItemAction() {
f1fae91f 1463 if (fPreviousItemAction == null) {
837a2f8c 1464
f1fae91f 1465 fPreviousItemAction = new Action() {
837a2f8c
PT
1466 @Override
1467 public void run() {
1468 selectPrevItem();
1469 }
1470 };
f1fae91f
PT
1471 fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
1472 fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
1473 fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
837a2f8c 1474 }
f1fae91f 1475 return fPreviousItemAction;
837a2f8c
PT
1476 }
1477
1478 /**
1479 * Get the zoom in action
1480 *
1481 * @return The Action object
1482 */
1483 public Action getZoomInAction() {
f1fae91f
PT
1484 if (fZoomInAction == null) {
1485 fZoomInAction = new Action() {
837a2f8c
PT
1486 @Override
1487 public void run() {
1488 zoomIn();
1489 }
1490 };
f1fae91f
PT
1491 fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
1492 fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
1493 fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
837a2f8c 1494 }
f1fae91f 1495 return fZoomInAction;
837a2f8c
PT
1496 }
1497
1498 /**
1499 * Get the zoom out action
1500 *
1501 * @return The Action object
1502 */
1503 public Action getZoomOutAction() {
f1fae91f
PT
1504 if (fZoomOutAction == null) {
1505 fZoomOutAction = new Action() {
837a2f8c
PT
1506 @Override
1507 public void run() {
1508 zoomOut();
1509 }
1510 };
f1fae91f
PT
1511 fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
1512 fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
1513 fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
837a2f8c 1514 }
f1fae91f 1515 return fZoomOutAction;
837a2f8c
PT
1516 }
1517
79ec0b89
PT
1518 /**
1519 * Get the hide arrows action
1520 *
1521 * @param dialogSettings
1522 * The dialog settings section where the state should be stored,
1523 * or null
1524 *
1525 * @return The Action object
1526 *
1527 * @since 2.1
1528 */
1529 public Action getHideArrowsAction(final IDialogSettings dialogSettings) {
1530 if (fHideArrowsAction == null) {
1531 fHideArrowsAction = new Action(Messages.TmfTimeGraphViewer_HideArrowsActionNameText, IAction.AS_CHECK_BOX) {
1532 @Override
1533 public void run() {
1534 boolean hideArrows = fHideArrowsAction.isChecked();
1535 fTimeGraphCtrl.hideArrows(hideArrows);
1536 refresh();
1537 if (dialogSettings != null) {
1538 dialogSettings.put(HIDE_ARROWS_KEY, hideArrows);
1539 }
086f21ae
PT
1540 if (fFollowArrowFwdAction != null) {
1541 fFollowArrowFwdAction.setEnabled(!hideArrows);
1542 }
1543 if (fFollowArrowBwdAction != null) {
1544 fFollowArrowBwdAction.setEnabled(!hideArrows);
1545 }
79ec0b89
PT
1546 }
1547 };
1548 fHideArrowsAction.setToolTipText(Messages.TmfTimeGraphViewer_HideArrowsActionToolTipText);
1549 fHideArrowsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HIDE_ARROWS));
1550 if (dialogSettings != null) {
1551 boolean hideArrows = dialogSettings.getBoolean(HIDE_ARROWS_KEY);
1552 fTimeGraphCtrl.hideArrows(hideArrows);
1553 fHideArrowsAction.setChecked(hideArrows);
086f21ae
PT
1554 if (fFollowArrowFwdAction != null) {
1555 fFollowArrowFwdAction.setEnabled(!hideArrows);
1556 }
1557 if (fFollowArrowBwdAction != null) {
1558 fFollowArrowBwdAction.setEnabled(!hideArrows);
1559 }
79ec0b89
PT
1560 }
1561 }
1562 return fHideArrowsAction;
1563 }
837a2f8c 1564
086f21ae
PT
1565 /**
1566 * Get the follow arrow forward action.
1567 *
1568 * @return The Action object
1569 *
1570 * @since 2.1
1571 */
1572 public Action getFollowArrowFwdAction() {
1573 if (fFollowArrowFwdAction == null) {
1574 fFollowArrowFwdAction = new Action() {
1575 @Override
1576 public void run() {
1577 fTimeGraphCtrl.followArrowFwd();
1578 adjustVerticalScrollBar();
1579 }
1580 };
1581 fFollowArrowFwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionNameText);
1582 fFollowArrowFwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText);
1583 fFollowArrowFwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_FORWARD));
1584 if (fHideArrowsAction != null) {
1585 fFollowArrowFwdAction.setEnabled(!fHideArrowsAction.isChecked());
1586 }
1587 }
1588 return fFollowArrowFwdAction;
1589 }
1590
1591 /**
1592 * Get the follow arrow backward action.
1593 *
1594 * @return The Action object
1595 *
1596 * @since 2.1
1597 */
1598 public Action getFollowArrowBwdAction() {
1599 if (fFollowArrowBwdAction == null) {
1600 fFollowArrowBwdAction = new Action() {
1601 @Override
1602 public void run() {
1603 fTimeGraphCtrl.followArrowBwd();
1604 adjustVerticalScrollBar();
1605 }
1606 };
1607 fFollowArrowBwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionNameText);
1608 fFollowArrowBwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText);
1609 fFollowArrowBwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_BACKWARD));
1610 if (fHideArrowsAction != null) {
1611 fFollowArrowBwdAction.setEnabled(!fHideArrowsAction.isChecked());
1612 }
1613 }
1614 return fFollowArrowBwdAction;
1615 }
1616
837a2f8c 1617 private void adjustVerticalScrollBar() {
f1fae91f
PT
1618 int topIndex = fTimeGraphCtrl.getTopIndex();
1619 int countPerPage = fTimeGraphCtrl.countPerPage();
1620 int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount();
837a2f8c 1621 if (topIndex + countPerPage > expandedElementCount) {
f1fae91f 1622 fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
837a2f8c
PT
1623 }
1624
f1fae91f 1625 int selection = fTimeGraphCtrl.getTopIndex();
837a2f8c
PT
1626 int min = 0;
1627 int max = Math.max(1, expandedElementCount - 1);
1628 int thumb = Math.min(max, Math.max(1, countPerPage - 1));
1629 int increment = 1;
1630 int pageIncrement = Math.max(1, countPerPage);
f1fae91f 1631 fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
837a2f8c
PT
1632 }
1633
27df1564 1634 /**
79ec0b89
PT
1635 * @param listener
1636 * a {@link MenuDetectListener}
27df1564 1637 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
77c4a6df 1638 * @since 1.2
27df1564
XR
1639 */
1640 public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
f1fae91f 1641 fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener);
27df1564
XR
1642 }
1643
1644 /**
79ec0b89
PT
1645 * @param listener
1646 * a {@link MenuDetectListener}
27df1564 1647 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
77c4a6df 1648 * @since 1.2
27df1564
XR
1649 */
1650 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
f1fae91f 1651 fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener);
27df1564
XR
1652 }
1653
1654 /**
79ec0b89
PT
1655 * @param listener
1656 * a {@link MenuDetectListener}
27df1564 1657 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
77c4a6df 1658 * @since 1.2
27df1564
XR
1659 */
1660 public void addTimeEventMenuListener(MenuDetectListener listener) {
f1fae91f 1661 fTimeGraphCtrl.addTimeEventMenuListener(listener);
27df1564
XR
1662 }
1663
1664 /**
79ec0b89
PT
1665 * @param listener
1666 * a {@link MenuDetectListener}
27df1564 1667 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
77c4a6df 1668 * @since 1.2
27df1564
XR
1669 */
1670 public void removeTimeEventMenuListener(MenuDetectListener listener) {
f1fae91f 1671 fTimeGraphCtrl.removeTimeEventMenuListener(listener);
27df1564
XR
1672 }
1673
6ac5a950 1674 /**
79ec0b89
PT
1675 * @param filter
1676 * The filter object to be attached to the view
6ac5a950
AM
1677 * @since 2.0
1678 */
1679 public void addFilter(ViewerFilter filter) {
f1fae91f 1680 fTimeGraphCtrl.addFilter(filter);
6ac5a950
AM
1681 refresh();
1682 }
837a2f8c 1683
6ac5a950 1684 /**
79ec0b89
PT
1685 * @param filter
1686 * The filter object to be attached to the view
6ac5a950
AM
1687 * @since 2.0
1688 */
1689 public void removeFilter(ViewerFilter filter) {
f1fae91f 1690 fTimeGraphCtrl.removeFilter(filter);
6ac5a950
AM
1691 refresh();
1692 }
837a2f8c
PT
1693
1694}
This page took 0.170054 seconds and 5 git commands to generate.