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