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