Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /*****************************************************************************\r |
a5823d5f | 2 | * Copyright (c) 2007, 2008, 2009, 2010 Intel Corporation, Ericsson\r |
b0d3496e ASL |
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 | *\r | |
14 | * $Id: ThreadStatesView.java,v 1.7 2008/05/19 15:07:21 jkubasta Exp $ \r | |
15 | *****************************************************************************/\r | |
16 | \r | |
17 | package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis;\r | |
18 | \r | |
19 | import java.util.Iterator;\r | |
20 | import java.util.List;\r | |
21 | import java.util.Vector;\r | |
22 | \r | |
23 | import org.eclipse.jface.viewers.ISelection;\r | |
24 | import org.eclipse.jface.viewers.ISelectionProvider;\r | |
25 | import org.eclipse.jface.viewers.IStructuredSelection;\r | |
26 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.dialogs.TmfTimeFilterDialog;\r | |
27 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.dialogs.TmfTimeLegend;\r | |
28 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r | |
29 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r | |
41dc35d0 | 30 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent;\r |
b0d3496e ASL |
31 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider;\r |
32 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TimeScaleCtrl;\r | |
79a3a76e | 33 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TmfTimeStatesCtrl;\r |
41dc35d0 | 34 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TmfTimeTipHandler;\r |
b0d3496e ASL |
35 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme;\r |
36 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.Utils;\r | |
37 | import org.eclipse.swt.SWT;\r | |
38 | import org.eclipse.swt.events.ControlAdapter;\r | |
39 | import org.eclipse.swt.events.ControlEvent;\r | |
40 | import org.eclipse.swt.events.SelectionEvent;\r | |
41 | import org.eclipse.swt.events.SelectionListener;\r | |
42 | import org.eclipse.swt.graphics.Rectangle;\r | |
a5823d5f | 43 | import org.eclipse.swt.layout.GridLayout;\r |
b0d3496e ASL |
44 | import org.eclipse.swt.widgets.Composite;\r |
45 | import org.eclipse.swt.widgets.Control;\r | |
46 | \r | |
47 | public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProvider, SelectionListener {\r | |
48 | \r | |
49 | /** vars */\r | |
50 | private long _minTimeInterval;\r | |
51 | private long _selectedTime;\r | |
52 | private long _beginTime;\r | |
53 | private long _endTime;\r | |
54 | private long _time0;\r | |
55 | private long _time1;\r | |
56 | private long _time0_;\r | |
57 | private long _time1_;\r | |
6a2ffb7f ASL |
58 | private long _time0_extSynch = 0;\r |
59 | private long _time1_extSynch = 0;\r | |
b0d3496e ASL |
60 | private boolean _timeRangeFixed;\r |
61 | private int _nameWidthPref = 200;\r | |
62 | private int _minNameWidth = 6;\r | |
63 | private int _nameWidth;\r | |
64 | private Composite _dataViewer;\r | |
65 | \r | |
66 | private TmfTimeStatesCtrl _stateCtrl;\r | |
67 | private TimeScaleCtrl _timeScaleCtrl;\r | |
68 | private TmfTimeTipHandler _threadTip;\r | |
69 | private TraceColorScheme _colors;\r | |
70 | private TmfTimeAnalysisProvider _utilImplm;\r | |
71 | \r | |
72 | private boolean _acceptSetSelAPICalls = false;\r | |
73 | Vector<ITmfTimeSelectionListener> widgetSelectionListners = new Vector<ITmfTimeSelectionListener>();\r | |
dfaf8391 | 74 | Vector<ITmfTimeScaleSelectionListener> widgetTimeScaleSelectionListners = new Vector<ITmfTimeScaleSelectionListener>();\r |
b0d3496e ASL |
75 | Vector<ITmfTimeFilterSelectionListener> widgetFilterSelectionListeners = new Vector<ITmfTimeFilterSelectionListener>();\r |
76 | \r | |
77 | // Calender Time format, using Epoch reference or Relative time\r | |
78 | // format(default\r | |
79 | private boolean calendarTimeFormat = false;\r | |
a5823d5f | 80 | private int borderWidth = 4;\r |
b0d3496e ASL |
81 | private int timeScaleHeight = 22;\r |
82 | \r | |
83 | /** ctor */\r | |
84 | public TmfTimeAnalysisViewer(Composite parent, TmfTimeAnalysisProvider provider) {\r | |
85 | createDataViewer(parent, provider);\r | |
86 | }\r | |
87 | \r | |
88 | /* (non-Javadoc)\r | |
89 | * @see org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.api.ITimeAnalysisWidget#display(org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.model.TmfTaTrace[])\r | |
90 | */\r | |
d4011df2 FC |
91 | @Override\r |
92 | public void display(ITmfTimeAnalysisEntry[] traceArr) {\r | |
b0d3496e ASL |
93 | modelUpdate(traceArr);\r |
94 | }\r | |
95 | \r | |
d4011df2 | 96 | @Override\r |
d712a5f3 FC |
97 | public void display(ITmfTimeAnalysisEntry[] traceArr, long start, long end,\r |
98 | boolean updateTimeBounds) {\r | |
99 | modelUpdate(traceArr, start, end, updateTimeBounds);\r | |
b0d3496e ASL |
100 | }\r |
101 | \r | |
102 | public void controlMoved(ControlEvent e) {\r | |
103 | }\r | |
104 | \r | |
d4011df2 | 105 | @Override\r |
b0d3496e ASL |
106 | public void controlResized(ControlEvent e) {\r |
107 | resizeControls();\r | |
108 | }\r | |
109 | \r | |
110 | // called from the display order in the API\r | |
111 | public void modelUpdate(ITmfTimeAnalysisEntry[] traces) {\r | |
112 | if (null != _stateCtrl) {\r | |
113 | loadOptions();\r | |
114 | updateInternalData(traces);\r | |
115 | _stateCtrl.redraw();\r | |
116 | _timeScaleCtrl.redraw();\r | |
117 | }\r | |
118 | }\r | |
119 | \r | |
120 | // called from the display order in the API\r | |
d712a5f3 FC |
121 | public void modelUpdate(ITmfTimeAnalysisEntry[] traces, long start,\r |
122 | long end, boolean updateTimeBounds) {\r | |
b0d3496e ASL |
123 | if (null != _stateCtrl) {\r |
124 | loadOptions();\r | |
125 | updateInternalData(traces, start, end);\r | |
d712a5f3 FC |
126 | if (updateTimeBounds) {\r |
127 | _timeRangeFixed = true;\r | |
128 | // set window to match limits\r | |
71c964eb | 129 | setStartFinishTime(_time0_, _time1_);\r |
d712a5f3 FC |
130 | } else {\r |
131 | _stateCtrl.redraw();\r | |
132 | _timeScaleCtrl.redraw();\r | |
133 | }\r | |
b0d3496e ASL |
134 | }\r |
135 | }\r | |
136 | \r | |
d4011df2 | 137 | @Override\r |
b0d3496e ASL |
138 | public void itemUpdate(ITmfTimeAnalysisEntry parent, TimeEvent item) {\r |
139 | if (null != parent && null != item) {\r | |
140 | _stateCtrl.refreshPartial(parent, item);\r | |
141 | _stateCtrl.redraw();\r | |
142 | _timeScaleCtrl.redraw();\r | |
143 | }\r | |
144 | }\r | |
145 | \r | |
146 | public void selectionChanged() {\r | |
147 | }\r | |
148 | \r | |
149 | protected String getViewTypeStr() {\r | |
150 | return "viewoption.threads";\r | |
151 | }\r | |
152 | \r | |
153 | int getMarginWidth(int idx) {\r | |
154 | return 0;\r | |
155 | }\r | |
156 | \r | |
157 | int getMarginHeight(int idx) {\r | |
158 | return 0;\r | |
159 | }\r | |
160 | \r | |
161 | void loadOptions() {\r | |
8b9fa226 | 162 | _minTimeInterval = 1;\r |
b0d3496e ASL |
163 | _selectedTime = -1;\r |
164 | _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"),\r | |
165 | _nameWidthPref, _minNameWidth, 1000);\r | |
166 | }\r | |
167 | \r | |
168 | void saveOptions() {\r | |
169 | Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth);\r | |
170 | }\r | |
171 | \r | |
172 | protected Control createDataViewer(Composite parent,\r | |
173 | TmfTimeAnalysisProvider utilImplm) {\r | |
174 | loadOptions();\r | |
175 | _utilImplm = utilImplm;\r | |
176 | _colors = new TraceColorScheme();\r | |
177 | _dataViewer = new Composite(parent, SWT.NULL);\r | |
178 | _dataViewer.setLayoutData(GridUtil.createFill());\r | |
a5823d5f ASL |
179 | GridLayout gl = new GridLayout();\r |
180 | gl.marginHeight = borderWidth;\r | |
181 | gl.marginWidth = 0;\r | |
182 | gl.verticalSpacing = 0;\r | |
183 | gl.horizontalSpacing = 0;\r | |
184 | _dataViewer.setLayout(gl);\r | |
b0d3496e ASL |
185 | \r |
186 | _timeScaleCtrl = new TimeScaleCtrl(_dataViewer, _colors);\r | |
187 | _timeScaleCtrl.setTimeProvider(this);\r | |
a5823d5f ASL |
188 | _timeScaleCtrl.setLayoutData(GridUtil.createHorizontalFill());\r |
189 | _timeScaleCtrl.setHeight(timeScaleHeight);\r | |
b0d3496e ASL |
190 | \r |
191 | _stateCtrl = new TmfTimeStatesCtrl(_dataViewer, _colors, _utilImplm);\r | |
192 | \r | |
193 | _stateCtrl.setTimeProvider(this);\r | |
194 | _stateCtrl.addSelectionListener(this);\r | |
195 | _stateCtrl.setLayoutData(GridUtil.createFill());\r | |
196 | _dataViewer.addControlListener(new ControlAdapter() {\r | |
4e3aa37d | 197 | @Override\r |
b0d3496e ASL |
198 | public void controlResized(ControlEvent event) {\r |
199 | resizeControls();\r | |
200 | }\r | |
201 | });\r | |
202 | resizeControls();\r | |
203 | _dataViewer.update();\r | |
204 | _threadTip = new TmfTimeTipHandler(parent.getShell(), _utilImplm, this);\r | |
205 | _threadTip.activateHoverHelp(_stateCtrl);\r | |
206 | return _dataViewer;\r | |
207 | }\r | |
208 | \r | |
209 | public void dispose() {\r | |
210 | saveOptions();\r | |
211 | _stateCtrl.dispose();\r | |
212 | _dataViewer.dispose();\r | |
213 | _colors.dispose();\r | |
214 | }\r | |
215 | \r | |
d4011df2 | 216 | @Override\r |
b0d3496e ASL |
217 | public void resizeControls() {\r |
218 | Rectangle r = _dataViewer.getClientArea();\r | |
219 | if (r.isEmpty())\r | |
220 | return;\r | |
221 | \r | |
222 | int width = r.width;\r | |
223 | if (_nameWidth > width - _minNameWidth)\r | |
224 | _nameWidth = width - _minNameWidth;\r | |
225 | if (_nameWidth < _minNameWidth)\r | |
226 | _nameWidth = _minNameWidth;\r | |
227 | }\r | |
228 | \r | |
a5823d5f | 229 | /** Tries to set most convenient time range for display. */\r |
b0d3496e ASL |
230 | void setTimeRange(Object traces[]) {\r |
231 | _endTime = 0;\r | |
232 | _beginTime = -1;\r | |
233 | ITimeEvent event;\r | |
234 | for (int i = 0; i < traces.length; i++) {\r | |
a5823d5f ASL |
235 | ITmfTimeAnalysisEntry entry = (ITmfTimeAnalysisEntry) traces[i];\r |
236 | if (entry.getStopTime() >= entry.getStartTime() && entry.getStopTime() > 0) {\r | |
237 | if (_beginTime < 0 || entry.getStartTime() < _beginTime) {\r | |
238 | _beginTime = entry.getStartTime();\r | |
239 | }\r | |
240 | if (entry.getStopTime() > _endTime) {\r | |
241 | _endTime = entry.getStopTime();\r | |
242 | }\r | |
b0d3496e | 243 | }\r |
a5823d5f | 244 | List<TimeEvent> list = entry.getTraceEvents();\r |
b0d3496e ASL |
245 | int len = list.size();\r |
246 | if (len > 0) {\r | |
a5823d5f ASL |
247 | event = (ITimeEvent) list.get(0);\r |
248 | if (_beginTime < 0 || event.getTime() < _beginTime) {\r | |
249 | _beginTime = event.getTime();\r | |
250 | }\r | |
b0d3496e | 251 | event = (ITimeEvent) list.get(list.size() - 1);\r |
a5823d5f ASL |
252 | long eventEndTime = event.getTime() + (event.getDuration() > 0 ? event.getDuration() : 0);\r |
253 | if (eventEndTime > _endTime) {\r | |
254 | _endTime = eventEndTime;\r | |
b0d3496e ASL |
255 | }\r |
256 | }\r | |
257 | }\r | |
258 | \r | |
259 | if (_beginTime < 0)\r | |
260 | _beginTime = 0;\r | |
261 | }\r | |
262 | \r | |
263 | void setTimeBounds() {\r | |
a5823d5f ASL |
264 | //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);\r |
265 | _time0_ = _beginTime;\r | |
b0d3496e ASL |
266 | if (_time0_ < 0)\r |
267 | _time0_ = 0;\r | |
268 | // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;\r | |
269 | _time1_ = _endTime;\r | |
270 | // _time0_ = Math.floor(_time0_);\r | |
271 | // _time1_ = Math.ceil(_time1_);\r | |
272 | if (!_timeRangeFixed) {\r | |
273 | _time0 = _time0_;\r | |
274 | _time1 = _time1_;\r | |
275 | }\r | |
8b9fa226 ASL |
276 | if (_time1 - _time0 < _minTimeInterval) {\r |
277 | _time1 = _time0 + _minTimeInterval;\r | |
278 | }\r | |
b0d3496e ASL |
279 | }\r |
280 | \r | |
281 | /**\r | |
282 | * @param traces\r | |
283 | */\r | |
284 | void updateInternalData(ITmfTimeAnalysisEntry[] traces) {\r | |
285 | if (null == traces)\r | |
286 | traces = new ITmfTimeAnalysisEntry[0];\r | |
287 | setTimeRange(traces);\r | |
288 | refreshAllData(traces);\r | |
289 | }\r | |
290 | \r | |
291 | /**\r | |
292 | * @param traces\r | |
293 | * @param start\r | |
294 | * @param end\r | |
295 | */\r | |
296 | void updateInternalData(ITmfTimeAnalysisEntry[] traces, long start, long end) {\r | |
297 | if (null == traces)\r | |
298 | traces = new ITmfTimeAnalysisEntry[0];\r | |
a5823d5f ASL |
299 | if ((start == 0 && end == 0) || start < 0 || end < 0) {\r |
300 | // Start and end time are unspecified and need to be determined from\r | |
d712a5f3 | 301 | // individual processes\r |
b0d3496e ASL |
302 | setTimeRange(traces);\r |
303 | } else {\r | |
79a3a76e | 304 | _beginTime = start;\r |
71c964eb | 305 | _endTime = end;\r |
b0d3496e ASL |
306 | }\r |
307 | \r | |
308 | refreshAllData(traces);\r | |
309 | }\r | |
310 | \r | |
311 | /**\r | |
312 | * @param traces\r | |
313 | */\r | |
314 | private void refreshAllData(ITmfTimeAnalysisEntry[] traces) {\r | |
315 | setTimeBounds();\r | |
a5823d5f ASL |
316 | if (_selectedTime < _beginTime) {\r |
317 | _selectedTime = _beginTime;\r | |
318 | } else if (_selectedTime > _endTime) {\r | |
319 | _selectedTime = _endTime;\r | |
320 | }\r | |
b0d3496e ASL |
321 | _stateCtrl.refreshData(traces);\r |
322 | filterOutNotification();\r | |
323 | }\r | |
324 | \r | |
d4011df2 | 325 | @Override\r |
b0d3496e ASL |
326 | public void setFocus() {\r |
327 | if (null != _stateCtrl)\r | |
328 | _stateCtrl.setFocus();\r | |
329 | }\r | |
330 | \r | |
d4011df2 | 331 | @Override\r |
b0d3496e ASL |
332 | public boolean isInFocus() {\r |
333 | return _stateCtrl.isInFocus();\r | |
334 | }\r | |
335 | \r | |
d4011df2 | 336 | @Override\r |
b0d3496e ASL |
337 | public ITmfTimeAnalysisEntry getSelectedTrace() {\r |
338 | return _stateCtrl.getSelectedTrace();\r | |
339 | }\r | |
340 | \r | |
d4011df2 | 341 | @Override\r |
b0d3496e ASL |
342 | public ISelection getSelection() {\r |
343 | return _stateCtrl.getSelection();\r | |
344 | }\r | |
345 | \r | |
d4011df2 | 346 | @Override\r |
b0d3496e ASL |
347 | public ISelection getSelectionTrace() {\r |
348 | return _stateCtrl.getSelectionTrace();\r | |
349 | }\r | |
350 | \r | |
d4011df2 | 351 | @Override\r |
b0d3496e ASL |
352 | public long getTime0() {\r |
353 | return _time0;\r | |
354 | }\r | |
355 | \r | |
d4011df2 | 356 | @Override\r |
b0d3496e ASL |
357 | public long getTime1() {\r |
358 | return _time1;\r | |
359 | }\r | |
360 | \r | |
d4011df2 | 361 | @Override\r |
b0d3496e ASL |
362 | public long getMinTimeInterval() {\r |
363 | return _minTimeInterval;\r | |
364 | }\r | |
365 | \r | |
d4011df2 | 366 | @Override\r |
b0d3496e ASL |
367 | public int getNameSpace() {\r |
368 | return _nameWidth;\r | |
369 | }\r | |
370 | \r | |
d4011df2 | 371 | @Override\r |
b0d3496e ASL |
372 | public void setNameSpace(int width) {\r |
373 | _nameWidth = width;\r | |
374 | width = _stateCtrl.getClientArea().width;\r | |
375 | if (_nameWidth > width - 6)\r | |
376 | _nameWidth = width - 6;\r | |
377 | if (_nameWidth < 6)\r | |
378 | _nameWidth = 6;\r | |
379 | _stateCtrl.adjustScrolls();\r | |
380 | _stateCtrl.redraw();\r | |
381 | _timeScaleCtrl.redraw();\r | |
382 | }\r | |
383 | \r | |
d4011df2 | 384 | @Override\r |
b0d3496e ASL |
385 | public int getTimeSpace() {\r |
386 | int w = _stateCtrl.getClientArea().width;\r | |
387 | return w - _nameWidth;\r | |
388 | }\r | |
389 | \r | |
d4011df2 | 390 | @Override\r |
b0d3496e ASL |
391 | public long getSelectedTime() {\r |
392 | return _selectedTime;\r | |
393 | }\r | |
394 | \r | |
d4011df2 | 395 | @Override\r |
b0d3496e ASL |
396 | public long getBeginTime() {\r |
397 | return _beginTime;\r | |
398 | }\r | |
399 | \r | |
d4011df2 | 400 | @Override\r |
b0d3496e ASL |
401 | public long getEndTime() {\r |
402 | return _endTime;\r | |
403 | }\r | |
404 | \r | |
d4011df2 | 405 | @Override\r |
b0d3496e ASL |
406 | public long getMaxTime() {\r |
407 | return _time1_;\r | |
408 | }\r | |
409 | \r | |
d4011df2 | 410 | @Override\r |
b0d3496e ASL |
411 | public long getMinTime() {\r |
412 | return _time0_;\r | |
413 | }\r | |
414 | \r | |
71c964eb ASL |
415 | /*\r |
416 | * (non-Javadoc)\r | |
417 | * \r | |
418 | * @see\r | |
419 | * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider\r | |
420 | * #setStartFinishTimeNotify(long, long)\r | |
421 | */\r | |
d4011df2 | 422 | @Override\r |
71c964eb ASL |
423 | public void setStartFinishTimeNotify(long time0, long time1) {\r |
424 | setStartFinishTime(time0, time1);\r | |
b0d3496e ASL |
425 | notifyStartFinishTimeSelectionListeners(time0, time1);\r |
426 | }\r | |
427 | \r | |
8b9fa226 ASL |
428 | \r |
429 | /* (non-Javadoc)\r | |
430 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()\r | |
431 | */\r | |
d4011df2 FC |
432 | @Override\r |
433 | public void notifyStartFinishTime() {\r | |
8b9fa226 ASL |
434 | notifyStartFinishTimeSelectionListeners(_time0, _time1);\r |
435 | }\r | |
436 | \r | |
437 | /*\r | |
71c964eb ASL |
438 | * (non-Javadoc)\r |
439 | * \r | |
440 | * @see\r | |
441 | * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider\r | |
442 | * #setStartFinishTime(long, long)\r | |
443 | */\r | |
d4011df2 | 444 | @Override\r |
71c964eb | 445 | public void setStartFinishTime(long time0, long time1) {\r |
b0d3496e | 446 | _time0 = time0;\r |
8b9fa226 ASL |
447 | if (_time0 < _time0_)\r |
448 | _time0 = _time0_;\r | |
449 | if (_time0 > _time1_)\r | |
450 | _time0 = _time1_;\r | |
b0d3496e | 451 | _time1 = time1;\r |
8b9fa226 ASL |
452 | if (_time1 < _time0_)\r |
453 | _time1 = _time0_;\r | |
454 | if (_time1 > _time1_)\r | |
455 | _time1 = _time1_;\r | |
b0d3496e | 456 | if (_time1 - _time0 < _minTimeInterval)\r |
8b9fa226 | 457 | _time1 = _time0 + _minTimeInterval;\r |
b0d3496e ASL |
458 | _timeRangeFixed = true;\r |
459 | _stateCtrl.adjustScrolls();\r | |
460 | _stateCtrl.redraw();\r | |
461 | _timeScaleCtrl.redraw();\r | |
462 | }\r | |
463 | \r | |
d4011df2 | 464 | @Override\r |
b0d3496e | 465 | public void resetStartFinishTime() {\r |
71c964eb | 466 | setStartFinishTimeNotify(_time0_, _time1_);\r |
b0d3496e ASL |
467 | _timeRangeFixed = false;\r |
468 | }\r | |
469 | \r | |
d4011df2 | 470 | @Override\r |
b0d3496e ASL |
471 | public void setSelectedTimeInt(long time, boolean ensureVisible) {\r |
472 | // Trace.debug("currentTime:" + _selectedTime + " new time:" + time);\r | |
473 | _selectedTime = time;\r | |
474 | if (_selectedTime > _endTime)\r | |
475 | _selectedTime = _endTime;\r | |
476 | if (_selectedTime < _beginTime)\r | |
477 | _selectedTime = _beginTime;\r | |
478 | if (ensureVisible) {\r | |
479 | double timeSpace = (_time1 - _time0) * .02;\r | |
480 | double timeMid = (_time1 - _time0) * .1;\r | |
481 | if (_selectedTime < _time0 + timeSpace) {\r | |
482 | double dt = _time0 - _selectedTime + timeMid;\r | |
483 | _time0 -= dt;\r | |
484 | _time1 -= dt;\r | |
485 | } else if (_selectedTime > _time1 - timeSpace) {\r | |
486 | double dt = _selectedTime - _time1 + timeMid;\r | |
487 | _time0 += dt;\r | |
488 | _time1 += dt;\r | |
489 | }\r | |
a5823d5f ASL |
490 | if (_time0 < _time0_) {\r |
491 | _time1 += _time0_ - _time0;\r | |
492 | _time0 = _time0_;\r | |
b0d3496e ASL |
493 | } else if (_time1 > _time1_) {\r |
494 | _time0 -= _time1 - _time1_;\r | |
495 | _time1 = _time1_;\r | |
496 | }\r | |
497 | }\r | |
498 | _stateCtrl.adjustScrolls();\r | |
499 | _stateCtrl.redraw();\r | |
500 | _timeScaleCtrl.redraw();\r | |
501 | }\r | |
502 | \r | |
d4011df2 | 503 | @Override\r |
b0d3496e ASL |
504 | public void widgetDefaultSelected(SelectionEvent e) {\r |
505 | // TODO: Opening call stack shall be replaced to a configurable view\r | |
506 | // new OpenCallStackViewAction().openView(false);\r | |
507 | // Replaced by event notification\r | |
508 | // updateModelSelection();\r | |
509 | notifySelectionListeners(TmfTimeSelectionEvent.type.WIDGET_DEF_SEL);\r | |
510 | }\r | |
511 | \r | |
d4011df2 | 512 | @Override\r |
b0d3496e ASL |
513 | public void widgetSelected(SelectionEvent e) {\r |
514 | // Replace by event notification\r | |
515 | // updateModelSelection();\r | |
516 | notifySelectionListeners(TmfTimeSelectionEvent.type.WIDGET_SEL);\r | |
517 | }\r | |
518 | \r | |
d4011df2 | 519 | @Override\r |
b0d3496e ASL |
520 | public void selectNextEvent() {\r |
521 | _stateCtrl.selectNextEvent();\r | |
522 | }\r | |
523 | \r | |
d4011df2 | 524 | @Override\r |
b0d3496e ASL |
525 | public void selectPrevEvent() {\r |
526 | _stateCtrl.selectPrevEvent();\r | |
527 | }\r | |
528 | \r | |
d4011df2 | 529 | @Override\r |
b0d3496e ASL |
530 | public void selectNextTrace() {\r |
531 | _stateCtrl.selectNextTrace();\r | |
532 | }\r | |
533 | \r | |
d4011df2 | 534 | @Override\r |
b0d3496e ASL |
535 | public void selectPrevTrace() {\r |
536 | _stateCtrl.selectPrevTrace();\r | |
537 | }\r | |
538 | \r | |
d4011df2 | 539 | @Override\r |
b0d3496e ASL |
540 | public void groupTraces(boolean on) {\r |
541 | _stateCtrl.groupTraces(on);\r | |
542 | }\r | |
543 | \r | |
d4011df2 | 544 | @Override\r |
b0d3496e ASL |
545 | public void filterTraces() {\r |
546 | if (_dataViewer == null || _dataViewer.isDisposed())\r | |
547 | return;\r | |
548 | \r | |
549 | if (TmfTimeFilterDialog.getTraceFilter(_dataViewer.getShell(), _stateCtrl\r | |
550 | .getTraces(), _stateCtrl.getTraceFilter())) {\r | |
551 | _stateCtrl.refreshData();\r | |
552 | filterOutNotification();\r | |
553 | }\r | |
554 | }\r | |
555 | \r | |
d4011df2 | 556 | @Override\r |
b0d3496e ASL |
557 | public void showLegend() {\r |
558 | if (_dataViewer == null || _dataViewer.isDisposed())\r | |
559 | return;\r | |
560 | \r | |
561 | TmfTimeLegend.open(_dataViewer.getShell(), _utilImplm);\r | |
562 | }\r | |
563 | \r | |
564 | public void toggleThreadsInteractionDrawing() {\r | |
565 | _stateCtrl.toggleTraceInteractionDrawing();\r | |
566 | }\r | |
567 | \r | |
568 | public void setThreadJoinDrawing(boolean on) {\r | |
569 | _stateCtrl.setTraceJoinDrawing(on);\r | |
570 | }\r | |
571 | \r | |
572 | public void setThreadWaitDrawing(boolean on) {\r | |
573 | _stateCtrl.setTraceWaitDrawing(on);\r | |
574 | }\r | |
575 | \r | |
576 | public void setThreadReleaseDrawing(boolean on) {\r | |
577 | _stateCtrl.setTraceReleaseDrawing(on);\r | |
578 | }\r | |
579 | \r | |
580 | public boolean getThreadInteractionDrawing() {\r | |
581 | return _stateCtrl.getTracesInteractionDrawing();\r | |
582 | }\r | |
583 | \r | |
584 | public boolean getThreadJoinDrawing() {\r | |
585 | return _stateCtrl.getTraceJoinDrawing();\r | |
586 | }\r | |
587 | \r | |
588 | public boolean getThreadWaitDrawing() {\r | |
589 | return _stateCtrl.getTraceWaitDrawing();\r | |
590 | }\r | |
591 | \r | |
592 | public boolean getThreadReleaseDrawing() {\r | |
593 | return _stateCtrl.getTraceReleaseDrawing();\r | |
594 | }\r | |
595 | \r | |
596 | protected void select(Object obj) {\r | |
597 | if (obj == null)\r | |
598 | return;\r | |
599 | // TODO: ThreadDetails Adaption removed, might need replacement\r | |
600 | // if (obj instanceof ThreadDetails) {\r | |
601 | // obj = ((ThreadDetails) obj).getThread();\r | |
602 | // }\r | |
603 | if (obj instanceof ITmfTimeAnalysisEntry) {\r | |
604 | // _stateCtrl.selectThread((TsfTmTrace) obj);\r | |
605 | }\r | |
606 | }\r | |
607 | \r | |
d4011df2 | 608 | @Override\r |
b0d3496e ASL |
609 | public void zoomIn() {\r |
610 | _stateCtrl.zoomIn();\r | |
611 | }\r | |
612 | \r | |
d4011df2 | 613 | @Override\r |
b0d3496e ASL |
614 | public void zoomOut() {\r |
615 | _stateCtrl.zoomOut();\r | |
616 | }\r | |
617 | \r | |
618 | private String getPreferenceString(String string) {\r | |
619 | return getViewTypeStr() + "." + string;\r | |
620 | }\r | |
621 | \r | |
d4011df2 | 622 | @Override\r |
b0d3496e ASL |
623 | public void addWidgetSelectionListner(ITmfTimeSelectionListener listener) {\r |
624 | widgetSelectionListners.add(listener);\r | |
625 | }\r | |
626 | \r | |
d4011df2 | 627 | @Override\r |
b0d3496e ASL |
628 | public void removeWidgetSelectionListner(ITmfTimeSelectionListener listener) {\r |
629 | widgetSelectionListners.removeElement(listener);\r | |
630 | }\r | |
631 | \r | |
d4011df2 | 632 | @Override\r |
b0d3496e | 633 | public void addWidgetTimeScaleSelectionListner(\r |
dfaf8391 | 634 | ITmfTimeScaleSelectionListener listener) {\r |
b0d3496e ASL |
635 | widgetTimeScaleSelectionListners.add(listener);\r |
636 | }\r | |
637 | \r | |
d4011df2 | 638 | @Override\r |
b0d3496e | 639 | public void removeWidgetTimeScaleSelectionListner(\r |
dfaf8391 | 640 | ITmfTimeScaleSelectionListener listener) {\r |
b0d3496e ASL |
641 | widgetTimeScaleSelectionListners.removeElement(listener);\r |
642 | }\r | |
643 | \r | |
d4011df2 | 644 | @Override\r |
b0d3496e ASL |
645 | public void setSelectedTime(long time, boolean ensureVisible, Object source) {\r |
646 | if (_acceptSetSelAPICalls == false || this == source) {\r | |
647 | return;\r | |
648 | }\r | |
649 | \r | |
650 | setSelectedTimeInt(time, ensureVisible);\r | |
651 | }\r | |
652 | \r | |
d4011df2 | 653 | @Override\r |
b0d3496e ASL |
654 | public void setSelectedEvent(ITimeEvent event, Object source) {\r |
655 | if (_acceptSetSelAPICalls == false || event == null || source == this) {\r | |
656 | return;\r | |
657 | }\r | |
658 | ITmfTimeAnalysisEntry trace = event.getEntry();\r | |
659 | if (trace != null) {\r | |
660 | _stateCtrl.selectItem(trace, false);\r | |
661 | }\r | |
662 | \r | |
663 | setSelectedTimeInt(event.getTime(), true);\r | |
664 | }\r | |
665 | \r | |
d4011df2 | 666 | @Override\r |
b0d3496e ASL |
667 | public void setSelectedTraceTime(ITmfTimeAnalysisEntry trace, long time, Object source) {\r |
668 | if (_acceptSetSelAPICalls == false || trace == null || source == this) {\r | |
669 | return;\r | |
670 | }\r | |
671 | \r | |
672 | if (trace != null) {\r | |
673 | _stateCtrl.selectItem(trace, false);\r | |
674 | }\r | |
675 | \r | |
676 | setSelectedTimeInt(time, true);\r | |
677 | }\r | |
678 | \r | |
d4011df2 | 679 | @Override\r |
b0d3496e ASL |
680 | public void setSelectedTrace(ITmfTimeAnalysisEntry trace) {\r |
681 | if (trace == null) {\r | |
682 | return;\r | |
683 | }\r | |
684 | \r | |
685 | _stateCtrl.selectItem(trace, false);\r | |
686 | }\r | |
687 | \r | |
6a2ffb7f ASL |
688 | /*\r |
689 | * (non-Javadoc)\r | |
690 | * \r | |
691 | * @see\r | |
692 | * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer\r | |
693 | * #setSelectVisTimeWindow(long, long, java.lang.Object)\r | |
694 | */\r | |
d4011df2 | 695 | @Override\r |
b0d3496e ASL |
696 | public void setSelectVisTimeWindow(long time0, long time1, Object source) {\r |
697 | if (_acceptSetSelAPICalls == false || source == this) {\r | |
698 | return;\r | |
699 | }\r | |
700 | \r | |
71c964eb | 701 | setStartFinishTime(time0, time1);\r |
6a2ffb7f ASL |
702 | \r |
703 | // update notification time values since we are now in synch with the\r | |
704 | // external application\r | |
705 | updateExtSynchTimers();\r | |
b0d3496e ASL |
706 | }\r |
707 | \r | |
d4011df2 | 708 | @Override\r |
b0d3496e ASL |
709 | public void setAcceptSelectionAPIcalls(boolean acceptCalls) {\r |
710 | _acceptSetSelAPICalls = acceptCalls;\r | |
711 | }\r | |
712 | \r | |
713 | private synchronized void notifySelectionListeners(\r | |
714 | TmfTimeSelectionEvent.type rtype) {\r | |
715 | // Any listeners out there ?\r | |
716 | if (widgetSelectionListners.size() > 0) {\r | |
717 | // Locate the event selected\r | |
718 | ISelection selection = getSelection();\r | |
719 | Object sel = null;\r | |
720 | if (selection != null && !selection.isEmpty()) {\r | |
721 | sel = ((IStructuredSelection) selection).getFirstElement();\r | |
722 | }\r | |
723 | \r | |
724 | if (sel != null) {\r | |
725 | // Notify Selection Listeners\r | |
726 | TmfTimeSelectionEvent event = new TmfTimeSelectionEvent(this,\r | |
727 | rtype, sel, getSelectedTime());\r | |
728 | \r | |
729 | for (Iterator<ITmfTimeSelectionListener> iter = widgetSelectionListners\r | |
730 | .iterator(); iter.hasNext();) {\r | |
731 | ITmfTimeSelectionListener listener = (ITmfTimeSelectionListener) iter\r | |
732 | .next();\r | |
733 | listener.tsfTmProcessSelEvent(event);\r | |
734 | }\r | |
735 | }\r | |
736 | }\r | |
737 | }\r | |
738 | \r | |
739 | public void notifyStartFinishTimeSelectionListeners(long _time0, long _time1) {\r | |
740 | if (widgetTimeScaleSelectionListners.size() > 0) {\r | |
71c964eb | 741 | // Check if the time has actually changed from last notification\r |
6a2ffb7f | 742 | if (_time0 != _time0_extSynch || _time1 != _time1_extSynch) {\r |
71c964eb ASL |
743 | // Notify Time Scale Selection Listeners\r |
744 | TmfTimeScaleSelectionEvent event = new TmfTimeScaleSelectionEvent(\r | |
745 | this, _time0, _time1, getTimeSpace(), getSelectedTime());\r | |
746 | \r | |
747 | for (Iterator<ITmfTimeScaleSelectionListener> iter = widgetTimeScaleSelectionListners\r | |
748 | .iterator(); iter.hasNext();) {\r | |
749 | ITmfTimeScaleSelectionListener listener = (ITmfTimeScaleSelectionListener) iter\r | |
750 | .next();\r | |
751 | listener.tsfTmProcessTimeScaleEvent(event);\r | |
752 | }\r | |
753 | \r | |
6a2ffb7f ASL |
754 | // update external synch timers\r |
755 | updateExtSynchTimers();\r | |
b0d3496e ASL |
756 | }\r |
757 | }\r | |
758 | }\r | |
759 | \r | |
6a2ffb7f ASL |
760 | /**\r |
761 | * update the cache timers used to identify the need to send a time window\r | |
762 | * update to external registered listeners\r | |
763 | */\r | |
764 | private void updateExtSynchTimers() {\r | |
765 | // last time notification cache\r | |
766 | _time0_extSynch = _time0;\r | |
767 | _time1_extSynch = _time1;\r | |
768 | }\r | |
769 | \r | |
d4011df2 | 770 | @Override\r |
b0d3496e ASL |
771 | public void setTimeCalendarFormat(boolean toAbsoluteCaltime) {\r |
772 | calendarTimeFormat = toAbsoluteCaltime;\r | |
773 | }\r | |
774 | \r | |
d4011df2 | 775 | @Override\r |
b0d3496e ASL |
776 | public boolean isCalendarFormat() {\r |
777 | return calendarTimeFormat;\r | |
778 | }\r | |
779 | \r | |
d4011df2 | 780 | @Override\r |
b0d3496e | 781 | public int getBorderWidth() {\r |
a5823d5f | 782 | return borderWidth;\r |
b0d3496e ASL |
783 | }\r |
784 | \r | |
d4011df2 | 785 | @Override\r |
b0d3496e ASL |
786 | public void setBorderWidth(int borderWidth) {\r |
787 | if (borderWidth > -1) {\r | |
a5823d5f ASL |
788 | this.borderWidth = borderWidth;\r |
789 | GridLayout gl = (GridLayout)_dataViewer.getLayout();\r | |
790 | gl.marginHeight = borderWidth;\r | |
b0d3496e ASL |
791 | }\r |
792 | }\r | |
793 | \r | |
d4011df2 | 794 | @Override\r |
b0d3496e ASL |
795 | public int getHeaderHeight() {\r |
796 | return timeScaleHeight;\r | |
797 | }\r | |
798 | \r | |
d4011df2 | 799 | @Override\r |
b0d3496e ASL |
800 | public void setHeaderHeight(int headerHeight) {\r |
801 | if (headerHeight > -1) {\r | |
802 | this.timeScaleHeight = headerHeight;\r | |
a5823d5f | 803 | _timeScaleCtrl.setHeight(headerHeight);\r |
b0d3496e ASL |
804 | }\r |
805 | }\r | |
806 | \r | |
d4011df2 | 807 | @Override\r |
b0d3496e ASL |
808 | public int getItemHeight() {\r |
809 | if (_stateCtrl != null) {\r | |
810 | return _stateCtrl.getItemHeight();\r | |
811 | }\r | |
812 | return 0;\r | |
813 | }\r | |
814 | \r | |
d4011df2 | 815 | @Override\r |
b0d3496e ASL |
816 | public void setItemHeight(int rowHeight) {\r |
817 | if (_stateCtrl != null) {\r | |
818 | _stateCtrl.setItemHeight(rowHeight);\r | |
819 | }\r | |
820 | }\r | |
821 | \r | |
d4011df2 | 822 | @Override\r |
b0d3496e ASL |
823 | public boolean isVisibleVerticalScroll() {\r |
824 | if (_stateCtrl != null) {\r | |
825 | _stateCtrl.isVisibleVerticalScroll();\r | |
826 | }\r | |
827 | return false;\r | |
828 | }\r | |
829 | \r | |
d4011df2 | 830 | @Override\r |
b0d3496e ASL |
831 | public void setVisibleVerticalScroll(boolean visibleVerticalScroll) {\r |
832 | if (_stateCtrl != null) {\r | |
833 | _stateCtrl.setVisibleVerticalScroll(visibleVerticalScroll);\r | |
834 | }\r | |
835 | }\r | |
836 | \r | |
d4011df2 | 837 | @Override\r |
b0d3496e ASL |
838 | public void setNameWidthPref(int width) {\r |
839 | _nameWidthPref = width;\r | |
840 | if (width == 0) {\r | |
841 | _minNameWidth = 0;\r | |
842 | }\r | |
843 | }\r | |
844 | \r | |
d4011df2 | 845 | @Override\r |
b0d3496e ASL |
846 | public int getNameWidthPref(int width) {\r |
847 | return _nameWidthPref;\r | |
848 | }\r | |
849 | \r | |
d4011df2 | 850 | @Override\r |
b0d3496e ASL |
851 | public void addFilterSelectionListner(ITmfTimeFilterSelectionListener listener) {\r |
852 | widgetFilterSelectionListeners.add(listener);\r | |
853 | }\r | |
854 | \r | |
d4011df2 | 855 | @Override\r |
b0d3496e ASL |
856 | public void removeFilterSelectionListner(\r |
857 | ITmfTimeFilterSelectionListener listener) {\r | |
858 | widgetFilterSelectionListeners.remove(listener);\r | |
859 | }\r | |
860 | \r | |
861 | private void filterOutNotification() {\r | |
862 | TmfTimeFilterSelectionEvent event = new TmfTimeFilterSelectionEvent(this);\r | |
863 | event.setFilteredOut(_stateCtrl.getFilteredOut());\r | |
864 | for (ITmfTimeFilterSelectionListener listener : widgetFilterSelectionListeners) {\r | |
865 | listener.tmfTaProcessFilterSelection(event);\r | |
866 | }\r | |
867 | }\r | |
868 | \r | |
869 | /**\r | |
870 | * needed in case there's a need to associate a context menu\r | |
871 | * \r | |
872 | * @return\r | |
873 | */\r | |
d4011df2 | 874 | @Override\r |
b0d3496e ASL |
875 | public Control getControl() {\r |
876 | return _stateCtrl;\r | |
877 | }\r | |
878 | \r | |
879 | /**\r | |
880 | * Get the selection provider\r | |
881 | * \r | |
882 | * @return\r | |
883 | */\r | |
d4011df2 | 884 | @Override\r |
b0d3496e ASL |
885 | public ISelectionProvider getSelectionProvider() {\r |
886 | return _stateCtrl;\r | |
887 | }\r | |
41dc35d0 FC |
888 | \r |
889 | /*\r | |
890 | * (non-Javadoc)\r | |
891 | * \r | |
892 | * @see\r | |
893 | * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer\r | |
894 | * #waitCursor(boolean)\r | |
895 | */\r | |
d4011df2 | 896 | @Override\r |
41dc35d0 FC |
897 | public void waitCursor(boolean waitInd) {\r |
898 | _stateCtrl.waitCursor(waitInd);\r | |
899 | }\r | |
b0d3496e | 900 | }\r |