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