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