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); | |
758 | } | |
759 | ||
760 | private void setStartFinishTimeInt(long time0, long time1) { | |
f1fae91f PT |
761 | fTime0 = time0; |
762 | if (fTime0 < fTime0Bound) { | |
763 | fTime0 = fTime0Bound; | |
837a2f8c | 764 | } |
f1fae91f PT |
765 | if (fTime0 > fTime1Bound) { |
766 | fTime0 = fTime1Bound; | |
837a2f8c | 767 | } |
f1fae91f PT |
768 | fTime1 = time1; |
769 | if (fTime1 < fTime0Bound) { | |
770 | fTime1 = fTime0Bound; | |
837a2f8c | 771 | } |
f1fae91f PT |
772 | if (fTime1 > fTime1Bound) { |
773 | fTime1 = fTime1Bound; | |
837a2f8c | 774 | } |
f1fae91f PT |
775 | if (fTime1 - fTime0 < fMinTimeInterval) { |
776 | fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval); | |
837a2f8c | 777 | } |
f1fae91f | 778 | fTimeRangeFixed = true; |
b698ec63 | 779 | adjustHorizontalScrollBar(); |
f1fae91f PT |
780 | fTimeGraphCtrl.redraw(); |
781 | fTimeScaleCtrl.redraw(); | |
837a2f8c PT |
782 | } |
783 | ||
837a2f8c PT |
784 | @Override |
785 | public void resetStartFinishTime() { | |
88de10c6 | 786 | setStartFinishTimeNotify(fTime0Bound, fTime1Bound); |
f1fae91f | 787 | fTimeRangeFixed = false; |
837a2f8c PT |
788 | } |
789 | ||
790 | @Override | |
791 | public void setSelectedTimeNotify(long time, boolean ensureVisible) { | |
792 | setSelectedTimeInt(time, ensureVisible, true); | |
793 | } | |
794 | ||
795 | @Override | |
796 | public void setSelectedTime(long time, boolean ensureVisible) { | |
88de10c6 PT |
797 | /* if there is a pending time selection, ignore this one */ |
798 | if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) { | |
799 | return; | |
800 | } | |
837a2f8c PT |
801 | setSelectedTimeInt(time, ensureVisible, false); |
802 | } | |
803 | ||
0fcf3b09 PT |
804 | @Override |
805 | public void setSelectionRangeNotify(long beginTime, long endTime) { | |
33fa1fc7 PT |
806 | long time0 = fTime0; |
807 | long time1 = fTime1; | |
0fcf3b09 PT |
808 | boolean changed = (beginTime != fSelectionBegin || endTime != fSelectionEnd); |
809 | fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime)); | |
810 | fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime)); | |
33fa1fc7 | 811 | ensureVisible(fSelectionEnd); |
0fcf3b09 PT |
812 | fTimeGraphCtrl.redraw(); |
813 | fTimeScaleCtrl.redraw(); | |
33fa1fc7 PT |
814 | if ((time0 != fTime0) || (time1 != fTime1)) { |
815 | notifyRangeListeners(); | |
816 | } | |
0fcf3b09 | 817 | if (changed) { |
10ad9fa6 | 818 | notifyTimeListeners(); |
0fcf3b09 PT |
819 | } |
820 | } | |
821 | ||
0fcf3b09 PT |
822 | @Override |
823 | public void setSelectionRange(long beginTime, long endTime) { | |
88de10c6 PT |
824 | /* if there is a pending time selection, ignore this one */ |
825 | if (fListenerNotifier != null && fListenerNotifier.hasTimeSelected()) { | |
826 | return; | |
827 | } | |
0fcf3b09 PT |
828 | fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime)); |
829 | fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime)); | |
830 | fTimeGraphCtrl.redraw(); | |
831 | fTimeScaleCtrl.redraw(); | |
832 | } | |
833 | ||
837a2f8c | 834 | private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) { |
f1fae91f PT |
835 | long time0 = fTime0; |
836 | long time1 = fTime1; | |
837a2f8c | 837 | if (ensureVisible) { |
33fa1fc7 | 838 | ensureVisible(time); |
837a2f8c | 839 | } |
f1fae91f PT |
840 | fTimeGraphCtrl.redraw(); |
841 | fTimeScaleCtrl.redraw(); | |
837a2f8c | 842 | |
0fcf3b09 PT |
843 | boolean notifySelectedTime = (time != fSelectionBegin || time != fSelectionEnd); |
844 | fSelectionBegin = time; | |
845 | fSelectionEnd = time; | |
837a2f8c | 846 | |
f1fae91f | 847 | if (doNotify && ((time0 != fTime0) || (time1 != fTime1))) { |
10ad9fa6 | 848 | notifyRangeListeners(); |
837a2f8c PT |
849 | } |
850 | ||
851 | if (doNotify && notifySelectedTime) { | |
10ad9fa6 | 852 | notifyTimeListeners(); |
837a2f8c PT |
853 | } |
854 | } | |
855 | ||
33fa1fc7 PT |
856 | private void ensureVisible(long time) { |
857 | long timeMid = (fTime1 - fTime0) / 2; | |
858 | if (time < fTime0) { | |
859 | long dt = fTime0 - time + timeMid; | |
860 | fTime0 -= dt; | |
861 | fTime1 -= dt; | |
862 | } else if (time > fTime1) { | |
863 | long dt = time - fTime1 + timeMid; | |
864 | fTime0 += dt; | |
865 | fTime1 += dt; | |
866 | } | |
867 | if (fTime0 < fTime0Bound) { | |
868 | fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0)); | |
869 | fTime0 = fTime0Bound; | |
870 | } else if (fTime1 > fTime1Bound) { | |
871 | fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound)); | |
872 | fTime1 = fTime1Bound; | |
873 | } | |
874 | if (fTime1 - fTime0 < fMinTimeInterval) { | |
875 | fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval); | |
876 | } | |
877 | adjustHorizontalScrollBar(); | |
878 | } | |
879 | ||
837a2f8c PT |
880 | @Override |
881 | public void widgetDefaultSelected(SelectionEvent e) { | |
f1fae91f PT |
882 | if (fSelectedEntry != getSelection()) { |
883 | fSelectedEntry = getSelection(); | |
10ad9fa6 | 884 | notifySelectionListeners(); |
837a2f8c PT |
885 | } |
886 | } | |
887 | ||
888 | @Override | |
889 | public void widgetSelected(SelectionEvent e) { | |
f1fae91f PT |
890 | if (fSelectedEntry != getSelection()) { |
891 | fSelectedEntry = getSelection(); | |
10ad9fa6 | 892 | notifySelectionListeners(); |
837a2f8c PT |
893 | } |
894 | } | |
895 | ||
896 | /** | |
897 | * Callback for when the next event is selected | |
33fa1fc7 PT |
898 | * |
899 | * @param extend | |
900 | * true to extend selection range, false for single selection | |
901 | * @since 1.0 | |
837a2f8c | 902 | */ |
33fa1fc7 PT |
903 | public void selectNextEvent(boolean extend) { |
904 | fTimeGraphCtrl.selectNextEvent(extend); | |
837a2f8c PT |
905 | adjustVerticalScrollBar(); |
906 | } | |
907 | ||
908 | /** | |
909 | * Callback for when the previous event is selected | |
33fa1fc7 PT |
910 | * |
911 | * @param extend | |
912 | * true to extend selection range, false for single selection | |
913 | * @since 1.0 | |
837a2f8c | 914 | */ |
33fa1fc7 PT |
915 | public void selectPrevEvent(boolean extend) { |
916 | fTimeGraphCtrl.selectPrevEvent(extend); | |
837a2f8c PT |
917 | adjustVerticalScrollBar(); |
918 | } | |
919 | ||
920 | /** | |
921 | * Callback for when the next item is selected | |
922 | */ | |
923 | public void selectNextItem() { | |
f1fae91f | 924 | fTimeGraphCtrl.selectNextTrace(); |
837a2f8c PT |
925 | adjustVerticalScrollBar(); |
926 | } | |
927 | ||
928 | /** | |
929 | * Callback for when the previous item is selected | |
930 | */ | |
931 | public void selectPrevItem() { | |
f1fae91f | 932 | fTimeGraphCtrl.selectPrevTrace(); |
837a2f8c PT |
933 | adjustVerticalScrollBar(); |
934 | } | |
935 | ||
936 | /** | |
937 | * Callback for the show legend action | |
938 | */ | |
939 | public void showLegend() { | |
f1fae91f | 940 | if (fDataViewer == null || fDataViewer.isDisposed()) { |
837a2f8c PT |
941 | return; |
942 | } | |
943 | ||
f1fae91f | 944 | TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider); |
837a2f8c PT |
945 | } |
946 | ||
947 | /** | |
948 | * Callback for the Zoom In action | |
949 | */ | |
950 | public void zoomIn() { | |
f1fae91f | 951 | fTimeGraphCtrl.zoomIn(); |
837a2f8c PT |
952 | } |
953 | ||
954 | /** | |
955 | * Callback for the Zoom Out action | |
956 | */ | |
957 | public void zoomOut() { | |
f1fae91f | 958 | fTimeGraphCtrl.zoomOut(); |
837a2f8c PT |
959 | } |
960 | ||
961 | private String getPreferenceString(String string) { | |
962 | return getViewTypeStr() + "." + string; //$NON-NLS-1$ | |
963 | } | |
964 | ||
965 | /** | |
966 | * Add a selection listener | |
967 | * | |
968 | * @param listener | |
969 | * The listener to add | |
970 | */ | |
971 | public void addSelectionListener(ITimeGraphSelectionListener listener) { | |
972 | fSelectionListeners.add(listener); | |
973 | } | |
974 | ||
975 | /** | |
976 | * Remove a selection listener | |
977 | * | |
978 | * @param listener | |
979 | * The listener to remove | |
980 | */ | |
981 | public void removeSelectionListener(ITimeGraphSelectionListener listener) { | |
982 | fSelectionListeners.remove(listener); | |
983 | } | |
984 | ||
10ad9fa6 | 985 | private void notifySelectionListeners() { |
88de10c6 PT |
986 | if (fListenerNotifier == null) { |
987 | fListenerNotifier = new ListenerNotifier(); | |
988 | fListenerNotifier.start(); | |
10ad9fa6 | 989 | } |
88de10c6 | 990 | fListenerNotifier.selectionChanged(); |
10ad9fa6 PT |
991 | } |
992 | ||
993 | private void fireSelectionChanged(ITimeGraphEntry selection) { | |
837a2f8c PT |
994 | TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection); |
995 | ||
996 | for (ITimeGraphSelectionListener listener : fSelectionListeners) { | |
997 | listener.selectionChanged(event); | |
998 | } | |
999 | } | |
1000 | ||
1001 | /** | |
1002 | * Add a time listener | |
1003 | * | |
1004 | * @param listener | |
1005 | * The listener to add | |
1006 | */ | |
1007 | public void addTimeListener(ITimeGraphTimeListener listener) { | |
1008 | fTimeListeners.add(listener); | |
1009 | } | |
1010 | ||
1011 | /** | |
1012 | * Remove a time listener | |
1013 | * | |
1014 | * @param listener | |
1015 | * The listener to remove | |
1016 | */ | |
1017 | public void removeTimeListener(ITimeGraphTimeListener listener) { | |
1018 | fTimeListeners.remove(listener); | |
1019 | } | |
1020 | ||
10ad9fa6 | 1021 | private void notifyTimeListeners() { |
88de10c6 PT |
1022 | if (fListenerNotifier == null) { |
1023 | fListenerNotifier = new ListenerNotifier(); | |
1024 | fListenerNotifier.start(); | |
10ad9fa6 | 1025 | } |
88de10c6 | 1026 | fListenerNotifier.timeSelected(); |
10ad9fa6 PT |
1027 | } |
1028 | ||
1029 | private void fireTimeSelected(long startTime, long endTime) { | |
0fcf3b09 | 1030 | TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime); |
837a2f8c PT |
1031 | |
1032 | for (ITimeGraphTimeListener listener : fTimeListeners) { | |
1033 | listener.timeSelected(event); | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | /** | |
1038 | * Add a range listener | |
1039 | * | |
1040 | * @param listener | |
1041 | * The listener to add | |
1042 | */ | |
1043 | public void addRangeListener(ITimeGraphRangeListener listener) { | |
1044 | fRangeListeners.add(listener); | |
1045 | } | |
1046 | ||
1047 | /** | |
1048 | * Remove a range listener | |
1049 | * | |
1050 | * @param listener | |
1051 | * The listener to remove | |
1052 | */ | |
1053 | public void removeRangeListener(ITimeGraphRangeListener listener) { | |
1054 | fRangeListeners.remove(listener); | |
1055 | } | |
1056 | ||
10ad9fa6 | 1057 | private void notifyRangeListeners() { |
88de10c6 PT |
1058 | if (fListenerNotifier == null) { |
1059 | fListenerNotifier = new ListenerNotifier(); | |
1060 | fListenerNotifier.start(); | |
10ad9fa6 | 1061 | } |
88de10c6 | 1062 | fListenerNotifier.timeRangeUpdated(); |
10ad9fa6 PT |
1063 | } |
1064 | ||
1065 | private void fireTimeRangeUpdated(long startTime, long endTime) { | |
837a2f8c | 1066 | // Check if the time has actually changed from last notification |
f1fae91f | 1067 | if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) { |
837a2f8c PT |
1068 | // Notify Time Scale Selection Listeners |
1069 | TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime); | |
1070 | ||
1071 | for (ITimeGraphRangeListener listener : fRangeListeners) { | |
1072 | listener.timeRangeUpdated(event); | |
1073 | } | |
1074 | ||
1075 | // update external synch timers | |
1076 | updateExtSynchTimers(); | |
1077 | } | |
1078 | } | |
1079 | ||
1080 | /** | |
1081 | * Callback to set a selected event in the view | |
1082 | * | |
1083 | * @param event | |
1084 | * The event that was selected | |
1085 | * @param source | |
1086 | * The source of this selection event | |
1087 | */ | |
1088 | public void setSelectedEvent(ITimeEvent event, Object source) { | |
1089 | if (event == null || source == this) { | |
1090 | return; | |
1091 | } | |
f1fae91f PT |
1092 | fSelectedEntry = event.getEntry(); |
1093 | fTimeGraphCtrl.selectItem(fSelectedEntry, false); | |
837a2f8c PT |
1094 | |
1095 | setSelectedTimeInt(event.getTime(), true, true); | |
1096 | adjustVerticalScrollBar(); | |
1097 | } | |
1098 | ||
1099 | /** | |
1100 | * Set the seeked time of a trace | |
1101 | * | |
1102 | * @param trace | |
1103 | * The trace that was seeked | |
1104 | * @param time | |
1105 | * The target time | |
1106 | * @param source | |
1107 | * The source of this seek event | |
1108 | */ | |
1109 | public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) { | |
1110 | if (trace == null || source == this) { | |
1111 | return; | |
1112 | } | |
f1fae91f PT |
1113 | fSelectedEntry = trace; |
1114 | fTimeGraphCtrl.selectItem(trace, false); | |
837a2f8c PT |
1115 | |
1116 | setSelectedTimeInt(time, true, true); | |
1117 | } | |
1118 | ||
1119 | /** | |
1120 | * Callback for a trace selection | |
1121 | * | |
1122 | * @param trace | |
1123 | * The trace that was selected | |
1124 | */ | |
1125 | public void setSelection(ITimeGraphEntry trace) { | |
88de10c6 PT |
1126 | /* if there is a pending selection, ignore this one */ |
1127 | if (fListenerNotifier != null && fListenerNotifier.hasSelectionChanged()) { | |
1128 | return; | |
1129 | } | |
f1fae91f PT |
1130 | fSelectedEntry = trace; |
1131 | fTimeGraphCtrl.selectItem(trace, false); | |
837a2f8c PT |
1132 | adjustVerticalScrollBar(); |
1133 | } | |
1134 | ||
1135 | /** | |
1136 | * Callback for a time window selection | |
1137 | * | |
1138 | * @param time0 | |
1139 | * Start time of the range | |
1140 | * @param time1 | |
1141 | * End time of the range | |
1142 | * @param source | |
1143 | * Source of the event | |
1144 | */ | |
1145 | public void setSelectVisTimeWindow(long time0, long time1, Object source) { | |
1146 | if (source == this) { | |
1147 | return; | |
1148 | } | |
1149 | ||
88de10c6 | 1150 | setStartFinishTimeInt(time0, time1); |
837a2f8c PT |
1151 | |
1152 | // update notification time values since we are now in synch with the | |
1153 | // external application | |
1154 | updateExtSynchTimers(); | |
1155 | } | |
1156 | ||
1157 | /** | |
1158 | * update the cache timers used to identify the need to send a time window | |
1159 | * update to external registered listeners | |
1160 | */ | |
1161 | private void updateExtSynchTimers() { | |
1162 | // last time notification cache | |
f1fae91f PT |
1163 | fTime0ExtSynch = fTime0; |
1164 | fTime1ExtSynch = fTime1; | |
837a2f8c PT |
1165 | } |
1166 | ||
026664b7 XR |
1167 | @Override |
1168 | public TimeFormat getTimeFormat() { | |
f1fae91f | 1169 | return fTimeFormat; |
837a2f8c PT |
1170 | } |
1171 | ||
026664b7 | 1172 | /** |
79ec0b89 PT |
1173 | * @param tf |
1174 | * the {@link TimeFormat} used to display timestamps | |
026664b7 XR |
1175 | */ |
1176 | public void setTimeFormat(TimeFormat tf) { | |
f1fae91f | 1177 | this.fTimeFormat = tf; |
0fab12b0 PT |
1178 | if (tf == TimeFormat.CYCLES) { |
1179 | fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency); | |
1180 | } else { | |
1181 | fTimeDataProvider = this; | |
1182 | } | |
1183 | fTimeScaleCtrl.setTimeProvider(fTimeDataProvider); | |
1184 | if (fToolTipHandler != null) { | |
1185 | fToolTipHandler.setTimeProvider(fTimeDataProvider); | |
1186 | } | |
1187 | } | |
1188 | ||
1189 | /** | |
1190 | * Sets the clock frequency. Used when the time format is set to CYCLES. | |
1191 | * | |
1192 | * @param clockFrequency | |
1193 | * the clock frequency in Hz | |
0fab12b0 PT |
1194 | */ |
1195 | public void setClockFrequency(long clockFrequency) { | |
1196 | fClockFrequency = clockFrequency; | |
1197 | if (fTimeFormat == TimeFormat.CYCLES) { | |
1198 | fTimeDataProvider = new TimeDataProviderCyclesConverter(this, fClockFrequency); | |
1199 | fTimeScaleCtrl.setTimeProvider(fTimeDataProvider); | |
1200 | if (fToolTipHandler != null) { | |
1201 | fToolTipHandler.setTimeProvider(fTimeDataProvider); | |
1202 | } | |
1203 | } | |
837a2f8c PT |
1204 | } |
1205 | ||
1206 | /** | |
1207 | * Retrieve the border width | |
1208 | * | |
1209 | * @return The width | |
1210 | */ | |
1211 | public int getBorderWidth() { | |
f1fae91f | 1212 | return fBorderWidth; |
837a2f8c PT |
1213 | } |
1214 | ||
1215 | /** | |
1216 | * Set the border width | |
1217 | * | |
1218 | * @param borderWidth | |
1219 | * The width | |
1220 | */ | |
1221 | public void setBorderWidth(int borderWidth) { | |
1222 | if (borderWidth > -1) { | |
f1fae91f | 1223 | this.fBorderWidth = borderWidth; |
79ec0b89 | 1224 | GridLayout gl = (GridLayout) fDataViewer.getLayout(); |
837a2f8c PT |
1225 | gl.marginHeight = borderWidth; |
1226 | } | |
1227 | } | |
1228 | ||
1229 | /** | |
1230 | * Retrieve the height of the header | |
1231 | * | |
1232 | * @return The height | |
1233 | */ | |
1234 | public int getHeaderHeight() { | |
f1fae91f | 1235 | return fTimeScaleHeight; |
837a2f8c PT |
1236 | } |
1237 | ||
1238 | /** | |
1239 | * Set the height of the header | |
1240 | * | |
1241 | * @param headerHeight | |
1242 | * The height to set | |
1243 | */ | |
1244 | public void setHeaderHeight(int headerHeight) { | |
1245 | if (headerHeight > -1) { | |
f1fae91f PT |
1246 | this.fTimeScaleHeight = headerHeight; |
1247 | fTimeScaleCtrl.setHeight(headerHeight); | |
837a2f8c PT |
1248 | } |
1249 | } | |
1250 | ||
1251 | /** | |
1252 | * Retrieve the height of an item row | |
1253 | * | |
1254 | * @return The height | |
1255 | */ | |
1256 | public int getItemHeight() { | |
f1fae91f PT |
1257 | if (fTimeGraphCtrl != null) { |
1258 | return fTimeGraphCtrl.getItemHeight(); | |
837a2f8c PT |
1259 | } |
1260 | return 0; | |
1261 | } | |
1262 | ||
1263 | /** | |
1264 | * Set the height of an item row | |
1265 | * | |
1266 | * @param rowHeight | |
1267 | * The height to set | |
1268 | */ | |
1269 | public void setItemHeight(int rowHeight) { | |
f1fae91f PT |
1270 | if (fTimeGraphCtrl != null) { |
1271 | fTimeGraphCtrl.setItemHeight(rowHeight); | |
837a2f8c PT |
1272 | } |
1273 | } | |
1274 | ||
1275 | /** | |
1276 | * Set the minimum item width | |
1277 | * | |
1278 | * @param width | |
1279 | * The min width | |
1280 | */ | |
1281 | public void setMinimumItemWidth(int width) { | |
f1fae91f PT |
1282 | if (fTimeGraphCtrl != null) { |
1283 | fTimeGraphCtrl.setMinimumItemWidth(width); | |
837a2f8c PT |
1284 | } |
1285 | } | |
1286 | ||
1287 | /** | |
1288 | * Set the width for the name column | |
1289 | * | |
79ec0b89 PT |
1290 | * @param width |
1291 | * The width | |
837a2f8c PT |
1292 | */ |
1293 | public void setNameWidthPref(int width) { | |
f1fae91f | 1294 | fNameWidthPref = width; |
837a2f8c | 1295 | if (width == 0) { |
f1fae91f PT |
1296 | fMinNameWidth = 0; |
1297 | fNameWidth = 0; | |
837a2f8c PT |
1298 | } |
1299 | } | |
1300 | ||
1301 | /** | |
1302 | * Retrieve the configure width for the name column | |
1303 | * | |
1304 | * @param width | |
1305 | * Unused? | |
1306 | * @return The width | |
1307 | */ | |
1308 | public int getNameWidthPref(int width) { | |
f1fae91f | 1309 | return fNameWidthPref; |
837a2f8c PT |
1310 | } |
1311 | ||
1312 | /** | |
1313 | * Returns the primary control associated with this viewer. | |
1314 | * | |
1315 | * @return the SWT control which displays this viewer's content | |
1316 | */ | |
1317 | public Control getControl() { | |
f1fae91f | 1318 | return fDataViewer; |
837a2f8c PT |
1319 | } |
1320 | ||
1321 | /** | |
1322 | * Returns the time graph control associated with this viewer. | |
1323 | * | |
1324 | * @return the time graph control | |
1325 | */ | |
3e9a3685 | 1326 | public TimeGraphControl getTimeGraphControl() { |
f1fae91f | 1327 | return fTimeGraphCtrl; |
837a2f8c PT |
1328 | } |
1329 | ||
1330 | /** | |
1331 | * Returns the time graph scale associated with this viewer. | |
1332 | * | |
1333 | * @return the time graph scale | |
1334 | */ | |
3e9a3685 | 1335 | public TimeGraphScale getTimeGraphScale() { |
f1fae91f | 1336 | return fTimeScaleCtrl; |
837a2f8c PT |
1337 | } |
1338 | ||
d2e4afa7 MAL |
1339 | /** |
1340 | * Returns the composite containing all the controls that are time aligned, | |
1341 | * i.e. TimeGraphScale, TimeGraphControl. | |
1342 | * | |
1343 | * @return the time based composite | |
1344 | * @since 1.0 | |
1345 | */ | |
1346 | public Composite getTimeAlignedComposite() { | |
1347 | return fTimeAlignedComposite; | |
1348 | } | |
1349 | ||
713a70ae PT |
1350 | /** |
1351 | * Return the x coordinate corresponding to a time | |
1352 | * | |
79ec0b89 PT |
1353 | * @param time |
1354 | * the time | |
713a70ae | 1355 | * @return the x coordinate corresponding to the time |
713a70ae PT |
1356 | */ |
1357 | public int getXForTime(long time) { | |
f1fae91f | 1358 | return fTimeGraphCtrl.getXForTime(time); |
713a70ae PT |
1359 | } |
1360 | ||
1361 | /** | |
1362 | * Return the time corresponding to an x coordinate | |
1363 | * | |
79ec0b89 PT |
1364 | * @param x |
1365 | * the x coordinate | |
713a70ae | 1366 | * @return the time corresponding to the x coordinate |
713a70ae PT |
1367 | */ |
1368 | public long getTimeAtX(int x) { | |
f1fae91f | 1369 | return fTimeGraphCtrl.getTimeAtX(x); |
713a70ae PT |
1370 | } |
1371 | ||
837a2f8c PT |
1372 | /** |
1373 | * Get the selection provider | |
1374 | * | |
1375 | * @return the selection provider | |
1376 | */ | |
1377 | public ISelectionProvider getSelectionProvider() { | |
f1fae91f | 1378 | return fTimeGraphCtrl; |
837a2f8c PT |
1379 | } |
1380 | ||
1381 | /** | |
1382 | * Wait for the cursor | |
1383 | * | |
1384 | * @param waitInd | |
1385 | * Wait indefinitely? | |
1386 | */ | |
1387 | public void waitCursor(boolean waitInd) { | |
f1fae91f | 1388 | fTimeGraphCtrl.waitCursor(waitInd); |
837a2f8c PT |
1389 | } |
1390 | ||
1391 | /** | |
1392 | * Get the horizontal scroll bar object | |
1393 | * | |
1394 | * @return The scroll bar | |
1395 | */ | |
b698ec63 PT |
1396 | public Slider getHorizontalBar() { |
1397 | return fHorizontalScrollBar; | |
837a2f8c PT |
1398 | } |
1399 | ||
1400 | /** | |
1401 | * Get the vertical scroll bar object | |
1402 | * | |
1403 | * @return The scroll bar | |
1404 | */ | |
1405 | public Slider getVerticalBar() { | |
f1fae91f | 1406 | return fVerticalScrollBar; |
837a2f8c PT |
1407 | } |
1408 | ||
1409 | /** | |
1410 | * Set the given index as the top one | |
1411 | * | |
1412 | * @param index | |
1413 | * The index that will go to the top | |
1414 | */ | |
1415 | public void setTopIndex(int index) { | |
f1fae91f | 1416 | fTimeGraphCtrl.setTopIndex(index); |
837a2f8c PT |
1417 | adjustVerticalScrollBar(); |
1418 | } | |
1419 | ||
1420 | /** | |
1421 | * Retrieve the current top index | |
1422 | * | |
1423 | * @return The top index | |
1424 | */ | |
1425 | public int getTopIndex() { | |
f1fae91f | 1426 | return fTimeGraphCtrl.getTopIndex(); |
837a2f8c PT |
1427 | } |
1428 | ||
f4617471 PT |
1429 | /** |
1430 | * Sets the auto-expand level to be used when the input of the viewer is set | |
1431 | * using {@link #setInput(Object)}. The value 0 means that there is no | |
1432 | * auto-expand; 1 means that top-level elements are expanded, but not their | |
1433 | * children; 2 means that top-level elements are expanded, and their | |
1434 | * children, but not grand-children; and so on. | |
1435 | * <p> | |
1436 | * The value {@link #ALL_LEVELS} means that all subtrees should be expanded. | |
1437 | * </p> | |
1438 | * @param level | |
1439 | * non-negative level, or <code>ALL_LEVELS</code> to expand all | |
1440 | * levels of the tree | |
f4617471 PT |
1441 | */ |
1442 | public void setAutoExpandLevel(int level) { | |
1443 | fTimeGraphCtrl.setAutoExpandLevel(level); | |
1444 | } | |
1445 | ||
1446 | /** | |
1447 | * Returns the auto-expand level. | |
1448 | * | |
1449 | * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of | |
1450 | * the tree are expanded automatically | |
1451 | * @see #setAutoExpandLevel | |
f4617471 PT |
1452 | */ |
1453 | public int getAutoExpandLevel() { | |
1454 | return fTimeGraphCtrl.getAutoExpandLevel(); | |
1455 | } | |
1456 | ||
837a2f8c PT |
1457 | /** |
1458 | * Set the expanded state of an entry | |
1459 | * | |
1460 | * @param entry | |
1461 | * The entry to expand/collapse | |
1462 | * @param expanded | |
1463 | * True for expanded, false for collapsed | |
1464 | */ | |
1465 | public void setExpandedState(ITimeGraphEntry entry, boolean expanded) { | |
f1fae91f | 1466 | fTimeGraphCtrl.setExpandedState(entry, expanded); |
837a2f8c PT |
1467 | adjustVerticalScrollBar(); |
1468 | } | |
1469 | ||
1470 | /** | |
1471 | * Collapses all nodes of the viewer's tree, starting with the root. | |
837a2f8c PT |
1472 | */ |
1473 | public void collapseAll() { | |
f1fae91f | 1474 | fTimeGraphCtrl.collapseAll(); |
837a2f8c PT |
1475 | adjustVerticalScrollBar(); |
1476 | } | |
1477 | ||
1478 | /** | |
1479 | * Expands all nodes of the viewer's tree, starting with the root. | |
837a2f8c PT |
1480 | */ |
1481 | public void expandAll() { | |
f1fae91f | 1482 | fTimeGraphCtrl.expandAll(); |
837a2f8c PT |
1483 | adjustVerticalScrollBar(); |
1484 | } | |
1485 | ||
1486 | /** | |
1487 | * Get the number of sub-elements when expanded | |
1488 | * | |
1489 | * @return The element count | |
1490 | */ | |
1491 | public int getExpandedElementCount() { | |
f1fae91f | 1492 | return fTimeGraphCtrl.getExpandedElementCount(); |
837a2f8c PT |
1493 | } |
1494 | ||
1495 | /** | |
1496 | * Get the sub-elements | |
1497 | * | |
1498 | * @return The array of entries that are below this one | |
1499 | */ | |
1500 | public ITimeGraphEntry[] getExpandedElements() { | |
f1fae91f | 1501 | return fTimeGraphCtrl.getExpandedElements(); |
837a2f8c PT |
1502 | } |
1503 | ||
1504 | /** | |
1505 | * Add a tree listener | |
1506 | * | |
1507 | * @param listener | |
1508 | * The listener to add | |
1509 | */ | |
1510 | public void addTreeListener(ITimeGraphTreeListener listener) { | |
f1fae91f | 1511 | fTimeGraphCtrl.addTreeListener(listener); |
837a2f8c PT |
1512 | } |
1513 | ||
1514 | /** | |
1515 | * Remove a tree listener | |
1516 | * | |
1517 | * @param listener | |
1518 | * The listener to remove | |
1519 | */ | |
1520 | public void removeTreeListener(ITimeGraphTreeListener listener) { | |
f1fae91f | 1521 | fTimeGraphCtrl.removeTreeListener(listener); |
837a2f8c PT |
1522 | } |
1523 | ||
1524 | /** | |
1525 | * Get the reset scale action. | |
1526 | * | |
1527 | * @return The Action object | |
1528 | */ | |
1529 | public Action getResetScaleAction() { | |
f1fae91f | 1530 | if (fResetScaleAction == null) { |
837a2f8c | 1531 | // resetScale |
f1fae91f | 1532 | fResetScaleAction = new Action() { |
837a2f8c PT |
1533 | @Override |
1534 | public void run() { | |
1535 | resetStartFinishTime(); | |
1536 | } | |
1537 | }; | |
f1fae91f PT |
1538 | fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText); |
1539 | fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText); | |
1540 | fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU)); | |
837a2f8c | 1541 | } |
f1fae91f | 1542 | return fResetScaleAction; |
837a2f8c PT |
1543 | } |
1544 | ||
1545 | /** | |
1546 | * Get the show legend action. | |
1547 | * | |
1548 | * @return The Action object | |
1549 | */ | |
1550 | public Action getShowLegendAction() { | |
f1fae91f | 1551 | if (fShowLegendAction == null) { |
837a2f8c | 1552 | // showLegend |
f1fae91f | 1553 | fShowLegendAction = new Action() { |
837a2f8c PT |
1554 | @Override |
1555 | public void run() { | |
1556 | showLegend(); | |
1557 | } | |
1558 | }; | |
f1fae91f PT |
1559 | fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText); |
1560 | fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText); | |
1561 | fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND)); | |
837a2f8c PT |
1562 | } |
1563 | ||
f1fae91f | 1564 | return fShowLegendAction; |
837a2f8c PT |
1565 | } |
1566 | ||
1567 | /** | |
1568 | * Get the the next event action. | |
1569 | * | |
1570 | * @return The action object | |
1571 | */ | |
1572 | public Action getNextEventAction() { | |
f1fae91f PT |
1573 | if (fNextEventAction == null) { |
1574 | fNextEventAction = new Action() { | |
837a2f8c | 1575 | @Override |
33fa1fc7 PT |
1576 | public void runWithEvent(Event event) { |
1577 | boolean extend = (event.stateMask & SWT.SHIFT) != 0; | |
1578 | selectNextEvent(extend); | |
837a2f8c PT |
1579 | } |
1580 | }; | |
1581 | ||
f1fae91f PT |
1582 | fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText); |
1583 | fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText); | |
1584 | fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT)); | |
837a2f8c PT |
1585 | } |
1586 | ||
f1fae91f | 1587 | return fNextEventAction; |
837a2f8c PT |
1588 | } |
1589 | ||
1590 | /** | |
1591 | * Get the previous event action. | |
1592 | * | |
1593 | * @return The Action object | |
1594 | */ | |
1595 | public Action getPreviousEventAction() { | |
f1fae91f PT |
1596 | if (fPrevEventAction == null) { |
1597 | fPrevEventAction = new Action() { | |
837a2f8c | 1598 | @Override |
33fa1fc7 PT |
1599 | public void runWithEvent(Event event) { |
1600 | boolean extend = (event.stateMask & SWT.SHIFT) != 0; | |
1601 | selectPrevEvent(extend); | |
837a2f8c PT |
1602 | } |
1603 | }; | |
1604 | ||
f1fae91f PT |
1605 | fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText); |
1606 | fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText); | |
1607 | fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT)); | |
837a2f8c PT |
1608 | } |
1609 | ||
f1fae91f | 1610 | return fPrevEventAction; |
837a2f8c PT |
1611 | } |
1612 | ||
1613 | /** | |
1614 | * Get the next item action. | |
1615 | * | |
1616 | * @return The Action object | |
1617 | */ | |
1618 | public Action getNextItemAction() { | |
f1fae91f | 1619 | if (fNextItemAction == null) { |
837a2f8c | 1620 | |
f1fae91f | 1621 | fNextItemAction = new Action() { |
837a2f8c PT |
1622 | @Override |
1623 | public void run() { | |
1624 | selectNextItem(); | |
1625 | } | |
1626 | }; | |
f1fae91f PT |
1627 | fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText); |
1628 | fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText); | |
1629 | fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM)); | |
837a2f8c | 1630 | } |
f1fae91f | 1631 | return fNextItemAction; |
837a2f8c PT |
1632 | } |
1633 | ||
1634 | /** | |
1635 | * Get the previous item action. | |
1636 | * | |
1637 | * @return The Action object | |
1638 | */ | |
1639 | public Action getPreviousItemAction() { | |
f1fae91f | 1640 | if (fPreviousItemAction == null) { |
837a2f8c | 1641 | |
f1fae91f | 1642 | fPreviousItemAction = new Action() { |
837a2f8c PT |
1643 | @Override |
1644 | public void run() { | |
1645 | selectPrevItem(); | |
1646 | } | |
1647 | }; | |
f1fae91f PT |
1648 | fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText); |
1649 | fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText); | |
1650 | fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM)); | |
837a2f8c | 1651 | } |
f1fae91f | 1652 | return fPreviousItemAction; |
837a2f8c PT |
1653 | } |
1654 | ||
1655 | /** | |
1656 | * Get the zoom in action | |
1657 | * | |
1658 | * @return The Action object | |
1659 | */ | |
1660 | public Action getZoomInAction() { | |
f1fae91f PT |
1661 | if (fZoomInAction == null) { |
1662 | fZoomInAction = new Action() { | |
837a2f8c PT |
1663 | @Override |
1664 | public void run() { | |
1665 | zoomIn(); | |
1666 | } | |
1667 | }; | |
f1fae91f PT |
1668 | fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText); |
1669 | fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText); | |
1670 | fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU)); | |
837a2f8c | 1671 | } |
f1fae91f | 1672 | return fZoomInAction; |
837a2f8c PT |
1673 | } |
1674 | ||
1675 | /** | |
1676 | * Get the zoom out action | |
1677 | * | |
1678 | * @return The Action object | |
1679 | */ | |
1680 | public Action getZoomOutAction() { | |
f1fae91f PT |
1681 | if (fZoomOutAction == null) { |
1682 | fZoomOutAction = new Action() { | |
837a2f8c PT |
1683 | @Override |
1684 | public void run() { | |
1685 | zoomOut(); | |
1686 | } | |
1687 | }; | |
f1fae91f PT |
1688 | fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText); |
1689 | fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText); | |
1690 | fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU)); | |
837a2f8c | 1691 | } |
f1fae91f | 1692 | return fZoomOutAction; |
837a2f8c PT |
1693 | } |
1694 | ||
79ec0b89 PT |
1695 | /** |
1696 | * Get the hide arrows action | |
1697 | * | |
1698 | * @param dialogSettings | |
1699 | * The dialog settings section where the state should be stored, | |
1700 | * or null | |
1701 | * | |
1702 | * @return The Action object | |
79ec0b89 PT |
1703 | */ |
1704 | public Action getHideArrowsAction(final IDialogSettings dialogSettings) { | |
1705 | if (fHideArrowsAction == null) { | |
1706 | fHideArrowsAction = new Action(Messages.TmfTimeGraphViewer_HideArrowsActionNameText, IAction.AS_CHECK_BOX) { | |
1707 | @Override | |
1708 | public void run() { | |
1709 | boolean hideArrows = fHideArrowsAction.isChecked(); | |
1710 | fTimeGraphCtrl.hideArrows(hideArrows); | |
1711 | refresh(); | |
1712 | if (dialogSettings != null) { | |
1713 | dialogSettings.put(HIDE_ARROWS_KEY, hideArrows); | |
1714 | } | |
086f21ae PT |
1715 | if (fFollowArrowFwdAction != null) { |
1716 | fFollowArrowFwdAction.setEnabled(!hideArrows); | |
1717 | } | |
1718 | if (fFollowArrowBwdAction != null) { | |
1719 | fFollowArrowBwdAction.setEnabled(!hideArrows); | |
1720 | } | |
79ec0b89 PT |
1721 | } |
1722 | }; | |
1723 | fHideArrowsAction.setToolTipText(Messages.TmfTimeGraphViewer_HideArrowsActionToolTipText); | |
1724 | fHideArrowsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HIDE_ARROWS)); | |
1725 | if (dialogSettings != null) { | |
1726 | boolean hideArrows = dialogSettings.getBoolean(HIDE_ARROWS_KEY); | |
1727 | fTimeGraphCtrl.hideArrows(hideArrows); | |
1728 | fHideArrowsAction.setChecked(hideArrows); | |
086f21ae PT |
1729 | if (fFollowArrowFwdAction != null) { |
1730 | fFollowArrowFwdAction.setEnabled(!hideArrows); | |
1731 | } | |
1732 | if (fFollowArrowBwdAction != null) { | |
1733 | fFollowArrowBwdAction.setEnabled(!hideArrows); | |
1734 | } | |
79ec0b89 PT |
1735 | } |
1736 | } | |
1737 | return fHideArrowsAction; | |
1738 | } | |
837a2f8c | 1739 | |
086f21ae PT |
1740 | /** |
1741 | * Get the follow arrow forward action. | |
1742 | * | |
1743 | * @return The Action object | |
086f21ae PT |
1744 | */ |
1745 | public Action getFollowArrowFwdAction() { | |
1746 | if (fFollowArrowFwdAction == null) { | |
1747 | fFollowArrowFwdAction = new Action() { | |
1748 | @Override | |
33fa1fc7 PT |
1749 | public void runWithEvent(Event event) { |
1750 | boolean extend = (event.stateMask & SWT.SHIFT) != 0; | |
1751 | fTimeGraphCtrl.followArrowFwd(extend); | |
086f21ae PT |
1752 | adjustVerticalScrollBar(); |
1753 | } | |
1754 | }; | |
1755 | fFollowArrowFwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionNameText); | |
1756 | fFollowArrowFwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText); | |
1757 | fFollowArrowFwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_FORWARD)); | |
1758 | if (fHideArrowsAction != null) { | |
1759 | fFollowArrowFwdAction.setEnabled(!fHideArrowsAction.isChecked()); | |
1760 | } | |
1761 | } | |
1762 | return fFollowArrowFwdAction; | |
1763 | } | |
1764 | ||
1765 | /** | |
1766 | * Get the follow arrow backward action. | |
1767 | * | |
1768 | * @return The Action object | |
086f21ae PT |
1769 | */ |
1770 | public Action getFollowArrowBwdAction() { | |
1771 | if (fFollowArrowBwdAction == null) { | |
1772 | fFollowArrowBwdAction = new Action() { | |
1773 | @Override | |
33fa1fc7 PT |
1774 | public void runWithEvent(Event event) { |
1775 | boolean extend = (event.stateMask & SWT.SHIFT) != 0; | |
1776 | fTimeGraphCtrl.followArrowBwd(extend); | |
086f21ae PT |
1777 | adjustVerticalScrollBar(); |
1778 | } | |
1779 | }; | |
1780 | fFollowArrowBwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionNameText); | |
1781 | fFollowArrowBwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText); | |
1782 | fFollowArrowBwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_BACKWARD)); | |
1783 | if (fHideArrowsAction != null) { | |
1784 | fFollowArrowBwdAction.setEnabled(!fHideArrowsAction.isChecked()); | |
1785 | } | |
1786 | } | |
1787 | return fFollowArrowBwdAction; | |
1788 | } | |
1789 | ||
b698ec63 PT |
1790 | private void adjustHorizontalScrollBar() { |
1791 | long time0 = getTime0(); | |
1792 | long time1 = getTime1(); | |
1793 | long timeMin = getMinTime(); | |
1794 | long timeMax = getMaxTime(); | |
1795 | long delta = timeMax - timeMin; | |
1796 | int timePos = 0; | |
1797 | int thumb = H_SCROLLBAR_MAX; | |
1798 | if (delta != 0) { | |
1799 | // Thumb size (page size) | |
1800 | thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta))); | |
1801 | // At the beginning of visible window | |
1802 | timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta)); | |
1803 | } | |
1804 | fHorizontalScrollBar.setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb)); | |
1805 | } | |
1806 | ||
837a2f8c | 1807 | private void adjustVerticalScrollBar() { |
f1fae91f PT |
1808 | int topIndex = fTimeGraphCtrl.getTopIndex(); |
1809 | int countPerPage = fTimeGraphCtrl.countPerPage(); | |
1810 | int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount(); | |
837a2f8c | 1811 | if (topIndex + countPerPage > expandedElementCount) { |
f1fae91f | 1812 | fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage)); |
837a2f8c PT |
1813 | } |
1814 | ||
f1fae91f | 1815 | int selection = fTimeGraphCtrl.getTopIndex(); |
837a2f8c PT |
1816 | int min = 0; |
1817 | int max = Math.max(1, expandedElementCount - 1); | |
1818 | int thumb = Math.min(max, Math.max(1, countPerPage - 1)); | |
1819 | int increment = 1; | |
1820 | int pageIncrement = Math.max(1, countPerPage); | |
f1fae91f | 1821 | fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement); |
837a2f8c PT |
1822 | } |
1823 | ||
27df1564 | 1824 | /** |
79ec0b89 PT |
1825 | * @param listener |
1826 | * a {@link MenuDetectListener} | |
2bdf0193 | 1827 | * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener) |
27df1564 XR |
1828 | */ |
1829 | public void addTimeGraphEntryMenuListener(MenuDetectListener listener) { | |
f1fae91f | 1830 | fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener); |
27df1564 XR |
1831 | } |
1832 | ||
1833 | /** | |
79ec0b89 PT |
1834 | * @param listener |
1835 | * a {@link MenuDetectListener} | |
2bdf0193 | 1836 | * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener) |
27df1564 XR |
1837 | */ |
1838 | public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) { | |
f1fae91f | 1839 | fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener); |
27df1564 XR |
1840 | } |
1841 | ||
1842 | /** | |
79ec0b89 PT |
1843 | * @param listener |
1844 | * a {@link MenuDetectListener} | |
2bdf0193 | 1845 | * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener) |
27df1564 XR |
1846 | */ |
1847 | public void addTimeEventMenuListener(MenuDetectListener listener) { | |
f1fae91f | 1848 | fTimeGraphCtrl.addTimeEventMenuListener(listener); |
27df1564 XR |
1849 | } |
1850 | ||
1851 | /** | |
79ec0b89 PT |
1852 | * @param listener |
1853 | * a {@link MenuDetectListener} | |
2bdf0193 | 1854 | * @see org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener) |
27df1564 XR |
1855 | */ |
1856 | public void removeTimeEventMenuListener(MenuDetectListener listener) { | |
f1fae91f | 1857 | fTimeGraphCtrl.removeTimeEventMenuListener(listener); |
27df1564 XR |
1858 | } |
1859 | ||
6ac5a950 | 1860 | /** |
79ec0b89 PT |
1861 | * @param filter |
1862 | * The filter object to be attached to the view | |
6ac5a950 AM |
1863 | */ |
1864 | public void addFilter(ViewerFilter filter) { | |
f1fae91f | 1865 | fTimeGraphCtrl.addFilter(filter); |
6ac5a950 AM |
1866 | refresh(); |
1867 | } | |
837a2f8c | 1868 | |
6ac5a950 | 1869 | /** |
79ec0b89 PT |
1870 | * @param filter |
1871 | * The filter object to be attached to the view | |
6ac5a950 AM |
1872 | */ |
1873 | public void removeFilter(ViewerFilter filter) { | |
f1fae91f | 1874 | fTimeGraphCtrl.removeFilter(filter); |
6ac5a950 AM |
1875 | refresh(); |
1876 | } | |
837a2f8c | 1877 | |
d2e4afa7 MAL |
1878 | /** |
1879 | * Return the time alignment information | |
1880 | * | |
1881 | * @return the time alignment information | |
1882 | * | |
1883 | * @see ITmfTimeAligned | |
1884 | * | |
1885 | * @since 1.0 | |
1886 | */ | |
1887 | public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() { | |
1888 | return fTimeGraphCtrl.getTimeViewAlignmentInfo(); | |
1889 | } | |
1890 | ||
1891 | /** | |
1892 | * Return the available width for the time-axis. | |
1893 | * | |
1894 | * @see ITmfTimeAligned | |
1895 | * | |
1896 | * @param requestedOffset | |
1897 | * the requested offset | |
1898 | * @return the available width for the time-axis | |
1899 | * | |
1900 | * @since 1.0 | |
1901 | */ | |
1902 | public int getAvailableWidth(int requestedOffset) { | |
921ae867 MAL |
1903 | int totalWidth = fTimeAlignedComposite.getSize().x; |
1904 | return Math.min(totalWidth, Math.max(0, totalWidth - requestedOffset)); | |
d2e4afa7 MAL |
1905 | } |
1906 | ||
1907 | /** | |
1908 | * Perform the alignment operation. | |
1909 | * | |
1910 | * @param offset | |
1911 | * the alignment offset | |
1912 | * @param width | |
1913 | * the alignment width | |
1914 | * | |
1915 | * @see ITmfTimeAligned | |
1916 | * | |
1917 | * @since 1.0 | |
1918 | */ | |
1919 | public void performAlign(int offset, int width) { | |
1920 | fTimeGraphCtrl.performAlign(offset); | |
1921 | int alignmentWidth = width; | |
1922 | int size = fTimeAlignedComposite.getSize().x; | |
1923 | GridLayout layout = (GridLayout) fTimeAlignedComposite.getLayout(); | |
1924 | int marginSize = size - alignmentWidth - offset; | |
1925 | layout.marginRight = Math.max(0, marginSize); | |
1926 | fTimeAlignedComposite.layout(); | |
1927 | } | |
1928 | ||
837a2f8c | 1929 | } |