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