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 | *******************************************************************************/ | |
f6281059 ASL |
12 | package org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.views; |
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; | |
36 | import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewerFactory; | |
37 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer; | |
38 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeSelectionListener; | |
39 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent; | |
40 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent; | |
41 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeScaleSelectionListener; | |
42 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; | |
43 | import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.adaption.TsfImplProvider; | |
44 | import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.EventImpl; | |
45 | import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.TraceImpl; | |
46 | import org.eclipse.linuxtools.tmf.ui.widgets.timeAnalysis.test.stub.model.TraceModelImplFactory; | |
47 | import org.eclipse.swt.SWT; | |
48 | import org.eclipse.swt.custom.SashForm; | |
49 | import org.eclipse.swt.graphics.Image; | |
50 | import org.eclipse.swt.widgets.Composite; | |
51 | import org.eclipse.swt.widgets.Menu; | |
52 | import org.eclipse.ui.IActionBars; | |
53 | import org.eclipse.ui.ISharedImages; | |
54 | import org.eclipse.ui.IWorkbenchActionConstants; | |
55 | import org.eclipse.ui.PlatformUI; | |
56 | import org.eclipse.ui.part.DrillDownAdapter; | |
57 | import org.eclipse.ui.part.ViewPart; | |
58 | ||
59 | public class TsfTraceAnalysisView extends ViewPart implements | |
60 | ITmfTimeSelectionListener, ITmfTimeScaleSelectionListener { | |
72eda778 ASL |
61 | |
62 | // ======================================================================== | |
63 | // Data | |
64 | // ======================================================================== | |
f6281059 ASL |
65 | private TreeViewer viewer; |
66 | private DrillDownAdapter drillDownAdapter; | |
67 | private Action action1; | |
68 | private Action action2; | |
69 | private Action actGroup; | |
70 | private Action resetScale; | |
71 | private Action nextEvent; | |
72 | private Action prevEvent; | |
73 | private Action nextTrace; | |
74 | private Action prevTrace; | |
75 | private Action showLegent; | |
76 | private Action filterTraces; | |
77 | private Action zoomIn; | |
78 | private Action zoomOut; | |
79 | private Action synch; | |
80 | private Action events300K; | |
81 | ||
82 | private Action doubleClickAction; | |
83 | private ITimeAnalysisViewer tsfviewer; | |
84 | private ITimeAnalysisViewer tsfviewer2; | |
85 | ||
86 | private static SimpleDateFormat stimeformat = new SimpleDateFormat( | |
87 | "yy/MM/dd HH:mm:ss"); | |
88 | private TraceModelImplFactory fact; | |
89 | ||
72eda778 ASL |
90 | // ======================================================================== |
91 | // Inner Classes | |
92 | // ======================================================================== | |
f6281059 ASL |
93 | /* |
94 | * The content provider class is responsible for providing objects to the | |
95 | * view. It can wrap existing objects in adapters or simply return objects | |
96 | * as-is. These objects may be sensitive to the current input of the view, | |
97 | * or ignore it and always show the same content (like Task List, for | |
98 | * example). | |
99 | */ | |
100 | ||
101 | class TreeObject implements IAdaptable { | |
102 | private String name; | |
103 | private TreeParent parent; | |
104 | ||
105 | public TreeObject(String name) { | |
106 | this.name = name; | |
107 | } | |
108 | ||
109 | public String getName() { | |
110 | return name; | |
111 | } | |
112 | ||
113 | public void setParent(TreeParent parent) { | |
114 | this.parent = parent; | |
115 | } | |
116 | ||
117 | public TreeParent getParent() { | |
118 | return parent; | |
119 | } | |
120 | ||
8f50c396 | 121 | @Override |
f6281059 ASL |
122 | public String toString() { |
123 | return getName(); | |
124 | } | |
125 | ||
d4011df2 | 126 | @Override |
f6281059 ASL |
127 | @SuppressWarnings("rawtypes") |
128 | public Object getAdapter(Class key) { | |
129 | return null; | |
130 | } | |
131 | } | |
132 | ||
133 | class TreeParent extends TreeObject { | |
134 | private ArrayList<TreeObject> children; | |
135 | ||
136 | public TreeParent(String name) { | |
137 | super(name); | |
138 | children = new ArrayList<TreeObject>(); | |
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 IStructuredContentProvider, | |
162 | ITreeContentProvider { | |
163 | private TreeParent invisibleRoot; | |
164 | ||
d4011df2 | 165 | @Override |
f6281059 ASL |
166 | public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
167 | } | |
168 | ||
d4011df2 | 169 | @Override |
f6281059 ASL |
170 | public void dispose() { |
171 | } | |
172 | ||
d4011df2 | 173 | @Override |
f6281059 ASL |
174 | public Object[] getElements(Object parent) { |
175 | if (parent.equals(getViewSite())) { | |
176 | if (invisibleRoot == null) | |
177 | initialize(); | |
178 | return getChildren(invisibleRoot); | |
179 | } | |
180 | return getChildren(parent); | |
181 | } | |
182 | ||
d4011df2 | 183 | @Override |
f6281059 ASL |
184 | public Object getParent(Object child) { |
185 | if (child instanceof TreeObject) { | |
186 | return ((TreeObject) child).getParent(); | |
187 | } | |
188 | return null; | |
189 | } | |
190 | ||
d4011df2 | 191 | @Override |
f6281059 ASL |
192 | public Object[] getChildren(Object parent) { |
193 | if (parent instanceof TreeParent) { | |
194 | return ((TreeParent) parent).getChildren(); | |
195 | } | |
196 | return new Object[0]; | |
197 | } | |
198 | ||
d4011df2 | 199 | @Override |
f6281059 ASL |
200 | public boolean hasChildren(Object parent) { |
201 | if (parent instanceof TreeParent) | |
202 | return ((TreeParent) parent).hasChildren(); | |
203 | return false; | |
204 | } | |
205 | ||
206 | /* | |
207 | * We will set up a dummy model to initialize tree heararchy. In a real | |
208 | * code, you will connect to a real model and expose its hierarchy. | |
209 | */ | |
210 | private void initialize() { | |
211 | TreeObject to1 = new TreeObject("Leaf 1"); | |
212 | TreeObject to2 = new TreeObject("Leaf 2"); | |
213 | TreeObject to3 = new TreeObject("Leaf 3"); | |
214 | TreeParent p1 = new TreeParent("Parent 1"); | |
215 | p1.addChild(to1); | |
216 | p1.addChild(to2); | |
217 | p1.addChild(to3); | |
218 | ||
219 | TreeObject to4 = new TreeObject("Leaf 4"); | |
220 | TreeParent p2 = new TreeParent("Parent 2"); | |
221 | p2.addChild(to4); | |
222 | ||
223 | TreeParent root = new TreeParent("Root"); | |
224 | root.addChild(p1); | |
225 | root.addChild(p2); | |
226 | ||
227 | invisibleRoot = new TreeParent(""); | |
228 | invisibleRoot.addChild(root); | |
229 | } | |
230 | } | |
231 | ||
232 | class ViewLabelProvider extends LabelProvider { | |
233 | ||
8f50c396 | 234 | @Override |
f6281059 ASL |
235 | public String getText(Object obj) { |
236 | return obj.toString(); | |
237 | } | |
238 | ||
8f50c396 | 239 | @Override |
f6281059 ASL |
240 | public Image getImage(Object obj) { |
241 | String imageKey = ISharedImages.IMG_OBJ_ELEMENT; | |
242 | if (obj instanceof TreeParent) | |
243 | imageKey = ISharedImages.IMG_OBJ_FOLDER; | |
244 | return PlatformUI.getWorkbench().getSharedImages().getImage( | |
245 | imageKey); | |
246 | } | |
247 | } | |
248 | ||
249 | class NameSorter extends ViewerSorter { | |
250 | } | |
251 | ||
72eda778 ASL |
252 | // ======================================================================== |
253 | // Methods | |
254 | // ======================================================================== | |
f6281059 ASL |
255 | /** |
256 | * This is a callback that will allow us to create the viewer and initialize | |
257 | * it. | |
258 | */ | |
8f50c396 | 259 | @Override |
f6281059 ASL |
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 = TmfViewerFactory.createViewer(sashForm2, | |
265 | new TsfImplProvider()); | |
266 | tsfviewer2 = TmfViewerFactory.createViewer(sashForm2, | |
267 | 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 | ITmfTimeAnalysisEntry[] traceArr = fact.createTraces(); | |
282 | tsfviewer.display(traceArr); | |
283 | tsfviewer.addWidgetSelectionListner(this); | |
284 | tsfviewer.addWidgetTimeScaleSelectionListner(this); | |
285 | tsfviewer.setTimeCalendarFormat(true); | |
286 | ||
287 | tsfviewer2.display(traceArr); | |
288 | tsfviewer2.addWidgetSelectionListner(this); | |
289 | tsfviewer2.addWidgetTimeScaleSelectionListner(this); | |
290 | // tsfviewer2.setTimeFormat(ITimeAnalysisViewer.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() { | |
d4011df2 | 302 | @Override |
f6281059 ASL |
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(actGroup); | |
336 | manager.add(resetScale); | |
337 | manager.add(nextEvent); | |
338 | manager.add(prevEvent); | |
339 | manager.add(nextTrace); | |
340 | manager.add(prevTrace); | |
341 | manager.add(showLegent); | |
342 | manager.add(filterTraces); | |
343 | manager.add(zoomIn); | |
344 | manager.add(zoomOut); | |
345 | manager.add(synch); | |
346 | manager.add(events300K); | |
347 | manager.add(new Separator()); | |
348 | ||
349 | drillDownAdapter.addNavigationActions(manager); | |
350 | } | |
351 | ||
352 | private ITimeAnalysisViewer getActiveTsfCtrl() { | |
353 | ITimeAnalysisViewer inFocusViewer = null; | |
354 | if (tsfviewer.isInFocus()) | |
355 | inFocusViewer = tsfviewer; | |
356 | else if (tsfviewer2.isInFocus()) | |
357 | inFocusViewer = tsfviewer2; | |
358 | return inFocusViewer; | |
359 | } | |
360 | ||
361 | private void makeActions() { | |
362 | // action1 | |
363 | action1 = new Action() { | |
8f50c396 | 364 | @Override |
f6281059 ASL |
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() { | |
8f50c396 | 376 | @Override |
f6281059 ASL |
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 | // action3 | |
387 | actGroup = new Action() { | |
8f50c396 | 388 | @Override |
f6281059 ASL |
389 | public void run() { |
390 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
391 | if (inFocusViewer != null) { | |
392 | if (actGroup.isChecked()) { | |
393 | inFocusViewer.groupTraces(false); | |
394 | } else { | |
395 | inFocusViewer.groupTraces(true); | |
396 | } | |
397 | } | |
398 | } | |
399 | }; | |
400 | actGroup.setText("Group"); | |
401 | actGroup.setToolTipText("Groupped or flat list"); | |
402 | actGroup.setChecked(true); | |
403 | ||
404 | // action4 | |
405 | resetScale = new Action() { | |
8f50c396 | 406 | @Override |
f6281059 ASL |
407 | public void run() { |
408 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
409 | if (inFocusViewer != null) { | |
410 | inFocusViewer.resetStartFinishTime(); | |
411 | } | |
412 | ||
413 | } | |
414 | }; | |
415 | resetScale.setText("Reset"); | |
416 | resetScale.setToolTipText("Reset the Time Scale to Default"); | |
417 | ||
418 | // action5 | |
419 | nextEvent = new Action() { | |
8f50c396 | 420 | @Override |
f6281059 ASL |
421 | public void run() { |
422 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
423 | if (inFocusViewer != null) { | |
424 | inFocusViewer.selectNextEvent(); | |
425 | } | |
426 | } | |
427 | }; | |
428 | nextEvent.setText("NextEv"); | |
429 | nextEvent.setToolTipText("Next Event"); | |
430 | ||
431 | // action6 | |
432 | prevEvent = new Action() { | |
8f50c396 | 433 | @Override |
f6281059 ASL |
434 | public void run() { |
435 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
436 | if (inFocusViewer != null) { | |
437 | inFocusViewer.selectPrevEvent(); | |
438 | } | |
439 | } | |
440 | }; | |
441 | prevEvent.setText("PrevEv"); | |
442 | prevEvent.setToolTipText("Previous Event"); | |
443 | ||
444 | // action7 | |
445 | nextTrace = new Action() { | |
8f50c396 | 446 | @Override |
f6281059 ASL |
447 | public void run() { |
448 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
449 | if (inFocusViewer != null) { | |
450 | inFocusViewer.selectNextTrace(); | |
451 | } | |
452 | } | |
453 | }; | |
454 | nextTrace.setText("NextTrace"); | |
455 | nextTrace.setToolTipText("Select Next Event"); | |
456 | ||
457 | // action8 | |
458 | prevTrace = new Action() { | |
8f50c396 | 459 | @Override |
f6281059 ASL |
460 | public void run() { |
461 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
462 | if (inFocusViewer != null) { | |
463 | inFocusViewer.selectPrevTrace(); | |
464 | } | |
465 | } | |
466 | }; | |
467 | prevTrace.setText("PrevTrace"); | |
468 | prevTrace.setToolTipText("Select Previous Trace"); | |
469 | ||
470 | // action9 | |
471 | showLegent = new Action() { | |
8f50c396 | 472 | @Override |
f6281059 ASL |
473 | public void run() { |
474 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
475 | if (inFocusViewer != null) { | |
476 | inFocusViewer.showLegend(); | |
477 | } | |
478 | } | |
479 | }; | |
480 | showLegent.setText("Legend"); | |
481 | showLegent.setToolTipText("Show Legend"); | |
482 | ||
483 | // action10 | |
484 | filterTraces = new Action() { | |
8f50c396 | 485 | @Override |
f6281059 ASL |
486 | public void run() { |
487 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
488 | if (inFocusViewer != null) { | |
489 | inFocusViewer.filterTraces(); | |
490 | } | |
491 | } | |
492 | }; | |
493 | filterTraces.setText("Filter"); | |
494 | filterTraces.setToolTipText("Trace Filter options"); | |
495 | ||
496 | // action10 | |
497 | zoomIn = new Action() { | |
8f50c396 | 498 | @Override |
f6281059 ASL |
499 | public void run() { |
500 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
501 | if (inFocusViewer != null) { | |
502 | inFocusViewer.zoomIn(); | |
503 | } | |
504 | } | |
505 | }; | |
506 | zoomIn.setText("Zoom In"); | |
507 | zoomIn.setToolTipText("Zoom In"); | |
508 | ||
509 | // action10 | |
510 | zoomOut = new Action() { | |
8f50c396 | 511 | @Override |
f6281059 ASL |
512 | public void run() { |
513 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
514 | if (inFocusViewer != null) { | |
515 | inFocusViewer.zoomOut(); | |
516 | } | |
517 | // ISelection selection = inFocusViewer.getSelection(); | |
518 | // Object sel = null; | |
519 | // if (selection != null && !selection.isEmpty()) { | |
520 | // sel = ((IStructuredSelection) selection) | |
521 | // .getFirstElement(); | |
522 | // if (sel instanceof EventImpl) { | |
523 | // EventImpl event = (EventImpl) sel; | |
524 | // inFocusViewer.selectNextEvent(); | |
525 | // } | |
526 | // } | |
527 | } | |
528 | }; | |
529 | zoomOut.setText("Zoom Out"); | |
530 | zoomOut.setToolTipText("Zoom Out"); | |
531 | ||
532 | // action11 | |
533 | synch = new Action() { | |
8f50c396 | 534 | @Override |
f6281059 ASL |
535 | public void run() { |
536 | if (synch.isChecked()) { | |
537 | tsfviewer.setAcceptSelectionAPIcalls(true); | |
538 | tsfviewer2.setAcceptSelectionAPIcalls(true); | |
539 | } else { | |
540 | tsfviewer.setAcceptSelectionAPIcalls(false); | |
541 | tsfviewer2.setAcceptSelectionAPIcalls(false); | |
542 | } | |
543 | } | |
544 | }; | |
545 | synch.setText("Synchronize"); | |
546 | synch | |
547 | .setToolTipText("Synchronize by listening to external API selection calls"); | |
548 | synch.setChecked(false); | |
549 | ||
550 | // action12 | |
551 | events300K = new Action() { | |
8f50c396 | 552 | @Override |
f6281059 ASL |
553 | public void run() { |
554 | ITimeAnalysisViewer inFocusViewer = getActiveTsfCtrl(); | |
555 | if (inFocusViewer != null) { | |
556 | ITmfTimeAnalysisEntry[] traceArr = fact | |
557 | .createLargeTraces(60); | |
558 | inFocusViewer.display(traceArr); | |
559 | } | |
560 | } | |
561 | }; | |
562 | events300K.setText("300K Events"); | |
563 | events300K.setToolTipText("Add 300K Events"); | |
564 | ||
565 | doubleClickAction = new Action() { | |
8f50c396 | 566 | @Override |
f6281059 ASL |
567 | public void run() { |
568 | ISelection selection = viewer.getSelection(); | |
569 | Object obj = ((IStructuredSelection) selection) | |
570 | .getFirstElement(); | |
571 | showMessage("Double-click detected on " + obj.toString()); | |
572 | } | |
573 | }; | |
574 | } | |
575 | ||
576 | private void hookDoubleClickAction() { | |
577 | viewer.addDoubleClickListener(new IDoubleClickListener() { | |
d4011df2 | 578 | @Override |
f6281059 ASL |
579 | public void doubleClick(DoubleClickEvent event) { |
580 | doubleClickAction.run(); | |
581 | } | |
582 | }); | |
583 | } | |
584 | ||
585 | private void showMessage(String message) { | |
586 | MessageDialog.openInformation(viewer.getControl().getShell(), | |
587 | "TsfTrace Analysis View", message); | |
588 | } | |
589 | ||
590 | /** | |
591 | * Passing the focus request to the viewer's control. | |
592 | */ | |
8f50c396 | 593 | @Override |
f6281059 ASL |
594 | public void setFocus() { |
595 | viewer.getControl().setFocus(); | |
596 | } | |
597 | ||
d4011df2 | 598 | @Override |
f6281059 ASL |
599 | public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { |
600 | Object source = event.getSource(); | |
601 | if (source == null || !(source instanceof ITimeAnalysisViewer)) { | |
602 | return; | |
603 | } | |
604 | ||
605 | ITimeAnalysisViewer rViewer = (ITimeAnalysisViewer) event.getSource(); | |
606 | ITimeAnalysisViewer synchViewer = null; | |
607 | // Synchronize viewer selections if Enabled, | |
608 | // make sure the selection does not go in loops | |
609 | if (tsfviewer == rViewer) { | |
610 | synchViewer = tsfviewer2; | |
611 | } else { | |
612 | synchViewer = tsfviewer; | |
613 | } | |
614 | Object selection = event.getSelection(); | |
615 | ||
616 | long selTimens = event.getSelectedTime(); | |
617 | long tms = (long) (selTimens * 1E-6); | |
618 | Date date = new Date(tms); | |
619 | String fDate = stimeformat.format(date); | |
620 | String ns = formatNs(selTimens); | |
621 | ||
622 | if (selection instanceof EventImpl) { | |
623 | EventImpl selEvent = (EventImpl) selection; | |
624 | date = new Date((long) (selTimens / 1E-6)); | |
625 | System.out | |
626 | .println("TsfTmIncubatorListener.tsfTmProcessEvent() Selected Event: \nType: " | |
627 | + selEvent.getType().toString() | |
628 | + "\nTime: " | |
629 | + selEvent.getTime() | |
630 | + "\nTrace Name: " | |
631 | + selEvent.getEntry().getName() | |
632 | + "\nSelection Type: " | |
633 | + event.getDType().toString() | |
634 | + "\nSelected Time: " | |
635 | + selTimens + " " + fDate + " " + ns); | |
636 | ||
637 | synchViewer.setSelectedEvent(selEvent, source); | |
638 | ||
639 | } else if (selection instanceof TraceImpl) { | |
640 | TraceImpl selTrace = (TraceImpl) selection; | |
641 | System.out | |
642 | .println("TsfTmIncubatorListener.tsfTmProcessEvent() Selected Trace: \nName: " | |
643 | + selTrace.getName().toString() | |
644 | + "\nClass Name: " | |
645 | + selTrace.getClassName() | |
646 | + "\nNumber of Events: " | |
647 | + selTrace.getTraceEvents().size() | |
648 | + "\nSelection Type: " | |
649 | + event.getDType().toString() | |
650 | + "\nSelected Time: " | |
651 | + selTimens + " " + fDate + " " + ns); | |
652 | ||
653 | synchViewer.setSelectedTraceTime(selTrace, event.getSelectedTime(), | |
654 | source); | |
655 | } else { | |
656 | System.out | |
657 | .println("TsfTmIncubatorListener.tsfTmProcessEvent() Unexpected event source received: " | |
658 | + selection.getClass().getName()); | |
659 | } | |
660 | ||
661 | } | |
662 | ||
d4011df2 | 663 | @Override |
f6281059 ASL |
664 | public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event) { |
665 | Object source = event.getSource(); | |
666 | if (source == null || !(source instanceof ITimeAnalysisViewer)) { | |
667 | return; | |
668 | } | |
669 | ||
670 | if (event != null && event instanceof TmfTimeScaleSelectionEvent) { | |
671 | TmfTimeScaleSelectionEvent rEvent = (TmfTimeScaleSelectionEvent) event; | |
672 | ITimeAnalysisViewer rViewer = (ITimeAnalysisViewer) event | |
673 | .getSource(); | |
674 | ITimeAnalysisViewer synchViewer = null; | |
675 | // Synchronize viewer selections if Enabled, | |
676 | // make sure the selection does not go in loops | |
677 | if (tsfviewer == rViewer) { | |
678 | synchViewer = tsfviewer2; | |
679 | } else { | |
680 | synchViewer = tsfviewer; | |
681 | } | |
682 | ||
683 | ||
684 | synchViewer.setSelectVisTimeWindow(rEvent.getTime0(), rEvent | |
685 | .getTime1(), source); | |
686 | } | |
687 | } | |
688 | ||
689 | /** | |
690 | * Obtains the remainder fraction on unit Seconds of the entered value in | |
691 | * nanoseconds. e.g. input: 1241207054171080214 ns The number of seconds can | |
692 | * be obtain by removing the last 9 digits: 1241207054 the fractional | |
693 | * portion of seconds, expressed in ns is: 171080214 | |
694 | * | |
695 | * @param v | |
696 | * @return | |
697 | */ | |
698 | public String formatNs(long v) { | |
699 | StringBuffer str = new StringBuffer(); | |
700 | boolean neg = v < 0; | |
701 | if (neg) { | |
702 | v = -v; | |
703 | str.append('-'); | |
704 | } | |
705 | ||
706 | String strVal = String.valueOf(v); | |
707 | if (v < 1000000000) { | |
708 | return strVal; | |
709 | } | |
710 | ||
711 | // Extract the last nine digits (e.g. fraction of a S expressed in ns | |
712 | return strVal.substring(strVal.length() - 9); | |
713 | } | |
714 | } |