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