Commit | Line | Data |
---|---|---|
72eda778 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
fb5cad3d | 12 | package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.views; |
f6281059 ASL |
13 | |
14 | import java.text.SimpleDateFormat; | |
15 | import java.util.ArrayList; | |
16 | import java.util.Date; | |
17 | ||
18 | import org.eclipse.core.runtime.IAdaptable; | |
19 | import org.eclipse.jface.action.Action; | |
20 | import org.eclipse.jface.action.IMenuListener; | |
21 | import org.eclipse.jface.action.IMenuManager; | |
22 | import org.eclipse.jface.action.IToolBarManager; | |
23 | import org.eclipse.jface.action.MenuManager; | |
24 | import org.eclipse.jface.action.Separator; | |
25 | import org.eclipse.jface.dialogs.MessageDialog; | |
26 | import org.eclipse.jface.viewers.DoubleClickEvent; | |
27 | import org.eclipse.jface.viewers.IDoubleClickListener; | |
28 | import org.eclipse.jface.viewers.ISelection; | |
29 | import org.eclipse.jface.viewers.IStructuredContentProvider; | |
30 | import org.eclipse.jface.viewers.IStructuredSelection; | |
31 | import org.eclipse.jface.viewers.ITreeContentProvider; | |
32 | import org.eclipse.jface.viewers.LabelProvider; | |
33 | import org.eclipse.jface.viewers.TreeViewer; | |
34 | import org.eclipse.jface.viewers.Viewer; | |
35 | import org.eclipse.jface.viewers.ViewerSorter; | |
fb5cad3d PT |
36 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; |
37 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; | |
38 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; | |
39 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; | |
40 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent; | |
41 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; | |
42 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer; | |
43 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
44 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.adaption.TsfImplProvider; | |
45 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.EventImpl; | |
46 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.TraceImpl; | |
47 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.test.stub.model.TraceModelImplFactory; | |
f6281059 ASL |
48 | import org.eclipse.swt.SWT; |
49 | import org.eclipse.swt.custom.SashForm; | |
50 | import org.eclipse.swt.graphics.Image; | |
51 | import org.eclipse.swt.widgets.Composite; | |
52 | import org.eclipse.swt.widgets.Menu; | |
53 | import org.eclipse.ui.IActionBars; | |
54 | import org.eclipse.ui.ISharedImages; | |
55 | import org.eclipse.ui.IWorkbenchActionConstants; | |
56 | import org.eclipse.ui.PlatformUI; | |
57 | import org.eclipse.ui.part.DrillDownAdapter; | |
58 | import org.eclipse.ui.part.ViewPart; | |
59 | ||
3b38ea61 | 60 | @SuppressWarnings("nls") |
f6281059 | 61 | public class TsfTraceAnalysisView extends ViewPart implements |
fb5cad3d | 62 | ITimeGraphSelectionListener, ITimeGraphTimeListener, ITimeGraphRangeListener { |
72eda778 ASL |
63 | |
64 | // ======================================================================== | |
65 | // Data | |
66 | // ======================================================================== | |
f6281059 ASL |
67 | private TreeViewer viewer; |
68 | private DrillDownAdapter drillDownAdapter; | |
69 | private Action action1; | |
70 | private Action action2; | |
f6281059 ASL |
71 | private Action resetScale; |
72 | private Action nextEvent; | |
73 | private Action prevEvent; | |
74 | private Action nextTrace; | |
75 | private Action prevTrace; | |
76 | private Action showLegent; | |
f6281059 ASL |
77 | private Action zoomIn; |
78 | private Action zoomOut; | |
f6281059 ASL |
79 | private Action events300K; |
80 | ||
81 | private Action doubleClickAction; | |
fb5cad3d PT |
82 | private TimeGraphViewer tsfviewer; |
83 | private TimeGraphViewer tsfviewer2; | |
f6281059 ASL |
84 | |
85 | private static SimpleDateFormat stimeformat = new SimpleDateFormat( | |
86 | "yy/MM/dd HH:mm:ss"); | |
87 | private TraceModelImplFactory fact; | |
88 | ||
72eda778 ASL |
89 | // ======================================================================== |
90 | // Inner Classes | |
91 | // ======================================================================== | |
f6281059 ASL |
92 | /* |
93 | * The content provider class is responsible for providing objects to the | |
94 | * view. It can wrap existing objects in adapters or simply return objects | |
95 | * as-is. These objects may be sensitive to the current input of the view, | |
96 | * or ignore it and always show the same content (like Task List, for | |
97 | * example). | |
98 | */ | |
99 | ||
100 | class TreeObject implements IAdaptable { | |
101 | private String name; | |
102 | private TreeParent parent; | |
103 | ||
104 | public TreeObject(String name) { | |
105 | this.name = name; | |
106 | } | |
107 | ||
108 | public String getName() { | |
109 | return name; | |
110 | } | |
111 | ||
112 | public void setParent(TreeParent parent) { | |
113 | this.parent = parent; | |
114 | } | |
115 | ||
116 | public TreeParent getParent() { | |
117 | return parent; | |
118 | } | |
119 | ||
8f50c396 | 120 | @Override |
f6281059 ASL |
121 | public String toString() { |
122 | return getName(); | |
123 | } | |
124 | ||
d4011df2 | 125 | @Override |
f6281059 ASL |
126 | @SuppressWarnings("rawtypes") |
127 | public Object getAdapter(Class key) { | |
128 | return null; | |
129 | } | |
130 | } | |
131 | ||
132 | class TreeParent extends TreeObject { | |
133 | private ArrayList<TreeObject> children; | |
134 | ||
135 | public TreeParent(String name) { | |
136 | super(name); | |
137 | children = new ArrayList<TreeObject>(); | |
138 | } | |
139 | ||
140 | public void addChild(TreeObject child) { | |
141 | children.add(child); | |
142 | child.setParent(this); | |
143 | } | |
144 | ||
145 | public void removeChild(TreeObject child) { | |
146 | children.remove(child); | |
147 | child.setParent(null); | |
148 | } | |
149 | ||
150 | public TreeObject[] getChildren() { | |
151 | return children.toArray(new TreeObject[children | |
152 | .size()]); | |
153 | } | |
154 | ||
155 | public boolean hasChildren() { | |
156 | return children.size() > 0; | |
157 | } | |
158 | } | |
159 | ||
160 | class ViewContentProvider implements IStructuredContentProvider, | |
161 | ITreeContentProvider { | |
162 | private TreeParent invisibleRoot; | |
163 | ||
d4011df2 | 164 | @Override |
f6281059 ASL |
165 | public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
166 | } | |
167 | ||
d4011df2 | 168 | @Override |
f6281059 ASL |
169 | public void dispose() { |
170 | } | |
171 | ||
d4011df2 | 172 | @Override |
f6281059 ASL |
173 | public Object[] getElements(Object parent) { |
174 | if (parent.equals(getViewSite())) { | |
175 | if (invisibleRoot == null) | |
176 | initialize(); | |
177 | return getChildren(invisibleRoot); | |
178 | } | |
179 | return getChildren(parent); | |
180 | } | |
181 | ||
d4011df2 | 182 | @Override |
f6281059 ASL |
183 | public Object getParent(Object child) { |
184 | if (child instanceof TreeObject) { | |
185 | return ((TreeObject) child).getParent(); | |
186 | } | |
187 | return null; | |
188 | } | |
189 | ||
d4011df2 | 190 | @Override |
f6281059 ASL |
191 | public Object[] getChildren(Object parent) { |
192 | if (parent instanceof TreeParent) { | |
193 | return ((TreeParent) parent).getChildren(); | |
194 | } | |
195 | return new Object[0]; | |
196 | } | |
197 | ||
d4011df2 | 198 | @Override |
f6281059 ASL |
199 | public boolean hasChildren(Object parent) { |
200 | if (parent instanceof TreeParent) | |
201 | return ((TreeParent) parent).hasChildren(); | |
202 | return false; | |
203 | } | |
204 | ||
205 | /* | |
206 | * We will set up a dummy model to initialize tree heararchy. In a real | |
207 | * code, you will connect to a real model and expose its hierarchy. | |
208 | */ | |
209 | private void initialize() { | |
210 | TreeObject to1 = new TreeObject("Leaf 1"); | |
211 | TreeObject to2 = new TreeObject("Leaf 2"); | |
212 | TreeObject to3 = new TreeObject("Leaf 3"); | |
213 | TreeParent p1 = new TreeParent("Parent 1"); | |
214 | p1.addChild(to1); | |
215 | p1.addChild(to2); | |
216 | p1.addChild(to3); | |
217 | ||
218 | TreeObject to4 = new TreeObject("Leaf 4"); | |
219 | TreeParent p2 = new TreeParent("Parent 2"); | |
220 | p2.addChild(to4); | |
221 | ||
222 | TreeParent root = new TreeParent("Root"); | |
223 | root.addChild(p1); | |
224 | root.addChild(p2); | |
225 | ||
226 | invisibleRoot = new TreeParent(""); | |
227 | invisibleRoot.addChild(root); | |
228 | } | |
229 | } | |
230 | ||
1f2f091b | 231 | static class ViewLabelProvider extends LabelProvider { |
f6281059 | 232 | |
8f50c396 | 233 | @Override |
f6281059 ASL |
234 | public String getText(Object obj) { |
235 | return obj.toString(); | |
236 | } | |
237 | ||
8f50c396 | 238 | @Override |
f6281059 ASL |
239 | public Image getImage(Object obj) { |
240 | String imageKey = ISharedImages.IMG_OBJ_ELEMENT; | |
241 | if (obj instanceof TreeParent) | |
242 | imageKey = ISharedImages.IMG_OBJ_FOLDER; | |
243 | return PlatformUI.getWorkbench().getSharedImages().getImage( | |
244 | imageKey); | |
245 | } | |
246 | } | |
247 | ||
1f2f091b | 248 | static class NameSorter extends ViewerSorter { |
f6281059 ASL |
249 | } |
250 | ||
72eda778 ASL |
251 | // ======================================================================== |
252 | // Methods | |
253 | // ======================================================================== | |
f6281059 ASL |
254 | /** |
255 | * This is a callback that will allow us to create the viewer and initialize | |
256 | * it. | |
257 | */ | |
8f50c396 | 258 | @Override |
f6281059 ASL |
259 | public void createPartControl(Composite parent) { |
260 | final SashForm sashForm = new SashForm(parent, SWT.NONE); | |
261 | final SashForm sashForm2 = new SashForm(sashForm, SWT.NONE); | |
262 | ||
fb5cad3d PT |
263 | tsfviewer = new TimeGraphViewer(sashForm2, SWT.NONE); |
264 | tsfviewer.setTimeGraphProvider(new TsfImplProvider()); | |
265 | tsfviewer2 = new TimeGraphViewer(sashForm2, SWT.NONE); | |
266 | tsfviewer2.setTimeGraphProvider(new TsfImplProvider()); | |
f6281059 ASL |
267 | |
268 | viewer = new TreeViewer(sashForm, SWT.MULTI | SWT.H_SCROLL | |
269 | | SWT.V_SCROLL); | |
270 | drillDownAdapter = new DrillDownAdapter(viewer); | |
271 | viewer.setContentProvider(new ViewContentProvider()); | |
272 | viewer.setLabelProvider(new ViewLabelProvider()); | |
273 | viewer.setSorter(new NameSorter()); | |
274 | viewer.setInput(getViewSite()); | |
275 | ||
276 | sashForm.setWeights(new int[] { 5, 1 }); | |
277 | sashForm2.setWeights(new int[] { 1, 1 }); | |
278 | ||
279 | fact = new TraceModelImplFactory(); | |
fb5cad3d PT |
280 | ITimeGraphEntry[] traceArr = fact.createTraces(); |
281 | tsfviewer.setInput(traceArr); | |
282 | tsfviewer.addSelectionListener(this); | |
283 | tsfviewer.addRangeListener(this); | |
f6281059 ASL |
284 | tsfviewer.setTimeCalendarFormat(true); |
285 | ||
fb5cad3d PT |
286 | tsfviewer2.setInput(traceArr); |
287 | tsfviewer2.addSelectionListener(this); | |
288 | tsfviewer2.addRangeListener(this); | |
289 | // tsfviewer2.setTimeFormat(TimeGraphViewer.timeFormat.epoch); | |
f6281059 ASL |
290 | |
291 | makeActions(); | |
292 | hookContextMenu(); | |
293 | hookDoubleClickAction(); | |
294 | contributeToActionBars(); | |
295 | } | |
296 | ||
297 | private void hookContextMenu() { | |
298 | MenuManager menuMgr = new MenuManager("#PopupMenu"); | |
299 | menuMgr.setRemoveAllWhenShown(true); | |
300 | menuMgr.addMenuListener(new IMenuListener() { | |
d4011df2 | 301 | @Override |
f6281059 ASL |
302 | public void menuAboutToShow(IMenuManager manager) { |
303 | TsfTraceAnalysisView.this.fillContextMenu(manager); | |
304 | } | |
305 | }); | |
306 | Menu menu = menuMgr.createContextMenu(viewer.getControl()); | |
307 | viewer.getControl().setMenu(menu); | |
308 | getSite().registerContextMenu(menuMgr, viewer); | |
309 | } | |
310 | ||
311 | private void contributeToActionBars() { | |
312 | IActionBars bars = getViewSite().getActionBars(); | |
313 | fillLocalPullDown(bars.getMenuManager()); | |
314 | fillLocalToolBar(bars.getToolBarManager()); | |
315 | } | |
316 | ||
317 | private void fillLocalPullDown(IMenuManager manager) { | |
318 | manager.add(action1); | |
319 | manager.add(new Separator()); | |
320 | manager.add(action2); | |
321 | } | |
322 | ||
323 | private void fillContextMenu(IMenuManager manager) { | |
324 | manager.add(action1); | |
325 | manager.add(action2); | |
326 | manager.add(new Separator()); | |
327 | drillDownAdapter.addNavigationActions(manager); | |
328 | // Other plug-ins can contribute there actions here | |
329 | manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); | |
330 | } | |
331 | ||
332 | private void fillLocalToolBar(IToolBarManager manager) { | |
333 | manager.add(new Separator()); | |
f6281059 ASL |
334 | manager.add(resetScale); |
335 | manager.add(nextEvent); | |
336 | manager.add(prevEvent); | |
337 | manager.add(nextTrace); | |
338 | manager.add(prevTrace); | |
339 | manager.add(showLegent); | |
f6281059 ASL |
340 | manager.add(zoomIn); |
341 | manager.add(zoomOut); | |
f6281059 ASL |
342 | manager.add(events300K); |
343 | manager.add(new Separator()); | |
344 | ||
345 | drillDownAdapter.addNavigationActions(manager); | |
346 | } | |
347 | ||
fb5cad3d PT |
348 | private TimeGraphViewer getActiveTsfCtrl() { |
349 | TimeGraphViewer inFocusViewer = null; | |
f6281059 ASL |
350 | if (tsfviewer.isInFocus()) |
351 | inFocusViewer = tsfviewer; | |
352 | else if (tsfviewer2.isInFocus()) | |
353 | inFocusViewer = tsfviewer2; | |
354 | return inFocusViewer; | |
355 | } | |
356 | ||
357 | private void makeActions() { | |
358 | // action1 | |
359 | action1 = new Action() { | |
8f50c396 | 360 | @Override |
f6281059 ASL |
361 | public void run() { |
362 | showMessage("Action 1 executed"); | |
363 | } | |
364 | }; | |
365 | action1.setText("Action 1"); | |
366 | action1.setToolTipText("Action 1 tooltip"); | |
367 | action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() | |
368 | .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); | |
369 | ||
370 | // action2 | |
371 | action2 = new Action() { | |
8f50c396 | 372 | @Override |
f6281059 ASL |
373 | public void run() { |
374 | showMessage("Action 2 executed"); | |
375 | } | |
376 | }; | |
377 | action2.setText("Action 2"); | |
378 | action2.setToolTipText("Action 2 tooltip"); | |
379 | action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() | |
380 | .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); | |
381 | ||
f6281059 ASL |
382 | // action4 |
383 | resetScale = new Action() { | |
8f50c396 | 384 | @Override |
f6281059 | 385 | public void run() { |
fb5cad3d | 386 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 ASL |
387 | if (inFocusViewer != null) { |
388 | inFocusViewer.resetStartFinishTime(); | |
389 | } | |
390 | ||
391 | } | |
392 | }; | |
393 | resetScale.setText("Reset"); | |
394 | resetScale.setToolTipText("Reset the Time Scale to Default"); | |
395 | ||
396 | // action5 | |
397 | nextEvent = new Action() { | |
8f50c396 | 398 | @Override |
f6281059 | 399 | public void run() { |
fb5cad3d | 400 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 ASL |
401 | if (inFocusViewer != null) { |
402 | inFocusViewer.selectNextEvent(); | |
403 | } | |
404 | } | |
405 | }; | |
406 | nextEvent.setText("NextEv"); | |
407 | nextEvent.setToolTipText("Next Event"); | |
408 | ||
409 | // action6 | |
410 | prevEvent = new Action() { | |
8f50c396 | 411 | @Override |
f6281059 | 412 | public void run() { |
fb5cad3d | 413 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 ASL |
414 | if (inFocusViewer != null) { |
415 | inFocusViewer.selectPrevEvent(); | |
416 | } | |
417 | } | |
418 | }; | |
419 | prevEvent.setText("PrevEv"); | |
420 | prevEvent.setToolTipText("Previous Event"); | |
421 | ||
422 | // action7 | |
423 | nextTrace = new Action() { | |
8f50c396 | 424 | @Override |
f6281059 | 425 | public void run() { |
fb5cad3d | 426 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 | 427 | if (inFocusViewer != null) { |
f7e7159c | 428 | inFocusViewer.selectNextTrace(); |
f6281059 ASL |
429 | } |
430 | } | |
431 | }; | |
432 | nextTrace.setText("NextTrace"); | |
433 | nextTrace.setToolTipText("Select Next Event"); | |
434 | ||
435 | // action8 | |
436 | prevTrace = new Action() { | |
8f50c396 | 437 | @Override |
f6281059 | 438 | public void run() { |
fb5cad3d | 439 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 | 440 | if (inFocusViewer != null) { |
f7e7159c | 441 | inFocusViewer.selectPrevTrace(); |
f6281059 ASL |
442 | } |
443 | } | |
444 | }; | |
445 | prevTrace.setText("PrevTrace"); | |
446 | prevTrace.setToolTipText("Select Previous Trace"); | |
447 | ||
448 | // action9 | |
449 | showLegent = new Action() { | |
8f50c396 | 450 | @Override |
f6281059 | 451 | public void run() { |
fb5cad3d | 452 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 ASL |
453 | if (inFocusViewer != null) { |
454 | inFocusViewer.showLegend(); | |
455 | } | |
456 | } | |
457 | }; | |
458 | showLegent.setText("Legend"); | |
459 | showLegent.setToolTipText("Show Legend"); | |
460 | ||
f6281059 ASL |
461 | // action10 |
462 | zoomIn = new Action() { | |
8f50c396 | 463 | @Override |
f6281059 | 464 | public void run() { |
fb5cad3d | 465 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 ASL |
466 | if (inFocusViewer != null) { |
467 | inFocusViewer.zoomIn(); | |
468 | } | |
469 | } | |
470 | }; | |
471 | zoomIn.setText("Zoom In"); | |
472 | zoomIn.setToolTipText("Zoom In"); | |
473 | ||
474 | // action10 | |
475 | zoomOut = new Action() { | |
8f50c396 | 476 | @Override |
f6281059 | 477 | public void run() { |
fb5cad3d | 478 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 ASL |
479 | if (inFocusViewer != null) { |
480 | inFocusViewer.zoomOut(); | |
481 | } | |
482 | // ISelection selection = inFocusViewer.getSelection(); | |
483 | // Object sel = null; | |
484 | // if (selection != null && !selection.isEmpty()) { | |
485 | // sel = ((IStructuredSelection) selection) | |
486 | // .getFirstElement(); | |
487 | // if (sel instanceof EventImpl) { | |
488 | // EventImpl event = (EventImpl) sel; | |
489 | // inFocusViewer.selectNextEvent(); | |
490 | // } | |
491 | // } | |
492 | } | |
493 | }; | |
494 | zoomOut.setText("Zoom Out"); | |
495 | zoomOut.setToolTipText("Zoom Out"); | |
496 | ||
f6281059 ASL |
497 | // action12 |
498 | events300K = new Action() { | |
8f50c396 | 499 | @Override |
f6281059 | 500 | public void run() { |
fb5cad3d | 501 | TimeGraphViewer inFocusViewer = getActiveTsfCtrl(); |
f6281059 | 502 | if (inFocusViewer != null) { |
fb5cad3d | 503 | ITimeGraphEntry[] traceArr = fact |
f6281059 | 504 | .createLargeTraces(60); |
fb5cad3d | 505 | inFocusViewer.setInput(traceArr); |
f6281059 ASL |
506 | } |
507 | } | |
508 | }; | |
509 | events300K.setText("300K Events"); | |
510 | events300K.setToolTipText("Add 300K Events"); | |
511 | ||
512 | doubleClickAction = new Action() { | |
8f50c396 | 513 | @Override |
f6281059 ASL |
514 | public void run() { |
515 | ISelection selection = viewer.getSelection(); | |
516 | Object obj = ((IStructuredSelection) selection) | |
517 | .getFirstElement(); | |
518 | showMessage("Double-click detected on " + obj.toString()); | |
519 | } | |
520 | }; | |
521 | } | |
522 | ||
523 | private void hookDoubleClickAction() { | |
524 | viewer.addDoubleClickListener(new IDoubleClickListener() { | |
d4011df2 | 525 | @Override |
f6281059 ASL |
526 | public void doubleClick(DoubleClickEvent event) { |
527 | doubleClickAction.run(); | |
528 | } | |
529 | }); | |
530 | } | |
531 | ||
532 | private void showMessage(String message) { | |
533 | MessageDialog.openInformation(viewer.getControl().getShell(), | |
534 | "TsfTrace Analysis View", message); | |
535 | } | |
536 | ||
537 | /** | |
538 | * Passing the focus request to the viewer's control. | |
539 | */ | |
8f50c396 | 540 | @Override |
f6281059 ASL |
541 | public void setFocus() { |
542 | viewer.getControl().setFocus(); | |
543 | } | |
544 | ||
ce62370f | 545 | @Override |
fb5cad3d | 546 | public void selectionChanged(TimeGraphSelectionEvent event) { |
f6281059 | 547 | Object source = event.getSource(); |
fb5cad3d | 548 | if (source == null || !(source instanceof TimeGraphViewer)) { |
f6281059 ASL |
549 | return; |
550 | } | |
551 | ||
fb5cad3d PT |
552 | TimeGraphViewer rViewer = (TimeGraphViewer) event.getSource(); |
553 | TimeGraphViewer synchViewer = null; | |
f6281059 ASL |
554 | // Synchronize viewer selections if Enabled, |
555 | // make sure the selection does not go in loops | |
556 | if (tsfviewer == rViewer) { | |
557 | synchViewer = tsfviewer2; | |
558 | } else { | |
559 | synchViewer = tsfviewer; | |
560 | } | |
561 | Object selection = event.getSelection(); | |
562 | ||
f6281059 ASL |
563 | if (selection instanceof EventImpl) { |
564 | EventImpl selEvent = (EventImpl) selection; | |
f6281059 | 565 | System.out |
fb5cad3d | 566 | .println("TsfTraceAnalysisView.selectionChanged() Selected Event: \nType: " |
f6281059 ASL |
567 | + selEvent.getType().toString() |
568 | + "\nTime: " | |
569 | + selEvent.getTime() | |
570 | + "\nTrace Name: " | |
fb5cad3d | 571 | + selEvent.getEntry().getName()); |
f6281059 ASL |
572 | |
573 | synchViewer.setSelectedEvent(selEvent, source); | |
574 | ||
575 | } else if (selection instanceof TraceImpl) { | |
576 | TraceImpl selTrace = (TraceImpl) selection; | |
577 | System.out | |
fb5cad3d | 578 | .println("TsfTraceAnalysisView.selectionChanged() Selected Trace: \nName: " |
f6281059 ASL |
579 | + selTrace.getName().toString() |
580 | + "\nClass Name: " | |
fb5cad3d PT |
581 | + selTrace.getClassName()); |
582 | ||
583 | synchViewer.setSelection(selTrace); | |
f6281059 ASL |
584 | } else { |
585 | System.out | |
586 | .println("TsfTmIncubatorListener.tsfTmProcessEvent() Unexpected event source received: " | |
587 | + selection.getClass().getName()); | |
588 | } | |
589 | ||
590 | } | |
591 | ||
fb5cad3d PT |
592 | @Override |
593 | public void timeSelected(TimeGraphTimeEvent event) { | |
594 | TimeGraphViewer rViewer = (TimeGraphViewer) event.getSource(); | |
595 | TimeGraphViewer synchViewer = null; | |
596 | // Synchronize viewer selections if Enabled, | |
597 | // make sure the selection does not go in loops | |
598 | if (tsfviewer == rViewer) { | |
599 | synchViewer = tsfviewer2; | |
600 | } else { | |
601 | synchViewer = tsfviewer; | |
602 | } | |
603 | long selTimens = event.getTime(); | |
604 | long tms = (long) (selTimens * 1E-6); | |
605 | Date date = new Date(tms); | |
606 | String fDate = stimeformat.format(date); | |
607 | String ns = formatNs(selTimens); | |
608 | ||
609 | System.out.println("TsfTraceAnalysisView.timeSelected() Selected Event: \nTime: " | |
610 | + event.getTime() | |
611 | + "\nSelected Time: " | |
612 | + selTimens + " " + fDate + " " + ns); | |
613 | ||
614 | synchViewer.setSelectedTime(event.getTime(), true, event.getSource()); | |
615 | } | |
616 | ||
617 | @Override | |
618 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { | |
f9a8715c FC |
619 | if (event == null) |
620 | return; | |
f6281059 | 621 | Object source = event.getSource(); |
fb5cad3d | 622 | if (source == null || !(source instanceof TimeGraphViewer)) { |
f6281059 ASL |
623 | return; |
624 | } | |
625 | ||
fb5cad3d PT |
626 | if (event instanceof TimeGraphRangeUpdateEvent) { |
627 | TimeGraphRangeUpdateEvent rEvent = (TimeGraphRangeUpdateEvent) event; | |
628 | TimeGraphViewer rViewer = (TimeGraphViewer) event | |
f6281059 | 629 | .getSource(); |
fb5cad3d | 630 | TimeGraphViewer synchViewer = null; |
f6281059 ASL |
631 | // Synchronize viewer selections if Enabled, |
632 | // make sure the selection does not go in loops | |
633 | if (tsfviewer == rViewer) { | |
634 | synchViewer = tsfviewer2; | |
635 | } else { | |
636 | synchViewer = tsfviewer; | |
637 | } | |
638 | ||
639 | ||
fb5cad3d PT |
640 | synchViewer.setSelectVisTimeWindow(rEvent.getStartTime(), rEvent |
641 | .getEndTime(), source); | |
f6281059 ASL |
642 | } |
643 | } | |
644 | ||
645 | /** | |
646 | * Obtains the remainder fraction on unit Seconds of the entered value in | |
647 | * nanoseconds. e.g. input: 1241207054171080214 ns The number of seconds can | |
648 | * be obtain by removing the last 9 digits: 1241207054 the fractional | |
649 | * portion of seconds, expressed in ns is: 171080214 | |
650 | * | |
651 | * @param v | |
652 | * @return | |
653 | */ | |
654 | public String formatNs(long v) { | |
655 | StringBuffer str = new StringBuffer(); | |
656 | boolean neg = v < 0; | |
657 | if (neg) { | |
658 | v = -v; | |
659 | str.append('-'); | |
660 | } | |
661 | ||
662 | String strVal = String.valueOf(v); | |
663 | if (v < 1000000000) { | |
664 | return strVal; | |
665 | } | |
666 | ||
667 | // Extract the last nine digits (e.g. fraction of a S expressed in ns | |
668 | return strVal.substring(strVal.length() - 9); | |
669 | } | |
670 | } |