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