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