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