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