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