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