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