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