Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
8035003b | 2 | * Copyright (c) 2009 Ericsson |
6e512b93 ASL |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are made | |
5 | * 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: Alvaro Sanchez-Leon - Initial implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.linuxtools.lttng.ui.views.controlflow; | |
12 | ||
8035003b | 13 | import java.util.Arrays; |
6e512b93 ASL |
14 | import java.util.Vector; |
15 | ||
16 | import org.eclipse.jface.action.Action; | |
17 | import org.eclipse.jface.action.IMenuListener; | |
18 | import org.eclipse.jface.action.IMenuManager; | |
19 | import org.eclipse.jface.action.IToolBarManager; | |
20 | import org.eclipse.jface.action.MenuManager; | |
21 | import org.eclipse.jface.action.Separator; | |
22 | import org.eclipse.jface.dialogs.MessageDialog; | |
23 | import org.eclipse.jface.viewers.DoubleClickEvent; | |
24 | import org.eclipse.jface.viewers.IDoubleClickListener; | |
25 | import org.eclipse.jface.viewers.ISelection; | |
26 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
27 | import org.eclipse.jface.viewers.IStructuredContentProvider; | |
28 | import org.eclipse.jface.viewers.IStructuredSelection; | |
29 | import org.eclipse.jface.viewers.ITableLabelProvider; | |
30 | import org.eclipse.jface.viewers.LabelProvider; | |
31 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
32 | import org.eclipse.jface.viewers.StructuredViewer; | |
33 | import org.eclipse.jface.viewers.TableViewer; | |
34 | import org.eclipse.jface.viewers.Viewer; | |
35 | import org.eclipse.jface.viewers.ViewerFilter; | |
36 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; | |
8035003b ASL |
37 | import org.eclipse.linuxtools.lttng.state.StateDataRequest; |
38 | import org.eclipse.linuxtools.lttng.state.StateManager; | |
39 | import org.eclipse.linuxtools.lttng.state.evProcessor.EventProcessorProxy; | |
40 | import org.eclipse.linuxtools.lttng.state.experiment.StateExperimentManager; | |
41 | import org.eclipse.linuxtools.lttng.state.experiment.StateManagerFactory; | |
6e512b93 | 42 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; |
6e512b93 ASL |
43 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess; |
44 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeViewerProvider; | |
45 | import org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView; | |
46 | import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater; | |
8035003b | 47 | import org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor.FlowTRangeUpdateFactory; |
6e512b93 | 48 | import org.eclipse.linuxtools.lttng.ui.views.controlflow.model.FlowModelFactory; |
6e512b93 | 49 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
0b0fc881 | 50 | import org.eclipse.linuxtools.tmf.signal.TmfRangeSynchSignal; |
6e512b93 | 51 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
8035003b | 52 | import org.eclipse.linuxtools.tmf.signal.TmfSignalManager; |
6e512b93 ASL |
53 | import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal; |
54 | import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewerFactory; | |
8035003b | 55 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer; |
6e512b93 ASL |
56 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeFilterSelectionListener; |
57 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeScaleSelectionListener; | |
58 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeSelectionListener; | |
59 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeFilterSelectionEvent; | |
60 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent; | |
61 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent; | |
62 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; | |
63 | import org.eclipse.swt.SWT; | |
64 | import org.eclipse.swt.custom.SashForm; | |
65 | import org.eclipse.swt.custom.ScrolledComposite; | |
8035003b ASL |
66 | import org.eclipse.swt.events.ControlAdapter; |
67 | import org.eclipse.swt.events.ControlEvent; | |
68 | import org.eclipse.swt.events.ControlListener; | |
6e512b93 ASL |
69 | import org.eclipse.swt.events.KeyEvent; |
70 | import org.eclipse.swt.events.KeyListener; | |
71 | import org.eclipse.swt.graphics.Image; | |
72 | import org.eclipse.swt.graphics.Point; | |
73 | import org.eclipse.swt.graphics.Rectangle; | |
8035003b | 74 | import org.eclipse.swt.layout.FillLayout; |
6e512b93 ASL |
75 | import org.eclipse.swt.widgets.Composite; |
76 | import org.eclipse.swt.widgets.Display; | |
77 | import org.eclipse.swt.widgets.Menu; | |
78 | import org.eclipse.swt.widgets.ScrollBar; | |
79 | import org.eclipse.swt.widgets.Table; | |
80 | import org.eclipse.swt.widgets.TableColumn; | |
81 | import org.eclipse.swt.widgets.TableItem; | |
82 | import org.eclipse.ui.IActionBars; | |
83 | import org.eclipse.ui.IWorkbenchActionConstants; | |
84 | import org.eclipse.ui.PlatformUI; | |
85 | import org.eclipse.ui.plugin.AbstractUIPlugin; | |
86 | ||
87 | /** | |
88 | * <b><u>ControlFlowView</u></b> | |
8035003b ASL |
89 | * <p> |
90 | * TODO: Implement me. Please. | |
6e512b93 ASL |
91 | */ |
92 | /** | |
93 | * @author alvaro | |
94 | * | |
95 | */ | |
96 | public class ControlFlowView extends AbsTimeUpdateView implements | |
97 | ITmfTimeSelectionListener, ITmfTimeScaleSelectionListener, | |
98 | ITmfTimeFilterSelectionListener { | |
99 | ||
100 | public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.controlflow"; | |
101 | ||
102 | // ======================================================================== | |
103 | // Table data | |
104 | // ======================================================================== | |
105 | private final String PROCESS_COLUMN = "Process"; | |
106 | private final String BRAND_COLUMN = "Brand"; | |
107 | private final String PID_COLUMN = "PID"; | |
108 | private final String TGID_COLUMN = "TGID"; | |
109 | private final String PPID_COLUMN = "PPID"; | |
110 | private final String CPU_COLUMN = "CPU"; | |
111 | private final String BIRTH_SEC_COLUMN = "Birth sec"; | |
112 | private final String BIRTH_NSEC_COLUMN = "Birth nsec"; | |
113 | private final String TRACE = "TRACE"; | |
114 | ||
115 | private final String[] columnNames = new String[] { PROCESS_COLUMN, /* */ | |
116 | BRAND_COLUMN,/* */ | |
117 | PID_COLUMN,/* */ | |
118 | TGID_COLUMN,/* */ | |
119 | PPID_COLUMN,/* */ | |
120 | CPU_COLUMN, /* */ | |
121 | BIRTH_SEC_COLUMN,/* */ | |
122 | BIRTH_NSEC_COLUMN,/* */ | |
123 | TRACE /* */ | |
124 | }; | |
125 | ||
126 | // ======================================================================== | |
127 | // Data | |
128 | // ======================================================================== | |
129 | private TableViewer tableViewer; | |
130 | // private int totalNumItems = 0; | |
131 | // Actions | |
132 | private Action doubleClickAction; | |
133 | private Action resetScale; | |
134 | private Action nextEvent; | |
135 | private Action prevEvent; | |
136 | private Action nextTrace; | |
137 | private Action prevTrace; | |
138 | private Action showLegend; | |
139 | private Action filterTraces; | |
140 | private Action zoomIn; | |
141 | private Action zoomOut; | |
0b0fc881 | 142 | private boolean synch = true; // replaced a previous action |
6e512b93 | 143 | |
8035003b | 144 | private ITimeAnalysisViewer tsfviewer; |
6e512b93 ASL |
145 | private ViewProcessFilter tableFilter = null; |
146 | private ScrolledComposite scrollFrame = null; | |
8035003b ASL |
147 | private Composite wrapper = null; |
148 | private Composite top; | |
6e512b93 ASL |
149 | |
150 | // private static SimpleDateFormat stimeformat = new SimpleDateFormat( | |
151 | // "yy/MM/dd HH:mm:ss"); | |
152 | ||
153 | // private TraceModelImplFactory fact; | |
154 | ||
155 | // ======================================================================== | |
156 | // Methods | |
157 | // ======================================================================== | |
158 | /* | |
159 | * The content provider class is responsible for providing objects to the | |
160 | * view. It can wrap existing objects in adapters or simply return objects | |
161 | * as-is. These objects may be sensitive to the current input of the view, | |
162 | * or ignore it and always show the same content (like Task List, for | |
163 | * example). | |
164 | */ | |
165 | ||
166 | class ViewContentProvider implements | |
167 | /* ILazyContentProvider, */IStructuredContentProvider { | |
168 | private TableViewer cviewer = null; | |
169 | private ITmfTimeAnalysisEntry[] elements = null; | |
170 | ||
171 | public ViewContentProvider(TableViewer v) { | |
172 | cviewer = v; | |
173 | } | |
174 | ||
175 | public void inputChanged(Viewer v, Object oldInput, Object newInput) { | |
176 | this.elements = (ITmfTimeAnalysisEntry[]) newInput; | |
177 | if (elements != null) { | |
8035003b ASL |
178 | TraceDebug |
179 | .debug("Total number of processes provided to Control Flow view: " | |
180 | + elements.length); | |
6e512b93 ASL |
181 | } else { |
182 | TraceDebug.debug("New input = null"); | |
183 | } | |
184 | } | |
185 | ||
186 | public void dispose() { | |
187 | ||
188 | } | |
189 | ||
190 | // Needed with the use of virtual tables in order to initialize items | |
191 | // which were not initially visible. | |
192 | public void updateElement(int index) { | |
193 | cviewer.replace(elements[index], index); | |
194 | } | |
195 | ||
196 | // @Override | |
197 | public Object[] getElements(Object inputElement) { | |
8035003b | 198 | // TODO Auto-generated method stub |
6e512b93 ASL |
199 | return elements; |
200 | } | |
201 | } | |
202 | ||
203 | class ViewLabelProvider extends LabelProvider implements | |
204 | ITableLabelProvider { | |
205 | public String getColumnText(Object obj, int index) { | |
206 | String strRes = ""; //$NON-NLS-1$ | |
207 | LttngTimestamp time; | |
208 | if (obj instanceof TimeRangeEventProcess) { | |
209 | TimeRangeEventProcess process = (TimeRangeEventProcess) obj; | |
210 | switch (index) { | |
211 | case 0: | |
212 | strRes = process.getName(); | |
213 | break; | |
214 | case 1: | |
215 | strRes = process.getBrand(); | |
216 | break; | |
217 | case 2: | |
218 | strRes = process.getPid().toString(); | |
219 | break; | |
220 | case 3: | |
221 | strRes = process.getTgid().toString(); | |
222 | break; | |
223 | case 4: | |
224 | strRes = process.getPpid().toString(); | |
225 | break; | |
226 | case 5: | |
227 | strRes = process.getCpu().toString(); | |
228 | break; | |
229 | case 6: | |
230 | time = new LttngTimestamp(process.getCreationTime() | |
231 | .longValue()); | |
232 | strRes = time.getSeconds(); | |
233 | break; | |
234 | case 7: | |
235 | time = new LttngTimestamp(process.getCreationTime() | |
236 | .longValue()); | |
237 | strRes = time.getNanoSeconds(); | |
238 | break; | |
239 | case 8: | |
240 | strRes = process.getTraceID(); | |
241 | break; | |
242 | default: | |
243 | break; | |
244 | } | |
245 | } else { | |
246 | return getText(obj); | |
247 | } | |
248 | ||
249 | return strRes; | |
250 | } | |
251 | ||
252 | public Image getColumnImage(Object obj, int index) { | |
253 | return getImage(obj); | |
254 | } | |
255 | ||
256 | @Override | |
257 | public Image getImage(Object obj) { | |
258 | // No image needed for the time being | |
259 | // return PlatformUI.getWorkbench().getSharedImages().getImage( | |
260 | // ISharedImages.IMG_OBJ_ELEMENT); | |
261 | return null; | |
262 | } | |
263 | } | |
264 | ||
265 | class ViewProcessFilter extends ViewerFilter { | |
266 | ||
267 | private Vector<ITmfTimeAnalysisEntry> filteredSet = new Vector<ITmfTimeAnalysisEntry>(); | |
268 | StructuredViewer viewer; | |
269 | ||
270 | public ViewProcessFilter(StructuredViewer rviewer) { | |
271 | this.viewer = rviewer; | |
272 | } | |
273 | ||
274 | public void setFilter(Vector<ITmfTimeAnalysisEntry> filtered) { | |
275 | if (filtered != null) { | |
276 | this.filteredSet = filtered; | |
277 | viewer.refresh(); | |
278 | } | |
279 | } | |
280 | ||
281 | @Override | |
282 | public boolean select(Viewer viewer, Object parentElement, | |
283 | Object element) { | |
284 | boolean filteredIn = true; | |
285 | if (element instanceof ITmfTimeAnalysisEntry) { | |
286 | ITmfTimeAnalysisEntry process = (ITmfTimeAnalysisEntry) element; | |
287 | if (filteredSet.contains(process)) { | |
288 | // The element is marked to be filtered out | |
289 | return false; | |
290 | } | |
291 | } else { | |
292 | TraceDebug.debug("Unexpected type of filter element received: " | |
293 | + element.toString()); | |
294 | } | |
295 | // Compare element versus a list of filtered out | |
296 | return filteredIn; | |
297 | } | |
298 | } | |
299 | ||
300 | /** | |
301 | * The constructor. | |
302 | */ | |
303 | public ControlFlowView() { | |
304 | super(ID); | |
305 | } | |
306 | ||
307 | /** | |
308 | * This is a callback that will allow us to create the viewer and initialize | |
309 | * it. | |
310 | */ | |
6e512b93 ASL |
311 | @Override |
312 | public void createPartControl(Composite parent) { | |
8035003b | 313 | top = new Composite(parent, SWT.BORDER); |
6e512b93 | 314 | |
8035003b ASL |
315 | top.setLayout(new FillLayout()); |
316 | ||
317 | scrollFrame = new ScrolledComposite(top, SWT.V_SCROLL | SWT.H_SCROLL); | |
318 | scrollFrame.setBounds(top.getClientArea()); | |
319 | ||
320 | wrapper = new Composite(scrollFrame, SWT.NONE); | |
321 | scrollFrame.setEnabled(true); | |
322 | scrollFrame.setRedraw(true); | |
6e512b93 ASL |
323 | scrollFrame.setExpandVertical(true); |
324 | scrollFrame.setExpandHorizontal(true); | |
8035003b | 325 | scrollFrame.setContent(wrapper); |
6e512b93 | 326 | scrollFrame.setAlwaysShowScrollBars(true); |
8035003b ASL |
327 | wrapper.setLayout(new FillLayout()); |
328 | ||
329 | SashForm sash = new SashForm(wrapper, SWT.NONE); | |
330 | final Composite tableComposite = new Composite(sash, SWT.NO_SCROLL); | |
331 | FillLayout layout = new FillLayout(); | |
332 | tableComposite.setLayout(layout); | |
333 | tableViewer = new TableViewer(tableComposite, SWT.FULL_SELECTION | |
334 | | SWT.H_SCROLL); | |
6e512b93 ASL |
335 | tableViewer.setContentProvider(new ViewContentProvider(tableViewer)); |
336 | tableViewer.setLabelProvider(new ViewLabelProvider()); | |
337 | Table table = tableViewer.getTable(); | |
8035003b ASL |
338 | tableViewer |
339 | .addSelectionChangedListener(new ISelectionChangedListener() { | |
340 | public void selectionChanged(SelectionChangedEvent event) { | |
341 | ISelection sel = event.getSelection(); | |
342 | if (!sel.isEmpty()) { | |
343 | Object firstSel = null; | |
344 | if (sel instanceof IStructuredSelection) { | |
345 | firstSel = ((IStructuredSelection) sel) | |
346 | .getFirstElement(); | |
347 | ||
348 | // Make sure the selection is visible | |
349 | updateScrollOrigin(); | |
350 | ||
351 | if (firstSel instanceof ITmfTimeAnalysisEntry) { | |
352 | ITmfTimeAnalysisEntry trace = (ITmfTimeAnalysisEntry) firstSel; | |
353 | tsfviewer.setSelectedTrace(trace); | |
354 | } | |
355 | } | |
6e512b93 ASL |
356 | } |
357 | } | |
6e512b93 | 358 | |
8035003b ASL |
359 | /** |
360 | * Make sure the selected item is visible | |
361 | */ | |
362 | private void updateScrollOrigin() { | |
363 | Table table = tableViewer.getTable(); | |
364 | if (table != null && table.getItemCount() > 0) { | |
365 | TableItem item = table.getSelection()[0]; | |
366 | if (item == null) { | |
367 | // no selected reference to go up or down | |
368 | return; | |
369 | } | |
6e512b93 | 370 | |
8035003b ASL |
371 | Rectangle itemRect = item.getBounds(); |
372 | int step = itemRect.height; | |
6e512b93 | 373 | |
8035003b ASL |
374 | // calculate height of horizontal bar |
375 | int hscrolly = 0; | |
376 | ScrollBar hbar = scrollFrame.getHorizontalBar(); | |
377 | if (hbar != null) { | |
378 | hscrolly = hbar.getSize().y; | |
379 | } | |
6e512b93 | 380 | |
8035003b ASL |
381 | int visibleHeight = scrollFrame.getSize().y |
382 | - hscrolly; | |
6e512b93 | 383 | |
8035003b ASL |
384 | // the current scrollbar offset to adjust i.e. start |
385 | // of | |
386 | // the visible window | |
387 | Point origin = scrollFrame.getOrigin(); | |
388 | // end of visible window | |
389 | int endy = origin.y + visibleHeight; | |
6e512b93 | 390 | |
8035003b ASL |
391 | int itemStartPos = itemRect.y |
392 | + table.getHeaderHeight() | |
393 | + table.getBorderWidth() | |
394 | + table.getParent().getBorderWidth(); | |
6e512b93 | 395 | |
8035003b ASL |
396 | // Item End Position |
397 | int itemEndPos = itemStartPos + step; | |
6e512b93 | 398 | |
8035003b ASL |
399 | // check if need to go up |
400 | if (origin.y >= step && itemStartPos < origin.y) { | |
401 | // one step up | |
402 | scrollFrame | |
403 | .setOrigin(origin.x, origin.y - step); | |
6e512b93 | 404 | |
8035003b | 405 | } |
6e512b93 ASL |
406 | |
407 | // check if it needs to go down | |
8035003b ASL |
408 | if (itemEndPos > endy) { |
409 | // one step down | |
410 | scrollFrame | |
411 | .setOrigin(origin.x, origin.y + step); | |
6e512b93 ASL |
412 | |
413 | } | |
8035003b ASL |
414 | } |
415 | } | |
416 | }); | |
417 | ||
6e512b93 ASL |
418 | // Listen to page up /down and Home / Enc keys |
419 | tableViewer.getTable().addKeyListener(new KeyListener() { | |
420 | public void keyPressed(KeyEvent e) { | |
421 | Table table = tableViewer.getTable(); | |
422 | Point origin = scrollFrame.getOrigin(); | |
423 | if (table == null || table.getItemCount() < 1) { | |
424 | // nothing to page | |
425 | return; | |
426 | } | |
427 | ||
428 | TableItem item; | |
429 | int count; | |
430 | ||
431 | switch (e.keyCode) { | |
432 | case SWT.PAGE_DOWN: | |
433 | updateScrollPageDown(); | |
434 | break; | |
435 | case SWT.PAGE_UP: | |
436 | updateScrollUp(); | |
437 | break; | |
438 | case SWT.HOME: | |
439 | // Home | |
440 | count = table.getItemCount(); | |
441 | item = table.getItem(0); | |
442 | // Go to the top | |
443 | scrollFrame.setOrigin(origin.x, 0); | |
444 | break; | |
445 | case SWT.END: | |
446 | // End Selected | |
447 | count = table.getItemCount(); | |
448 | item = table.getItem(count - 1); | |
449 | int itemStartPos = item.getBounds().y; | |
450 | // Get to the bottom | |
451 | scrollFrame.setOrigin(origin.x, itemStartPos); | |
452 | break; | |
453 | default: | |
454 | break; | |
455 | } | |
456 | } | |
457 | ||
458 | public void keyReleased(KeyEvent e) { | |
459 | // Nothing to do | |
460 | ||
461 | } | |
462 | ||
463 | /** | |
464 | * Scroll one page down | |
465 | */ | |
466 | private void updateScrollPageDown() { | |
467 | // null protection before calling private method | |
468 | Table table = tableViewer.getTable(); | |
469 | int step = table.getItemHeight(); | |
470 | ||
471 | int hscrolly = 0; | |
472 | ScrollBar hbar = scrollFrame.getHorizontalBar(); | |
473 | if (hbar != null) { | |
474 | hscrolly = hbar.getSize().y; | |
475 | } | |
476 | ||
477 | Point origin = scrollFrame.getOrigin(); | |
478 | int visibleHeight = scrollFrame.getSize().y - hscrolly; | |
479 | int endy = origin.y + visibleHeight; | |
480 | ||
481 | scrollFrame.setOrigin(origin.x, endy - step); | |
482 | } | |
483 | ||
484 | /** | |
485 | * Scroll one page up | |
486 | */ | |
487 | private void updateScrollUp() { | |
488 | // null protection before calling private method | |
489 | Table table = tableViewer.getTable(); | |
490 | int step = table.getItemHeight(); | |
491 | ||
492 | int hscrolly = 0; | |
493 | ScrollBar hbar = scrollFrame.getHorizontalBar(); | |
494 | if (hbar != null) { | |
495 | hscrolly = hbar.getSize().y; | |
496 | } | |
497 | ||
498 | Point origin = scrollFrame.getOrigin(); | |
499 | int visibleHeight = scrollFrame.getSize().y - hscrolly; | |
500 | int pageUpPos = origin.y - visibleHeight + step; | |
501 | pageUpPos = pageUpPos > 0 ? pageUpPos : 0; | |
502 | scrollFrame.setOrigin(origin.x, pageUpPos); | |
503 | } | |
504 | ||
505 | }); | |
506 | // Describe table | |
507 | applyTableLayout(table); | |
508 | ||
509 | int borderWidth = table.getBorderWidth(); | |
510 | ||
8035003b | 511 | int itemHeight = table.getItemHeight(); |
6e512b93 ASL |
512 | int headerHeight = table.getHeaderHeight(); |
513 | table.getVerticalBar().setVisible(false); | |
514 | ||
515 | tsfviewer = TmfViewerFactory.createViewer(sash, | |
516 | new TimeRangeViewerProvider()); | |
517 | ||
518 | tsfviewer.addWidgetSelectionListner(this); | |
519 | tsfviewer.addWidgetTimeScaleSelectionListner(this); | |
520 | ||
521 | // Traces shall not be grouped to allow synchronisation | |
522 | tsfviewer.groupTraces(false); | |
523 | tsfviewer.setItemHeight(itemHeight); | |
524 | tsfviewer.setBorderWidth(borderWidth); | |
525 | tsfviewer.setHeaderHeight(headerHeight); | |
526 | tsfviewer.setVisibleVerticalScroll(false); | |
527 | // Names provided by the table | |
528 | tsfviewer.setNameWidthPref(0); | |
529 | tsfviewer.setAcceptSelectionAPIcalls(true); | |
530 | ||
531 | // Viewer to notify selection to this class | |
532 | // This class will synchronise selections with table. | |
533 | tsfviewer.addWidgetSelectionListner(this); | |
534 | tsfviewer.addFilterSelectionListner(this); | |
535 | tsfviewer.addWidgetTimeScaleSelectionListner(this); | |
536 | ||
537 | sash.setWeights(new int[] { 1, 1 }); | |
538 | // Create the help context id for the viewer's control | |
539 | // TODO: Associate with help system | |
540 | PlatformUI.getWorkbench().getHelpSystem().setHelp( | |
541 | tableViewer.getControl(), | |
542 | "org.eclipse.linuxtools.lttnng.ui.views.flow.viewer"); //$NON-NLS-1$ | |
543 | ||
544 | makeActions(); | |
545 | hookContextMenu(); | |
546 | hookDoubleClickAction(); | |
547 | contributeToActionBars(); | |
548 | ||
8035003b ASL |
549 | scrollFrame.addControlListener(new ControlAdapter() { |
550 | @Override | |
551 | public void controlResized(ControlEvent e) { | |
552 | tsfviewer.resizeControls(); | |
553 | updateScrolls(scrollFrame, wrapper); | |
554 | } | |
555 | }); | |
556 | ||
557 | tableComposite.addControlListener(new ControlListener() { | |
558 | public void controlResized(ControlEvent e) { | |
559 | scrollFrame.getParent().update(); | |
560 | } | |
561 | ||
562 | public void controlMoved(ControlEvent e) { | |
563 | ||
564 | } | |
565 | }); | |
566 | ||
567 | // Register the updater in charge to refresh elements as we update the | |
568 | // time ranges | |
569 | // FlowParamsUpdater listener = FlowModelFactory.getParamsUpdater(); | |
570 | // tsfviewer.addWidgetTimeScaleSelectionListner(listener); | |
571 | ||
572 | // Register this view to receive updates when the model is updated with | |
573 | // fresh info | |
574 | // ModelListenFactory.getRegister().addFlowModelUpdatesListener(this); | |
575 | ||
576 | // Register the event processor factory in charge of event handling | |
577 | EventProcessorProxy.getInstance().addEventProcessorFactory( | |
578 | FlowTRangeUpdateFactory.getInstance()); | |
6e512b93 ASL |
579 | |
580 | // set the initial view parameter values | |
581 | // Experiment start and end time | |
582 | // as well as time space width in pixels, used by the time analysis | |
583 | // widget | |
8035003b ASL |
584 | ParamsUpdater paramUpdater = FlowModelFactory.getParamsUpdater(); |
585 | StateExperimentManager experimentManger = StateManagerFactory | |
586 | .getExperimentManager(); | |
6e512b93 ASL |
587 | // Read relevant values |
588 | int timeSpaceWidth = tsfviewer.getTimeSpace(); | |
8035003b ASL |
589 | TmfTimeRange timeRange = experimentManger.getExperimentTimeRange(); |
590 | if (timeRange != null) { | |
591 | long time0 = timeRange.getStartTime().getValue(); | |
592 | long time1 = timeRange.getEndTime().getValue(); | |
593 | paramUpdater.update(time0, time1, timeSpaceWidth); | |
6e512b93 ASL |
594 | } |
595 | ||
8035003b | 596 | experimentManger.readExperiment("flowView", this); |
6e512b93 ASL |
597 | } |
598 | ||
599 | private void hookContextMenu() { | |
600 | MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ | |
601 | menuMgr.setRemoveAllWhenShown(true); | |
602 | menuMgr.addMenuListener(new IMenuListener() { | |
603 | public void menuAboutToShow(IMenuManager manager) { | |
604 | ControlFlowView.this.fillContextMenu(manager); | |
605 | } | |
606 | }); | |
607 | Menu menu = menuMgr.createContextMenu(tableViewer.getControl()); | |
608 | tableViewer.getControl().setMenu(menu); | |
609 | getSite().registerContextMenu(menuMgr, tableViewer); | |
610 | } | |
611 | ||
612 | private void contributeToActionBars() { | |
613 | IActionBars bars = getViewSite().getActionBars(); | |
614 | fillLocalPullDown(bars.getMenuManager()); | |
615 | fillLocalToolBar(bars.getToolBarManager()); | |
616 | } | |
617 | ||
618 | private void fillLocalPullDown(IMenuManager manager) { | |
619 | manager.add(new Separator()); | |
620 | // manager.add(showLegend); | |
621 | manager.add(new Separator()); | |
622 | manager.add(resetScale); | |
623 | manager.add(nextEvent); | |
624 | manager.add(prevEvent); | |
625 | manager.add(nextTrace); | |
626 | manager.add(prevTrace); | |
627 | // manager.add(filterTraces); | |
628 | manager.add(zoomIn); | |
629 | manager.add(zoomOut); | |
6e512b93 ASL |
630 | manager.add(new Separator()); |
631 | } | |
632 | ||
633 | private void fillContextMenu(IMenuManager manager) { | |
634 | // manager.add(showLegend); | |
635 | manager.add(new Separator()); | |
636 | manager.add(resetScale); | |
637 | manager.add(nextEvent); | |
638 | manager.add(prevEvent); | |
639 | manager.add(nextTrace); | |
640 | manager.add(prevTrace); | |
641 | // manager.add(showLegend); | |
642 | // manager.add(filterTraces); | |
643 | manager.add(zoomIn); | |
644 | manager.add(zoomOut); | |
6e512b93 ASL |
645 | manager.add(new Separator()); |
646 | manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); | |
647 | } | |
648 | ||
649 | private void fillLocalToolBar(IToolBarManager manager) { | |
650 | // manager.add(showLegend); | |
651 | manager.add(new Separator()); | |
652 | manager.add(resetScale); | |
653 | manager.add(nextEvent); | |
654 | manager.add(prevEvent); | |
655 | manager.add(nextTrace); | |
656 | manager.add(prevTrace); | |
657 | // manager.add(filterTraces); | |
658 | manager.add(zoomIn); | |
659 | manager.add(zoomOut); | |
6e512b93 ASL |
660 | manager.add(new Separator()); |
661 | } | |
662 | ||
663 | private void makeActions() { | |
8035003b | 664 | // action4 |
6e512b93 ASL |
665 | resetScale = new Action() { |
666 | @Override | |
667 | public void run() { | |
668 | if (tsfviewer != null) { | |
669 | tsfviewer.resetStartFinishTime(); | |
670 | } | |
671 | ||
672 | } | |
673 | }; | |
674 | resetScale.setText(Messages.getString("ControlFlowView.Action.Reset")); //$NON-NLS-1$ | |
675 | resetScale.setToolTipText(Messages | |
676 | .getString("ControlFlowView.Action.Reset.ToolTip")); //$NON-NLS-1$ | |
677 | resetScale.setImageDescriptor(AbstractUIPlugin | |
678 | .imageDescriptorFromPlugin(Messages | |
679 | .getString("ControlFlowView.tmf.UI"), | |
680 | "icons/home_nav.gif")); | |
681 | ||
8035003b | 682 | // action5 |
6e512b93 ASL |
683 | nextEvent = new Action() { |
684 | @Override | |
685 | public void run() { | |
686 | if (tsfviewer != null) { | |
687 | tsfviewer.selectNextEvent(); | |
688 | } | |
689 | } | |
690 | }; | |
691 | nextEvent.setText(Messages | |
692 | .getString("ControlFlowView.Action.NextEvent")); //$NON-NLS-1$ | |
693 | nextEvent.setToolTipText(Messages | |
694 | .getString("ControlFlowView.Action.NextEvent.Tooltip")); //$NON-NLS-1$ | |
695 | nextEvent.setImageDescriptor(AbstractUIPlugin | |
696 | .imageDescriptorFromPlugin(Messages | |
697 | .getString("ControlFlowView.tmf.UI"), | |
698 | "icons/next_event.gif")); | |
699 | ||
8035003b | 700 | // action6 |
6e512b93 ASL |
701 | prevEvent = new Action() { |
702 | @Override | |
703 | public void run() { | |
704 | if (tsfviewer != null) { | |
705 | tsfviewer.selectPrevEvent(); | |
706 | } | |
707 | } | |
708 | }; | |
709 | prevEvent.setText(Messages | |
710 | .getString("ControlFlowView.Action.PrevEvent")); //$NON-NLS-1$ | |
711 | prevEvent.setToolTipText(Messages | |
712 | .getString("ControlFlowView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$ | |
713 | prevEvent.setImageDescriptor(AbstractUIPlugin | |
714 | .imageDescriptorFromPlugin(Messages | |
715 | .getString("ControlFlowView.tmf.UI"), | |
716 | "icons/prev_event.gif")); | |
717 | ||
8035003b | 718 | // action7 |
6e512b93 ASL |
719 | nextTrace = new Action() { |
720 | @Override | |
721 | public void run() { | |
722 | if (tsfviewer != null) { | |
723 | tsfviewer.selectNextTrace(); | |
724 | } | |
725 | } | |
726 | }; | |
727 | nextTrace.setText(Messages | |
728 | .getString("ControlFlowView.Action.NextProcess")); //$NON-NLS-1$ | |
729 | nextTrace.setToolTipText(Messages | |
730 | .getString("ControlFlowView.Action.NextProcess.ToolTip")); //$NON-NLS-1$ | |
731 | nextTrace.setImageDescriptor(AbstractUIPlugin | |
732 | .imageDescriptorFromPlugin(Messages | |
733 | .getString("ControlFlowView.tmf.UI"), | |
734 | "icons/next_item.gif")); | |
735 | ||
8035003b | 736 | // action8 |
6e512b93 ASL |
737 | prevTrace = new Action() { |
738 | @Override | |
739 | public void run() { | |
740 | if (tsfviewer != null) { | |
741 | tsfviewer.selectPrevTrace(); | |
742 | } | |
743 | } | |
744 | }; | |
745 | prevTrace.setText(Messages | |
746 | .getString("ControlFlowView.Action.PreviousProcess")); //$NON-NLS-1$ | |
747 | prevTrace.setToolTipText(Messages | |
748 | .getString("ControlFlowView.Action.PreviousProcess.Tooltip")); //$NON-NLS-1$ | |
749 | prevTrace.setImageDescriptor(AbstractUIPlugin | |
750 | .imageDescriptorFromPlugin(Messages | |
751 | .getString("ControlFlowView.tmf.UI"), | |
752 | "icons/prev_item.gif")); | |
753 | ||
8035003b | 754 | // action9 |
6e512b93 ASL |
755 | showLegend = new Action() { |
756 | @Override | |
757 | public void run() { | |
758 | if (tsfviewer != null) { | |
759 | tsfviewer.showLegend(); | |
760 | } | |
761 | } | |
762 | }; | |
763 | showLegend.setText(Messages.getString("ControlFlowView.Action.Legend")); //$NON-NLS-1$ | |
764 | showLegend.setToolTipText(Messages | |
765 | .getString("ControlFlowView.Action.Legend.ToolTip")); //$NON-NLS-1$ | |
766 | ||
8035003b | 767 | // action10 |
6e512b93 ASL |
768 | filterTraces = new Action() { |
769 | @Override | |
770 | public void run() { | |
771 | if (tsfviewer != null) { | |
772 | tsfviewer.filterTraces(); | |
773 | } | |
774 | } | |
775 | }; | |
776 | filterTraces.setText(Messages | |
777 | .getString("ControlFlowView.Action.Filter")); //$NON-NLS-1$ | |
778 | filterTraces.setToolTipText(Messages | |
779 | .getString("ControlFlowView.Action.Filter.ToolTip")); //$NON-NLS-1$ | |
780 | filterTraces.setImageDescriptor(AbstractUIPlugin | |
781 | .imageDescriptorFromPlugin(Messages | |
782 | .getString("ControlFlowView.tmf.UI"), | |
783 | "icons/filter_items.gif")); | |
784 | ||
8035003b | 785 | // action10 |
6e512b93 ASL |
786 | zoomIn = new Action() { |
787 | @Override | |
788 | public void run() { | |
789 | if (tsfviewer != null) { | |
790 | tsfviewer.zoomIn(); | |
791 | } | |
792 | } | |
793 | }; | |
794 | zoomIn.setText(Messages.getString("ControlFlowView.Action.ZoomIn")); //$NON-NLS-1$ | |
795 | zoomIn.setToolTipText(Messages | |
796 | .getString("ControlFlowView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$ | |
797 | zoomIn.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( | |
798 | Messages.getString("ControlFlowView.tmf.UI"), | |
799 | "icons/zoomin_nav.gif")); | |
800 | ||
8035003b | 801 | // action10 |
6e512b93 ASL |
802 | zoomOut = new Action() { |
803 | @Override | |
804 | public void run() { | |
805 | if (tsfviewer != null) { | |
806 | tsfviewer.zoomOut(); | |
807 | } | |
808 | } | |
809 | }; | |
810 | zoomOut.setText(Messages.getString("ControlFlowView.Action.ZoomOut")); //$NON-NLS-1$ | |
811 | zoomOut.setToolTipText(Messages | |
812 | .getString("ControlFlowView.Action.ZoomOut.tooltip")); //$NON-NLS-1$ | |
813 | zoomOut.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( | |
814 | Messages.getString("ControlFlowView.tmf.UI"), | |
815 | "icons/zoomout_nav.gif")); | |
816 | ||
8035003b | 817 | // action11 |
6e512b93 ASL |
818 | // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED); |
819 | ||
820 | doubleClickAction = new Action() { | |
821 | @Override | |
822 | public void run() { | |
823 | ISelection selection = tableViewer.getSelection(); | |
824 | Object obj = ((IStructuredSelection) selection) | |
825 | .getFirstElement(); | |
826 | showMessage("Double-click detected on " + obj.toString()); //$NON-NLS-1$ | |
827 | } | |
828 | }; | |
829 | } | |
830 | ||
831 | private void hookDoubleClickAction() { | |
832 | tableViewer.addDoubleClickListener(new IDoubleClickListener() { | |
833 | public void doubleClick(DoubleClickEvent event) { | |
834 | doubleClickAction.run(); | |
835 | } | |
836 | }); | |
837 | } | |
838 | ||
839 | private void showMessage(String message) { | |
840 | MessageDialog.openInformation(tableViewer.getControl().getShell(), | |
841 | Messages.getString("ControlFlowView.msgSlogan"), message); //$NON-NLS-1$ | |
842 | } | |
843 | ||
844 | /** | |
845 | * Passing the focus request to the viewer's control. | |
846 | */ | |
847 | @Override | |
848 | public void setFocus() { | |
849 | tableViewer.getControl().setFocus(); | |
850 | } | |
851 | ||
6e512b93 | 852 | public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { |
8035003b ASL |
853 | Object source = event.getSource(); |
854 | if (source == null) { | |
855 | return; | |
856 | } | |
6e512b93 ASL |
857 | |
858 | // Reselect the table viewer to widget selection | |
859 | ISelection sel = tsfviewer.getSelectionTrace(); | |
860 | if (sel != null && !sel.isEmpty()) { | |
861 | tableViewer.setSelection(sel); | |
862 | } | |
8035003b ASL |
863 | |
864 | ParamsUpdater paramUpdater = FlowModelFactory.getParamsUpdater(); | |
865 | Long savedSelTime = paramUpdater.getSelectedTime(); | |
866 | ||
867 | long selTimens = event.getSelectedTime(); | |
868 | ||
869 | // make sure the new selected time is different than saved before | |
870 | // executing update | |
871 | if (savedSelTime == null || savedSelTime != selTimens) { | |
872 | // Notify listener views. | |
0b0fc881 | 873 | synchTimeNotification(selTimens, source); |
8035003b ASL |
874 | |
875 | // Update the parameter updater to save the selected time | |
876 | paramUpdater.setSelectedTime(selTimens); | |
877 | ||
878 | if (TraceDebug.isDEBUG()) { | |
879 | // Object selection = event.getSelection(); | |
880 | TraceDebug.debug("Selected Time in control Flow View: " | |
881 | + new LttngTimestamp(selTimens)); | |
882 | } | |
883 | } | |
6e512b93 ASL |
884 | } |
885 | ||
8035003b ASL |
886 | public synchronized void tsfTmProcessTimeScaleEvent( |
887 | TmfTimeScaleSelectionEvent event) { | |
888 | // source needed to keep track of source values | |
889 | Object source = event.getSource(); | |
890 | ||
891 | if (source != null) { | |
892 | // Update the parameter updater before carrying out a read request | |
893 | ParamsUpdater paramUpdater = FlowModelFactory.getParamsUpdater(); | |
894 | boolean newParams = paramUpdater.processTimeScaleEvent(event); | |
895 | ||
896 | if (newParams) { | |
897 | // Read the updated time window | |
898 | TmfTimeRange trange = paramUpdater.getTrange(); | |
899 | if (trange != null) { | |
0b0fc881 ASL |
900 | |
901 | // Notify listener views. views to perform data requests | |
902 | // upon the notification below | |
903 | synchTimeRangeNotification(trange, paramUpdater | |
904 | .getSelectedTime(), source); | |
8035003b ASL |
905 | } |
906 | } | |
907 | } | |
908 | } | |
909 | ||
910 | /** | |
911 | * Obtains the remainder fraction on unit Seconds of the entered value in | |
912 | * nanoseconds. e.g. input: 1241207054171080214 ns The number of seconds can | |
913 | * be obtain by removing the last 9 digits: 1241207054 the fractional | |
914 | * portion of seconds, expressed in ns is: 171080214 | |
6e512b93 | 915 | * |
8035003b ASL |
916 | * @param v |
917 | * @return | |
6e512b93 | 918 | */ |
8035003b ASL |
919 | public String formatNs(long v) { |
920 | StringBuffer str = new StringBuffer(); | |
921 | boolean neg = v < 0; | |
922 | if (neg) { | |
923 | v = -v; | |
924 | str.append('-'); | |
925 | } | |
926 | ||
927 | String strVal = String.valueOf(v); | |
928 | if (v < 1000000000) { | |
929 | return strVal; | |
930 | } | |
931 | ||
932 | // Extract the last nine digits (e.g. fraction of a S expressed in ns | |
933 | return strVal.substring(strVal.length() - 9); | |
6e512b93 ASL |
934 | } |
935 | ||
936 | private void applyTableLayout(Table table) { | |
937 | for (int i = 0; i < columnNames.length; i++) { | |
938 | TableColumn tableColumn = new TableColumn(table, SWT.LEFT); | |
939 | tableColumn.setText(columnNames[i]); | |
940 | tableColumn.pack(); | |
941 | } | |
942 | table.setHeaderVisible(true); | |
943 | table.setLinesVisible(true); | |
944 | } | |
945 | ||
8035003b ASL |
946 | /** |
947 | * @param items | |
948 | * @param startTime | |
949 | * @param endTime | |
950 | * @param updateTimeBounds - Update needed e.g. a new Experiment or trace selected | |
6e512b93 | 951 | */ |
8035003b ASL |
952 | public void flowModelUpdates(final ITmfTimeAnalysisEntry[] items, |
953 | final long startTime, final long endTime, | |
954 | final boolean updateTimeBounds) { | |
6e512b93 ASL |
955 | final Table table = tableViewer.getTable(); |
956 | Display display = table.getDisplay(); | |
957 | ||
958 | // Perform the updates on the UI thread) | |
959 | display.asyncExec(new Runnable() { | |
960 | public void run() { | |
961 | ||
962 | tableViewer.setInput(items); // This shall be the minimal | |
963 | // initial | |
964 | tableFilter = new ViewProcessFilter(tableViewer); | |
965 | tableViewer.setFilters(new ViewerFilter[] { tableFilter }); | |
966 | ||
967 | resizeTableColumns(table); | |
968 | table.update(); | |
969 | tableViewer.refresh(); | |
970 | ||
8035003b | 971 | tsfviewer.display(items, startTime, endTime, updateTimeBounds); |
6e512b93 ASL |
972 | tsfviewer.resizeControls(); |
973 | ||
974 | // Adjust the size of the vertical scroll bar to fit the | |
975 | // contents | |
8035003b ASL |
976 | if (scrollFrame != null && wrapper != null) { |
977 | updateScrolls(scrollFrame, wrapper); | |
978 | // scrollFrame.update(); | |
6e512b93 ASL |
979 | } |
980 | } | |
981 | }); | |
982 | } | |
983 | ||
984 | @Override | |
985 | public void dispose() { | |
986 | // dispose parent resources | |
987 | super.dispose(); | |
8035003b ASL |
988 | // Remove the event processor factory |
989 | EventProcessorProxy.getInstance().removeEventProcessorFactory( | |
990 | FlowTRangeUpdateFactory.getInstance()); | |
6e512b93 | 991 | |
8035003b ASL |
992 | // Remove listener to model updates |
993 | // ModelListenFactory.getRegister().removeFlowModelUpdatesListener(this); | |
6e512b93 ASL |
994 | tsfviewer.removeFilterSelectionListner(this); |
995 | tsfviewer.removeWidgetSelectionListner(this); | |
996 | tsfviewer.removeWidgetTimeScaleSelectionListner(this); | |
997 | tableViewer = null; | |
998 | tsfviewer = null; | |
999 | } | |
1000 | ||
1001 | /** | |
1002 | * @param tableComposite | |
1003 | * @param table | |
1004 | */ | |
1005 | private synchronized void resizeTableColumns(Table table) { | |
1006 | if (table != null) { | |
1007 | Composite parent = table.getParent(); | |
1008 | int tableWidthSum = parent.getBorderWidth(); | |
1009 | ||
1010 | TableColumn[] columns = table.getColumns(); | |
1011 | for (TableColumn column : columns) { | |
1012 | column.pack(); | |
1013 | tableWidthSum += column.getWidth(); | |
1014 | } | |
1015 | } | |
1016 | } | |
1017 | ||
1018 | // @Override | |
1019 | public void tmfTaProcessFilterSelection(TmfTimeFilterSelectionEvent event) { | |
1020 | if (tableFilter != null) { | |
1021 | Vector<ITmfTimeAnalysisEntry> filteredout = event.getFilteredOut(); | |
1022 | if (filteredout != null) { | |
1023 | tableFilter.setFilter(filteredout); | |
1024 | } else { | |
1025 | tableFilter.setFilter(new Vector<ITmfTimeAnalysisEntry>()); | |
1026 | } | |
1027 | tableViewer.refresh(); | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | /** | |
1032 | * @param scrollFrame | |
1033 | * @param wrapper | |
1034 | */ | |
8035003b ASL |
1035 | private void updateScrolls(final ScrolledComposite scrollFrame, |
1036 | final Composite wrapper) { | |
1037 | ||
1038 | Point ptSize = wrapper.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
1039 | wrapper.setSize(ptSize); | |
1040 | scrollFrame.setMinSize(ptSize); | |
1041 | ||
1042 | // calculate the increment area considering the table header height and | |
1043 | // borders | |
1044 | Rectangle area = top.getBounds(); | |
1045 | int marginsHeight = tableViewer.getTable().getHeaderHeight(); | |
1046 | marginsHeight -= top.getBorderWidth() + wrapper.getBorderWidth(); | |
1047 | area.height -= marginsHeight; | |
1048 | ||
1049 | // set page vertical increment area | |
1050 | ScrollBar verBar = scrollFrame.getVerticalBar(); | |
1051 | ScrollBar horBar = scrollFrame.getHorizontalBar(); | |
1052 | if (verBar != null) { | |
1053 | verBar.setPageIncrement(area.height); | |
1054 | } | |
1055 | if (horBar != null) { | |
1056 | horBar.setPageIncrement(area.width); | |
1057 | } | |
1058 | ||
6e512b93 ASL |
1059 | } |
1060 | ||
1061 | /** | |
8035003b ASL |
1062 | * Trigger time synchronisation to other views this method shall be called |
1063 | * when a check has been performed to note that an actual change of time has | |
1064 | * been performed vs a pure re-selection of the same time | |
6e512b93 | 1065 | * |
8035003b | 1066 | * @param time |
0b0fc881 | 1067 | * @param source |
6e512b93 | 1068 | */ |
0b0fc881 | 1069 | private void synchTimeNotification(long time, Object source) { |
8035003b | 1070 | // if synchronisation selected |
0b0fc881 | 1071 | if (synch) { |
8035003b | 1072 | // Notify other views |
0b0fc881 | 1073 | TmfSignalManager.dispatchSignal(new TmfTimeSynchSignal(source, |
8035003b ASL |
1074 | new LttngTimestamp(time))); |
1075 | } | |
6e512b93 ASL |
1076 | } |
1077 | ||
1078 | /** | |
0b0fc881 ASL |
1079 | * Trigger time range synchronisation to other views this method shall be |
1080 | * called when a check has been performed to note that an actual change of | |
1081 | * time range has been performed vs a pure re-selection of the same. | |
1082 | * | |
1083 | * @param trange | |
1084 | * @param source | |
1085 | */ | |
1086 | private void synchTimeRangeNotification(TmfTimeRange trange, | |
1087 | Long selectedTime, Object source) { | |
1088 | // if synchronisation selected | |
1089 | if (synch) { | |
1090 | // Notify other views | |
1091 | TmfSignalManager.dispatchSignal(new TmfRangeSynchSignal(source, | |
1092 | trange, new LttngTimestamp(selectedTime))); | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | /** | |
1097 | * Registers as listener of time selection from other views | |
6e512b93 ASL |
1098 | * |
1099 | * @param signal | |
1100 | */ | |
1101 | @TmfSignalHandler | |
8035003b | 1102 | public void synchToTime(TmfTimeSynchSignal signal) { |
0b0fc881 | 1103 | if (synch) { |
8035003b ASL |
1104 | Object source = signal.getSource(); |
1105 | if (signal != null && source != null && source != this) { | |
1106 | // Internal value is expected in nano seconds. | |
1107 | long selectedTime = signal.getCurrentTime().getValue(); | |
1108 | if (tsfviewer != null) { | |
1109 | tsfviewer.setSelectedTime(selectedTime, true, source); | |
1110 | } | |
1111 | } | |
6e512b93 ASL |
1112 | } |
1113 | } | |
1114 | ||
0b0fc881 ASL |
1115 | /** |
1116 | * Annotation Registers as listener of time range selection from other views | |
1117 | * The implementation handles the entry of the signal. | |
1118 | * | |
1119 | * @param signal | |
1120 | */ | |
1121 | @TmfSignalHandler | |
1122 | public void synchToTimeRange(TmfRangeSynchSignal signal) { | |
1123 | if (synch) { | |
1124 | Object source = signal.getSource(); | |
1125 | if (signal != null && source != null && source != this) { | |
1126 | // Internal value is expected in nano seconds. | |
1127 | TmfTimeRange trange = signal.getCurrentRange(); | |
1128 | if (tsfviewer != null) { | |
1129 | tsfviewer | |
1130 | .setSelectVisTimeWindow(trange.getStartTime() | |
1131 | .getValue(), | |
1132 | trange.getEndTime().getValue(), source); | |
1133 | ||
1134 | // Request the data to populate the new selected time window | |
1135 | dataRequest(trange); | |
1136 | } | |
1137 | } | |
1138 | } | |
1139 | } | |
6e512b93 ASL |
1140 | /* |
1141 | * (non-Javadoc) | |
1142 | * | |
8035003b ASL |
1143 | * @see |
1144 | * org.eclipse.linuxtools.lttng.ui.views.common.LttngTimeUpdateView#waitCursor | |
1145 | * (boolean) | |
6e512b93 ASL |
1146 | */ |
1147 | @Override | |
8035003b ASL |
1148 | protected synchronized void waitCursor(final boolean waitInd) { |
1149 | if (tsfviewer != null) { | |
1150 | Display display = tsfviewer.getControl().getDisplay(); | |
1151 | ||
1152 | // Perform the updates on the UI thread | |
1153 | display.asyncExec(new Runnable() { | |
1154 | public void run() { | |
1155 | tsfviewer.waitCursor(waitInd); | |
1156 | } | |
1157 | }); | |
6e512b93 | 1158 | } |
6e512b93 ASL |
1159 | } |
1160 | ||
1161 | /* | |
1162 | * (non-Javadoc) | |
1163 | * | |
8035003b ASL |
1164 | * @seeorg.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# |
1165 | * ModelUpdatePrep(java.lang.String, boolean) | |
6e512b93 ASL |
1166 | */ |
1167 | @Override | |
8035003b ASL |
1168 | public void ModelUpdatePrep(String traceId, boolean clearAllData, |
1169 | TmfTimeRange trange) { | |
1170 | if (clearAllData) { | |
1171 | FlowModelFactory.getProcContainer().clearProcesses(); | |
1172 | // Obtain the current process array | |
1173 | TimeRangeEventProcess[] processArr = FlowModelFactory | |
1174 | .getProcContainer().readProcesses(); | |
1175 | ||
1176 | ||
1177 | // initialise to an empty model | |
1178 | flowModelUpdates(processArr, -1, -1, false); | |
1179 | } else { | |
1180 | FlowModelFactory.getProcContainer().clearChildren(traceId); | |
1181 | } | |
1182 | ||
1183 | ParamsUpdater updater = FlowModelFactory.getParamsUpdater(); | |
1184 | // Start over | |
1185 | updater.setEventsDiscarded(0); | |
1186 | ||
1187 | // Update new visible time range if available | |
1188 | if (trange != null) { | |
1189 | updater.update(trange.getStartTime().getValue(), trange | |
1190 | .getEndTime().getValue()); | |
1191 | } | |
6e512b93 ASL |
1192 | } |
1193 | ||
1194 | /* | |
1195 | * (non-Javadoc) | |
1196 | * | |
8035003b ASL |
1197 | * @seeorg.eclipse.linuxtools.lttng.ui.views.common.LttngTimeUpdateView# |
1198 | * ModelUpdateComplete(org.eclipse.linuxtools.lttng.state.StateDataRequest) | |
6e512b93 ASL |
1199 | */ |
1200 | @Override | |
8035003b ASL |
1201 | public void ModelUpdateComplete(StateDataRequest request) { |
1202 | long experimentStartTime = -1; | |
1203 | long experimentEndTime = -1; | |
1204 | StateManager smanager = request.getStateManager(); | |
1205 | TmfTimeRange experimentTimeRange = smanager.getExperimentTimeWindow(); | |
1206 | if (experimentTimeRange != null) { | |
1207 | experimentStartTime = experimentTimeRange.getStartTime().getValue(); | |
1208 | experimentEndTime = experimentTimeRange.getEndTime().getValue(); | |
1209 | } | |
1210 | // Obtain the current process array | |
1211 | TimeRangeEventProcess[] processArr = FlowModelFactory | |
1212 | .getProcContainer().readProcesses(); | |
1213 | // Sort the array by pid | |
1214 | Arrays.sort(processArr); | |
1215 | ||
1216 | // Update the view part | |
1217 | flowModelUpdates(processArr, experimentStartTime, experimentEndTime, | |
1218 | request.isclearDataInd()); | |
1219 | ||
1220 | // get back to user selected time if still within range | |
1221 | ParamsUpdater paramUpdater = FlowModelFactory.getParamsUpdater(); | |
1222 | final Long selTime = paramUpdater.getSelectedTime(); | |
1223 | if (selTime != null) { | |
1224 | Display display = tsfviewer.getControl().getDisplay(); | |
1225 | display.asyncExec(new Runnable() { | |
1226 | public void run() { | |
1227 | tsfviewer.setSelectedTime(selTime, false, this); | |
1228 | } | |
1229 | }); | |
1230 | } | |
1231 | ||
1232 | if (TraceDebug.isDEBUG()) { | |
1233 | int eventCount = 0; | |
1234 | Long count = smanager.getEventCount(); | |
1235 | for ( int pos = 0; pos<processArr.length; pos++ ) { | |
1236 | eventCount += processArr[pos].getTraceEvents().size(); | |
1237 | } | |
1238 | ||
1239 | int discarded = FlowModelFactory.getParamsUpdater() | |
1240 | .getEventsDiscarded(); | |
1241 | int discardedOutofOrder = FlowModelFactory.getParamsUpdater() | |
1242 | .getEventsDiscardedWrongOrder(); | |
1243 | TmfTimeRange range = request.getRange(); | |
1244 | StringBuilder sb = new StringBuilder( | |
1245 | "Events handled: " | |
1246 | + count | |
1247 | + " Events loaded in Control Flow view: " | |
1248 | + eventCount | |
1249 | + " Number of events discarded: " | |
1250 | + discarded | |
1251 | + "\n\tNumber of events discarded with start time earlier than next good time: " | |
1252 | + discardedOutofOrder); | |
1253 | ||
1254 | sb.append("\n\t\tRequested Time Range: " + range.getStartTime() | |
1255 | + "-" + range.getEndTime()); | |
1256 | sb.append("\n\t\tExperiment Time Range: " + experimentStartTime | |
1257 | + "-" + experimentEndTime); | |
1258 | TraceDebug.debug(sb.toString()); | |
1259 | } | |
6e512b93 ASL |
1260 | } |
1261 | } |