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