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