Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
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 | ||
13 | import java.util.Vector; | |
14 | ||
15 | import org.eclipse.jface.action.Action; | |
16 | import org.eclipse.jface.action.IMenuListener; | |
17 | import org.eclipse.jface.action.IMenuManager; | |
18 | import org.eclipse.jface.action.IToolBarManager; | |
19 | import org.eclipse.jface.action.MenuManager; | |
20 | import org.eclipse.jface.action.Separator; | |
21 | import org.eclipse.jface.dialogs.MessageDialog; | |
22 | import org.eclipse.jface.viewers.DoubleClickEvent; | |
23 | import org.eclipse.jface.viewers.IDoubleClickListener; | |
24 | import org.eclipse.jface.viewers.ISelection; | |
25 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
26 | import org.eclipse.jface.viewers.IStructuredContentProvider; | |
27 | import org.eclipse.jface.viewers.IStructuredSelection; | |
28 | import org.eclipse.jface.viewers.ITableLabelProvider; | |
29 | import org.eclipse.jface.viewers.LabelProvider; | |
30 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
31 | import org.eclipse.jface.viewers.StructuredViewer; | |
32 | import org.eclipse.jface.viewers.TableViewer; | |
33 | import org.eclipse.jface.viewers.Viewer; | |
34 | import org.eclipse.jface.viewers.ViewerFilter; | |
35 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; | |
36 | import org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest; | |
37 | import org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor; | |
38 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; | |
39 | import org.eclipse.linuxtools.lttng.ui.model.trange.ItemContainer; | |
40 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess; | |
41 | import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeViewerProvider; | |
42 | import org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView; | |
43 | import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater; | |
44 | import org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor.FlowEventToHandlerFactory; | |
45 | import org.eclipse.linuxtools.lttng.ui.views.controlflow.model.FlowModelFactory; | |
46 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
47 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
48 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; | |
49 | import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal; | |
50 | import org.eclipse.linuxtools.tmf.signal.TmfRangeSynchSignal; | |
51 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; | |
52 | import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal; | |
53 | import org.eclipse.linuxtools.tmf.ui.viewers.TmfViewerFactory; | |
54 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeFilterSelectionListener; | |
55 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeScaleSelectionListener; | |
56 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITmfTimeSelectionListener; | |
57 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeFilterSelectionEvent; | |
58 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent; | |
59 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent; | |
60 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; | |
61 | import org.eclipse.swt.SWT; | |
62 | import org.eclipse.swt.custom.SashForm; | |
63 | import org.eclipse.swt.custom.ScrolledComposite; | |
64 | import org.eclipse.swt.events.KeyEvent; | |
65 | import org.eclipse.swt.events.KeyListener; | |
66 | import org.eclipse.swt.graphics.Image; | |
67 | import org.eclipse.swt.graphics.Point; | |
68 | import org.eclipse.swt.graphics.Rectangle; | |
69 | import org.eclipse.swt.widgets.Composite; | |
70 | import org.eclipse.swt.widgets.Display; | |
71 | import org.eclipse.swt.widgets.Menu; | |
72 | import org.eclipse.swt.widgets.ScrollBar; | |
73 | import org.eclipse.swt.widgets.Table; | |
74 | import org.eclipse.swt.widgets.TableColumn; | |
75 | import org.eclipse.swt.widgets.TableItem; | |
76 | import org.eclipse.ui.IActionBars; | |
77 | import org.eclipse.ui.IWorkbenchActionConstants; | |
78 | import org.eclipse.ui.PlatformUI; | |
79 | import org.eclipse.ui.plugin.AbstractUIPlugin; | |
80 | ||
81 | /** | |
82 | * <b><u>ControlFlowView</u></b> | |
83 | */ | |
84 | /** | |
85 | * @author alvaro | |
86 | * | |
87 | */ | |
88 | public class ControlFlowView extends AbsTimeUpdateView implements | |
89 | ITmfTimeSelectionListener, ITmfTimeScaleSelectionListener, | |
90 | ITmfTimeFilterSelectionListener { | |
91 | ||
92 | public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.controlflow"; | |
93 | ||
94 | // ======================================================================== | |
95 | // Table data | |
96 | // ======================================================================== | |
97 | private final String PROCESS_COLUMN = "Process"; | |
98 | private final String BRAND_COLUMN = "Brand"; | |
99 | private final String PID_COLUMN = "PID"; | |
100 | private final String TGID_COLUMN = "TGID"; | |
101 | private final String PPID_COLUMN = "PPID"; | |
102 | private final String CPU_COLUMN = "CPU"; | |
103 | private final String BIRTH_SEC_COLUMN = "Birth sec"; | |
104 | private final String BIRTH_NSEC_COLUMN = "Birth nsec"; | |
105 | private final String TRACE = "TRACE"; | |
106 | ||
107 | private final String[] columnNames = new String[] { PROCESS_COLUMN, /* */ | |
108 | BRAND_COLUMN,/* */ | |
109 | PID_COLUMN,/* */ | |
110 | TGID_COLUMN,/* */ | |
111 | PPID_COLUMN,/* */ | |
112 | CPU_COLUMN, /* */ | |
113 | BIRTH_SEC_COLUMN,/* */ | |
114 | BIRTH_NSEC_COLUMN,/* */ | |
115 | TRACE /* */ | |
116 | }; | |
117 | ||
118 | // ======================================================================== | |
119 | // Data | |
120 | // ======================================================================== | |
121 | private TableViewer tableViewer; | |
122 | // private int totalNumItems = 0; | |
123 | // Actions | |
124 | private Action doubleClickAction; | |
125 | private Action resetScale; | |
126 | private Action nextEvent; | |
127 | private Action prevEvent; | |
128 | private Action nextTrace; | |
129 | private Action prevTrace; | |
130 | private Action showLegend; | |
131 | private Action filterTraces; | |
132 | private Action zoomIn; | |
133 | private Action zoomOut; | |
134 | private Action zoomFilter; | |
135 | ||
136 | private ViewProcessFilter tableFilter = null; | |
137 | private ScrolledComposite scrollFrame = null; | |
138 | ||
139 | // private static SimpleDateFormat stimeformat = new SimpleDateFormat( | |
140 | // "yy/MM/dd HH:mm:ss"); | |
141 | ||
142 | // private TraceModelImplFactory fact; | |
143 | ||
144 | // ======================================================================== | |
145 | // Methods | |
146 | // ======================================================================== | |
147 | /* | |
148 | * The content provider class is responsible for providing objects to the | |
149 | * view. It can wrap existing objects in adapters or simply return objects | |
150 | * as-is. These objects may be sensitive to the current input of the view, | |
151 | * or ignore it and always show the same content (like Task List, for | |
152 | * example). | |
153 | */ | |
154 | ||
155 | class ViewContentProvider implements | |
156 | /* ILazyContentProvider, */IStructuredContentProvider { | |
157 | private TableViewer cviewer = null; | |
158 | private ITmfTimeAnalysisEntry[] elements = null; | |
159 | ||
160 | public ViewContentProvider(TableViewer v) { | |
161 | cviewer = v; | |
162 | } | |
163 | ||
164 | public void inputChanged(Viewer v, Object oldInput, Object newInput) { | |
165 | this.elements = (ITmfTimeAnalysisEntry[]) newInput; | |
166 | if (elements != null) { | |
167 | TraceDebug.debug("Total number of processes provided to Control Flow view: " + elements.length); | |
168 | } else { | |
169 | TraceDebug.debug("New input = null"); | |
170 | } | |
171 | } | |
172 | ||
173 | public void dispose() { | |
174 | ||
175 | } | |
176 | ||
177 | // Needed with the use of virtual tables in order to initialize items | |
178 | // which were not initially visible. | |
179 | public void updateElement(int index) { | |
180 | cviewer.replace(elements[index], index); | |
181 | } | |
182 | ||
183 | // @Override | |
184 | public Object[] getElements(Object inputElement) { | |
185 | return elements; | |
186 | } | |
187 | } | |
188 | ||
189 | class ViewLabelProvider extends LabelProvider implements | |
190 | ITableLabelProvider { | |
191 | public String getColumnText(Object obj, int index) { | |
192 | String strRes = ""; //$NON-NLS-1$ | |
193 | LttngTimestamp time; | |
194 | if (obj instanceof TimeRangeEventProcess) { | |
195 | TimeRangeEventProcess process = (TimeRangeEventProcess) obj; | |
196 | switch (index) { | |
197 | case 0: | |
198 | strRes = process.getName(); | |
199 | break; | |
200 | case 1: | |
201 | strRes = process.getBrand(); | |
202 | break; | |
203 | case 2: | |
204 | strRes = process.getPid().toString(); | |
205 | break; | |
206 | case 3: | |
207 | strRes = process.getTgid().toString(); | |
208 | break; | |
209 | case 4: | |
210 | strRes = process.getPpid().toString(); | |
211 | break; | |
212 | case 5: | |
213 | strRes = process.getCpu().toString(); | |
214 | break; | |
215 | case 6: | |
216 | time = new LttngTimestamp(process.getCreationTime() | |
217 | .longValue()); | |
218 | strRes = time.getSeconds(); | |
219 | break; | |
220 | case 7: | |
221 | time = new LttngTimestamp(process.getCreationTime() | |
222 | .longValue()); | |
223 | strRes = time.getNanoSeconds(); | |
224 | break; | |
225 | case 8: | |
226 | strRes = process.getTraceID(); | |
227 | break; | |
228 | default: | |
229 | break; | |
230 | } | |
231 | } else { | |
232 | return getText(obj); | |
233 | } | |
234 | ||
235 | return strRes; | |
236 | } | |
237 | ||
238 | public Image getColumnImage(Object obj, int index) { | |
239 | return getImage(obj); | |
240 | } | |
241 | ||
242 | @Override | |
243 | public Image getImage(Object obj) { | |
244 | // No image needed for the time being | |
245 | // return PlatformUI.getWorkbench().getSharedImages().getImage( | |
246 | // ISharedImages.IMG_OBJ_ELEMENT); | |
247 | return null; | |
248 | } | |
249 | } | |
250 | ||
251 | class ViewProcessFilter extends ViewerFilter { | |
252 | ||
253 | private Vector<ITmfTimeAnalysisEntry> filteredSet = new Vector<ITmfTimeAnalysisEntry>(); | |
254 | StructuredViewer viewer; | |
255 | ||
256 | public ViewProcessFilter(StructuredViewer rviewer) { | |
257 | this.viewer = rviewer; | |
258 | } | |
259 | ||
260 | public void setFilter(Vector<ITmfTimeAnalysisEntry> filtered) { | |
261 | if (filtered != null) { | |
262 | this.filteredSet = filtered; | |
263 | viewer.refresh(); | |
264 | } | |
265 | } | |
266 | ||
267 | @Override | |
268 | public boolean select(Viewer viewer, Object parentElement, | |
269 | Object element) { | |
270 | boolean filteredIn = true; | |
271 | if (element instanceof ITmfTimeAnalysisEntry) { | |
272 | ITmfTimeAnalysisEntry process = (ITmfTimeAnalysisEntry) element; | |
273 | if (filteredSet.contains(process)) { | |
274 | // The element is marked to be filtered out | |
275 | return false; | |
276 | } | |
277 | } else { | |
278 | TraceDebug.debug("Unexpected type of filter element received: " | |
279 | + element.toString()); | |
280 | } | |
281 | // Compare element versus a list of filtered out | |
282 | return filteredIn; | |
283 | } | |
284 | } | |
285 | ||
286 | /** | |
287 | * The constructor. | |
288 | */ | |
289 | public ControlFlowView() { | |
290 | super(ID); | |
291 | } | |
292 | ||
293 | /** | |
294 | * This is a callback that will allow us to create the viewer and initialize | |
295 | * it. | |
296 | */ | |
297 | /* | |
298 | * (non-Javadoc) | |
299 | * | |
300 | * @see | |
301 | * org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse | |
302 | * .swt.widgets.Composite) | |
303 | */ | |
304 | @Override | |
305 | public void createPartControl(Composite parent) { | |
306 | ||
307 | scrollFrame = new ScrolledComposite(parent, SWT.V_SCROLL); | |
308 | ||
309 | scrollFrame.setExpandVertical(true); | |
310 | scrollFrame.setExpandHorizontal(true); | |
311 | scrollFrame.setAlwaysShowScrollBars(true); | |
312 | ||
313 | SashForm sash = new SashForm(scrollFrame, SWT.NONE); | |
314 | scrollFrame.setContent(sash); | |
315 | ||
316 | tableViewer = new TableViewer(sash, SWT.FULL_SELECTION | SWT.H_SCROLL); | |
317 | tableViewer.setContentProvider(new ViewContentProvider(tableViewer)); | |
318 | tableViewer.setLabelProvider(new ViewLabelProvider()); | |
319 | Table table = tableViewer.getTable(); | |
320 | tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { | |
321 | public void selectionChanged(SelectionChangedEvent event) { | |
322 | ISelection sel = event.getSelection(); | |
323 | if (!sel.isEmpty()) { | |
324 | Object firstSel = null; | |
325 | if (sel instanceof IStructuredSelection) { | |
326 | firstSel = ((IStructuredSelection) sel).getFirstElement(); | |
327 | ||
328 | // Make sure the selection is visible | |
329 | updateScrollOrigin(); | |
330 | ||
331 | if (firstSel instanceof ITmfTimeAnalysisEntry) { | |
332 | ITmfTimeAnalysisEntry trace = (ITmfTimeAnalysisEntry) firstSel; | |
333 | tsfviewer.setSelectedTrace(trace); | |
334 | } | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
339 | /** | |
340 | * Make sure the selected item is visible | |
341 | */ | |
342 | private void updateScrollOrigin() { | |
343 | Table table = tableViewer.getTable(); | |
344 | if (table != null && table.getItemCount() > 0) { | |
345 | TableItem item = table.getSelection()[0]; | |
346 | if (item == null) { | |
347 | // no selected reference to go up or down | |
348 | return; | |
349 | } | |
350 | ||
351 | Rectangle itemRect = item.getBounds(); | |
352 | int step = itemRect.height; | |
353 | ||
354 | // calculate height of horizontal bar | |
355 | int hscrolly = 0; | |
356 | ScrollBar hbar = scrollFrame.getHorizontalBar(); | |
357 | if (hbar != null) { | |
358 | hscrolly = hbar.getSize().y; | |
359 | } | |
360 | ||
361 | int visibleHeight = scrollFrame.getSize().y - hscrolly; | |
362 | ||
363 | // the current scrollbar offset to adjust i.e. start | |
364 | // of | |
365 | // the visible window | |
366 | Point origin = scrollFrame.getOrigin(); | |
367 | // end of visible window | |
368 | int endy = origin.y + visibleHeight; | |
369 | ||
370 | int itemStartPos = itemRect.y + table.getHeaderHeight() + table.getBorderWidth() | |
371 | + table.getParent().getBorderWidth(); | |
372 | ||
373 | // Item End Position | |
374 | int itemEndPos = itemStartPos + step; | |
375 | ||
376 | // check if need to go up | |
377 | if (origin.y >= step && itemStartPos < origin.y) { | |
378 | // one step up | |
379 | scrollFrame.setOrigin(origin.x, origin.y - step); | |
380 | ||
381 | } | |
382 | ||
383 | // check if it needs to go down | |
384 | if (itemEndPos > endy) { | |
385 | // one step down | |
386 | scrollFrame.setOrigin(origin.x, origin.y + step); | |
387 | ||
388 | } | |
389 | } | |
390 | } | |
391 | }); | |
392 | ||
393 | // Listen to page up /down and Home / Enc keys | |
394 | tableViewer.getTable().addKeyListener(new KeyListener() { | |
395 | public void keyPressed(KeyEvent e) { | |
396 | Table table = tableViewer.getTable(); | |
397 | Point origin = scrollFrame.getOrigin(); | |
398 | if (table == null || table.getItemCount() < 1) { | |
399 | // nothing to page | |
400 | return; | |
401 | } | |
402 | ||
403 | TableItem item; | |
404 | int count; | |
405 | ||
406 | switch (e.keyCode) { | |
407 | case SWT.PAGE_DOWN: | |
408 | updateScrollPageDown(); | |
409 | break; | |
410 | case SWT.PAGE_UP: | |
411 | updateScrollUp(); | |
412 | break; | |
413 | case SWT.HOME: | |
414 | // Home | |
415 | count = table.getItemCount(); | |
416 | item = table.getItem(0); | |
417 | // Go to the top | |
418 | scrollFrame.setOrigin(origin.x, 0); | |
419 | break; | |
420 | case SWT.END: | |
421 | // End Selected | |
422 | count = table.getItemCount(); | |
423 | item = table.getItem(count - 1); | |
424 | int itemStartPos = item.getBounds().y; | |
425 | // Get to the bottom | |
426 | scrollFrame.setOrigin(origin.x, itemStartPos); | |
427 | break; | |
428 | default: | |
429 | break; | |
430 | } | |
431 | } | |
432 | ||
433 | public void keyReleased(KeyEvent e) { | |
434 | // Nothing to do | |
435 | ||
436 | } | |
437 | ||
438 | /** | |
439 | * Scroll one page down | |
440 | */ | |
441 | private void updateScrollPageDown() { | |
442 | // null protection before calling private method | |
443 | Table table = tableViewer.getTable(); | |
444 | int step = table.getItemHeight(); | |
445 | ||
446 | int hscrolly = 0; | |
447 | ScrollBar hbar = scrollFrame.getHorizontalBar(); | |
448 | if (hbar != null) { | |
449 | hscrolly = hbar.getSize().y; | |
450 | } | |
451 | ||
452 | Point origin = scrollFrame.getOrigin(); | |
453 | int visibleHeight = scrollFrame.getSize().y - hscrolly; | |
454 | int endy = origin.y + visibleHeight; | |
455 | ||
456 | scrollFrame.setOrigin(origin.x, endy - step); | |
457 | } | |
458 | ||
459 | /** | |
460 | * Scroll one page up | |
461 | */ | |
462 | private void updateScrollUp() { | |
463 | // null protection before calling private method | |
464 | Table table = tableViewer.getTable(); | |
465 | int step = table.getItemHeight(); | |
466 | ||
467 | int hscrolly = 0; | |
468 | ScrollBar hbar = scrollFrame.getHorizontalBar(); | |
469 | if (hbar != null) { | |
470 | hscrolly = hbar.getSize().y; | |
471 | } | |
472 | ||
473 | Point origin = scrollFrame.getOrigin(); | |
474 | int visibleHeight = scrollFrame.getSize().y - hscrolly; | |
475 | int pageUpPos = origin.y - visibleHeight + step; | |
476 | pageUpPos = pageUpPos > 0 ? pageUpPos : 0; | |
477 | scrollFrame.setOrigin(origin.x, pageUpPos); | |
478 | } | |
479 | ||
480 | }); | |
481 | // Describe table | |
482 | applyTableLayout(table); | |
483 | ||
484 | int borderWidth = table.getBorderWidth(); | |
485 | ||
486 | int itemHeight = table.getItemHeight() + checkForSWTBugItemHeightAdjustement(); | |
487 | int headerHeight = table.getHeaderHeight(); | |
488 | table.getVerticalBar().setVisible(false); | |
489 | ||
490 | tsfviewer = TmfViewerFactory.createViewer(sash, | |
491 | new TimeRangeViewerProvider()); | |
492 | ||
493 | tsfviewer.addWidgetSelectionListner(this); | |
494 | tsfviewer.addWidgetTimeScaleSelectionListner(this); | |
495 | ||
496 | // Traces shall not be grouped to allow synchronisation | |
497 | tsfviewer.groupTraces(false); | |
498 | tsfviewer.setItemHeight(itemHeight); | |
499 | tsfviewer.setBorderWidth(borderWidth); | |
500 | tsfviewer.setHeaderHeight(headerHeight); | |
501 | tsfviewer.setVisibleVerticalScroll(false); | |
502 | // Names provided by the table | |
503 | tsfviewer.setNameWidthPref(0); | |
504 | tsfviewer.setAcceptSelectionAPIcalls(true); | |
505 | ||
506 | // Viewer to notify selection to this class | |
507 | // This class will synchronise selections with table. | |
508 | tsfviewer.addWidgetSelectionListner(this); | |
509 | tsfviewer.addFilterSelectionListner(this); | |
510 | tsfviewer.addWidgetTimeScaleSelectionListner(this); | |
511 | ||
512 | sash.setWeights(new int[] { 1, 1 }); | |
513 | // Create the help context id for the viewer's control | |
514 | // TODO: Associate with help system | |
515 | PlatformUI.getWorkbench().getHelpSystem().setHelp( | |
516 | tableViewer.getControl(), | |
517 | "org.eclipse.linuxtools.lttnng.ui.views.flow.viewer"); //$NON-NLS-1$ | |
518 | ||
519 | makeActions(); | |
520 | hookContextMenu(); | |
521 | hookDoubleClickAction(); | |
522 | contributeToActionBars(); | |
523 | ||
524 | // scrollFrame.addControlListener(new ControlAdapter() { | |
525 | // | |
526 | // @Override | |
527 | // public void controlResized(ControlEvent e) { | |
528 | // tsfviewer.resizeControls(); | |
529 | // updateScrolls(scrollFrame); | |
530 | // } | |
531 | // }); | |
532 | ||
533 | // set the initial view parameter values | |
534 | // Experiment start and end time | |
535 | // as well as time space width in pixels, used by the time analysis | |
536 | // widget | |
537 | // Read relevant values | |
538 | int timeSpaceWidth = tsfviewer.getTimeSpace(); | |
539 | if (timeSpaceWidth < 0) { | |
540 | timeSpaceWidth = -timeSpaceWidth; | |
541 | } | |
542 | ||
543 | TmfExperiment<?> experiment = TmfExperiment.getCurrentExperiment(); | |
544 | if (experiment != null) { | |
545 | TmfTimeRange experimentTRange = experiment.getTimeRange(); | |
546 | ||
547 | // send request and received the adjusted time used | |
548 | TmfTimeRange adjustedTimeRange = initialExperimentDataRequest(this, | |
549 | experimentTRange); | |
550 | ||
551 | // initialize widget time boundaries and filtering parameters | |
552 | ModelUpdateInit(experimentTRange, adjustedTimeRange, this); | |
553 | } else { | |
554 | TraceDebug.debug("No selected experiment information available"); | |
555 | } | |
556 | } | |
557 | ||
558 | private void hookContextMenu() { | |
559 | MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ | |
560 | menuMgr.setRemoveAllWhenShown(true); | |
561 | menuMgr.addMenuListener(new IMenuListener() { | |
562 | public void menuAboutToShow(IMenuManager manager) { | |
563 | ControlFlowView.this.fillContextMenu(manager); | |
564 | } | |
565 | }); | |
566 | Menu menu = menuMgr.createContextMenu(tableViewer.getControl()); | |
567 | tableViewer.getControl().setMenu(menu); | |
568 | getSite().registerContextMenu(menuMgr, tableViewer); | |
569 | } | |
570 | ||
571 | private void contributeToActionBars() { | |
572 | IActionBars bars = getViewSite().getActionBars(); | |
573 | fillLocalPullDown(bars.getMenuManager()); | |
574 | fillLocalToolBar(bars.getToolBarManager()); | |
575 | } | |
576 | ||
577 | private void fillLocalPullDown(IMenuManager manager) { | |
578 | manager.add(new Separator()); | |
579 | // manager.add(showLegend); | |
580 | manager.add(new Separator()); | |
581 | manager.add(resetScale); | |
582 | manager.add(nextEvent); | |
583 | manager.add(prevEvent); | |
584 | manager.add(nextTrace); | |
585 | manager.add(prevTrace); | |
586 | // manager.add(filterTraces); | |
587 | manager.add(zoomIn); | |
588 | manager.add(zoomOut); | |
589 | manager.add(zoomFilter); | |
590 | manager.add(new Separator()); | |
591 | } | |
592 | ||
593 | private void fillContextMenu(IMenuManager manager) { | |
594 | // manager.add(showLegend); | |
595 | manager.add(new Separator()); | |
596 | manager.add(resetScale); | |
597 | manager.add(nextEvent); | |
598 | manager.add(prevEvent); | |
599 | manager.add(nextTrace); | |
600 | manager.add(prevTrace); | |
601 | // manager.add(showLegend); | |
602 | // manager.add(filterTraces); | |
603 | manager.add(zoomIn); | |
604 | manager.add(zoomOut); | |
605 | manager.add(zoomFilter); | |
606 | manager.add(new Separator()); | |
607 | manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); | |
608 | } | |
609 | ||
610 | private void fillLocalToolBar(IToolBarManager manager) { | |
611 | // manager.add(showLegend); | |
612 | manager.add(new Separator()); | |
613 | manager.add(resetScale); | |
614 | manager.add(nextEvent); | |
615 | manager.add(prevEvent); | |
616 | manager.add(nextTrace); | |
617 | manager.add(prevTrace); | |
618 | // manager.add(filterTraces); | |
619 | manager.add(zoomIn); | |
620 | manager.add(zoomOut); | |
621 | manager.add(zoomFilter); | |
622 | manager.add(new Separator()); | |
623 | } | |
624 | ||
625 | private void makeActions() { | |
626 | // resetScale | |
627 | resetScale = new Action() { | |
628 | @Override | |
629 | public void run() { | |
630 | if (tsfviewer != null) { | |
631 | tsfviewer.resetStartFinishTime(); | |
632 | } | |
633 | ||
634 | } | |
635 | }; | |
636 | resetScale.setText(Messages.getString("ControlFlowView.Action.Reset")); //$NON-NLS-1$ | |
637 | resetScale.setToolTipText(Messages | |
638 | .getString("ControlFlowView.Action.Reset.ToolTip")); //$NON-NLS-1$ | |
639 | resetScale.setImageDescriptor(AbstractUIPlugin | |
640 | .imageDescriptorFromPlugin(Messages | |
641 | .getString("ControlFlowView.tmf.UI"), | |
642 | "icons/home_nav.gif")); | |
643 | ||
644 | // nextEvent | |
645 | nextEvent = new Action() { | |
646 | @Override | |
647 | public void run() { | |
648 | if (tsfviewer != null) { | |
649 | tsfviewer.selectNextEvent(); | |
650 | } | |
651 | } | |
652 | }; | |
653 | nextEvent.setText(Messages | |
654 | .getString("ControlFlowView.Action.NextEvent")); //$NON-NLS-1$ | |
655 | nextEvent.setToolTipText(Messages | |
656 | .getString("ControlFlowView.Action.NextEvent.Tooltip")); //$NON-NLS-1$ | |
657 | nextEvent.setImageDescriptor(AbstractUIPlugin | |
658 | .imageDescriptorFromPlugin(Messages | |
659 | .getString("ControlFlowView.tmf.UI"), | |
660 | "icons/next_event.gif")); | |
661 | ||
662 | // prevEvent | |
663 | prevEvent = new Action() { | |
664 | @Override | |
665 | public void run() { | |
666 | if (tsfviewer != null) { | |
667 | tsfviewer.selectPrevEvent(); | |
668 | } | |
669 | } | |
670 | }; | |
671 | prevEvent.setText(Messages | |
672 | .getString("ControlFlowView.Action.PrevEvent")); //$NON-NLS-1$ | |
673 | prevEvent.setToolTipText(Messages | |
674 | .getString("ControlFlowView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$ | |
675 | prevEvent.setImageDescriptor(AbstractUIPlugin | |
676 | .imageDescriptorFromPlugin(Messages | |
677 | .getString("ControlFlowView.tmf.UI"), | |
678 | "icons/prev_event.gif")); | |
679 | ||
680 | // nextTrace | |
681 | nextTrace = new Action() { | |
682 | @Override | |
683 | public void run() { | |
684 | if (tsfviewer != null) { | |
685 | tsfviewer.selectNextTrace(); | |
686 | } | |
687 | } | |
688 | }; | |
689 | nextTrace.setText(Messages | |
690 | .getString("ControlFlowView.Action.NextProcess")); //$NON-NLS-1$ | |
691 | nextTrace.setToolTipText(Messages | |
692 | .getString("ControlFlowView.Action.NextProcess.ToolTip")); //$NON-NLS-1$ | |
693 | nextTrace.setImageDescriptor(AbstractUIPlugin | |
694 | .imageDescriptorFromPlugin(Messages | |
695 | .getString("ControlFlowView.tmf.UI"), | |
696 | "icons/next_item.gif")); | |
697 | ||
698 | // prevTrace | |
699 | prevTrace = new Action() { | |
700 | @Override | |
701 | public void run() { | |
702 | if (tsfviewer != null) { | |
703 | tsfviewer.selectPrevTrace(); | |
704 | } | |
705 | } | |
706 | }; | |
707 | prevTrace.setText(Messages | |
708 | .getString("ControlFlowView.Action.PreviousProcess")); //$NON-NLS-1$ | |
709 | prevTrace.setToolTipText(Messages | |
710 | .getString("ControlFlowView.Action.PreviousProcess.Tooltip")); //$NON-NLS-1$ | |
711 | prevTrace.setImageDescriptor(AbstractUIPlugin | |
712 | .imageDescriptorFromPlugin(Messages | |
713 | .getString("ControlFlowView.tmf.UI"), | |
714 | "icons/prev_item.gif")); | |
715 | ||
716 | // showLegend | |
717 | showLegend = new Action() { | |
718 | @Override | |
719 | public void run() { | |
720 | if (tsfviewer != null) { | |
721 | tsfviewer.showLegend(); | |
722 | } | |
723 | } | |
724 | }; | |
725 | showLegend.setText(Messages.getString("ControlFlowView.Action.Legend")); //$NON-NLS-1$ | |
726 | showLegend.setToolTipText(Messages | |
727 | .getString("ControlFlowView.Action.Legend.ToolTip")); //$NON-NLS-1$ | |
728 | ||
729 | // filterTraces | |
730 | filterTraces = new Action() { | |
731 | @Override | |
732 | public void run() { | |
733 | if (tsfviewer != null) { | |
734 | tsfviewer.filterTraces(); | |
735 | } | |
736 | } | |
737 | }; | |
738 | filterTraces.setText(Messages | |
739 | .getString("ControlFlowView.Action.Filter")); //$NON-NLS-1$ | |
740 | filterTraces.setToolTipText(Messages | |
741 | .getString("ControlFlowView.Action.Filter.ToolTip")); //$NON-NLS-1$ | |
742 | filterTraces.setImageDescriptor(AbstractUIPlugin | |
743 | .imageDescriptorFromPlugin(Messages | |
744 | .getString("ControlFlowView.tmf.UI"), | |
745 | "icons/filter_items.gif")); | |
746 | ||
747 | // zoomIn | |
748 | zoomIn = new Action() { | |
749 | @Override | |
750 | public void run() { | |
751 | if (tsfviewer != null) { | |
752 | tsfviewer.zoomIn(); | |
753 | } | |
754 | } | |
755 | }; | |
756 | zoomIn.setText(Messages.getString("ControlFlowView.Action.ZoomIn")); //$NON-NLS-1$ | |
757 | zoomIn.setToolTipText(Messages | |
758 | .getString("ControlFlowView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$ | |
759 | zoomIn.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( | |
760 | Messages.getString("ControlFlowView.tmf.UI"), | |
761 | "icons/zoomin_nav.gif")); | |
762 | ||
763 | // zoomOut | |
764 | zoomOut = new Action() { | |
765 | @Override | |
766 | public void run() { | |
767 | if (tsfviewer != null) { | |
768 | tsfviewer.zoomOut(); | |
769 | } | |
770 | } | |
771 | }; | |
772 | zoomOut.setText(Messages.getString("ControlFlowView.Action.ZoomOut")); //$NON-NLS-1$ | |
773 | zoomOut.setToolTipText(Messages | |
774 | .getString("ControlFlowView.Action.ZoomOut.tooltip")); //$NON-NLS-1$ | |
775 | zoomOut.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( | |
776 | Messages.getString("ControlFlowView.tmf.UI"), | |
777 | "icons/zoomout_nav.gif")); | |
778 | ||
779 | // zoomFilter | |
780 | zoomFilter = new Action() { | |
781 | @Override | |
782 | public void run() { | |
783 | // Nothing to do, however the selection status is needed by the | |
784 | // application | |
785 | } | |
786 | }; | |
787 | zoomFilter.setText(Messages | |
788 | .getString("ControlFlowView.Action.ZoomFilter")); //$NON-NLS-1$ | |
789 | zoomFilter.setToolTipText(Messages | |
790 | .getString("ControlFlowView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$ | |
791 | zoomFilter.setImageDescriptor(AbstractUIPlugin | |
792 | .imageDescriptorFromPlugin(Messages | |
793 | .getString("ControlFlowView.tmf.UI"), | |
794 | "icons/filter_items.gif")); | |
795 | zoomFilter.setChecked(false); | |
796 | ||
797 | // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED); | |
798 | ||
799 | doubleClickAction = new Action() { | |
800 | @Override | |
801 | public void run() { | |
802 | ISelection selection = tableViewer.getSelection(); | |
803 | Object obj = ((IStructuredSelection) selection) | |
804 | .getFirstElement(); | |
805 | showMessage("Double-click detected on " + obj.toString()); //$NON-NLS-1$ | |
806 | } | |
807 | }; | |
808 | } | |
809 | ||
810 | private void hookDoubleClickAction() { | |
811 | tableViewer.addDoubleClickListener(new IDoubleClickListener() { | |
812 | public void doubleClick(DoubleClickEvent event) { | |
813 | doubleClickAction.run(); | |
814 | } | |
815 | }); | |
816 | } | |
817 | ||
818 | private void showMessage(String message) { | |
819 | MessageDialog.openInformation(tableViewer.getControl().getShell(), | |
820 | Messages.getString("ControlFlowView.msgSlogan"), message); //$NON-NLS-1$ | |
821 | } | |
822 | ||
823 | /** | |
824 | * Passing the focus request to the viewer's control. | |
825 | */ | |
826 | @Override | |
827 | public void setFocus() { | |
828 | tableViewer.getControl().setFocus(); | |
829 | } | |
830 | ||
831 | /* | |
832 | * (non-Javadoc) | |
833 | * | |
834 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# | |
835 | * tsfTmProcessSelEvent | |
836 | * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent | |
837 | * ) | |
838 | */ | |
9aae0442 | 839 | @Override |
6e512b93 ASL |
840 | public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event) { |
841 | // common implementation | |
842 | super.tsfTmProcessSelEvent(event); | |
843 | ||
844 | // Reselect the table viewer to widget selection | |
845 | ISelection sel = tsfviewer.getSelectionTrace(); | |
846 | if (sel != null && !sel.isEmpty()) { | |
847 | tableViewer.setSelection(sel); | |
848 | } | |
849 | } | |
850 | ||
851 | /* | |
852 | * (non-Javadoc) | |
853 | * | |
854 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis. | |
855 | * ITmfTimeScaleSelectionListener | |
856 | * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools | |
857 | * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent) | |
858 | */ | |
9aae0442 | 859 | @Override |
6e512b93 ASL |
860 | public synchronized void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event) { |
861 | super.tsfTmProcessTimeScaleEvent(event); | |
862 | } | |
863 | ||
864 | private void applyTableLayout(Table table) { | |
865 | for (int i = 0; i < columnNames.length; i++) { | |
866 | TableColumn tableColumn = new TableColumn(table, SWT.LEFT); | |
867 | tableColumn.setText(columnNames[i]); | |
868 | tableColumn.pack(); | |
869 | } | |
870 | table.setHeaderVisible(true); | |
871 | table.setLinesVisible(true); | |
872 | } | |
873 | ||
874 | /* | |
875 | * (non-Javadoc) | |
876 | * | |
877 | * @see | |
878 | * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel | |
879 | * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model. | |
880 | * ITmfTimeAnalysisEntry[], long, long, boolean, long, long, | |
881 | * java.lang.Object) | |
882 | */ | |
9aae0442 | 883 | @Override |
6e512b93 ASL |
884 | public void displayModel(final ITmfTimeAnalysisEntry[] items, |
885 | final long startBoundTime, final long endBoundTime, | |
886 | final boolean updateTimeBounds, final long startVisibleWindow, | |
887 | final long endVisibleWindow, final Object source) { | |
888 | final Table table = tableViewer.getTable(); | |
889 | Display display = table.getDisplay(); | |
890 | ||
891 | // Perform the updates on the UI thread) | |
892 | display.asyncExec(new Runnable() { | |
893 | public void run() { | |
894 | ||
895 | tableViewer.setInput(items); // This shall be the minimal | |
896 | // initial | |
897 | tableFilter = new ViewProcessFilter(tableViewer); | |
898 | tableViewer.setFilters(new ViewerFilter[] { tableFilter }); | |
899 | ||
900 | resizeTableColumns(table); | |
901 | table.update(); | |
902 | tableViewer.refresh(); | |
903 | ||
904 | tsfviewer.display(items, startBoundTime, endBoundTime, | |
905 | updateTimeBounds); | |
906 | ||
907 | // validate visible boundaries | |
908 | if (startVisibleWindow > -1 && endVisibleWindow > -1) { | |
909 | tsfviewer.setSelectVisTimeWindow(startVisibleWindow, | |
910 | endVisibleWindow, source); | |
911 | } | |
912 | ||
913 | tsfviewer.resizeControls(); | |
914 | ||
915 | // Adjust the size of the vertical scroll bar to fit the | |
916 | // contents | |
917 | if (scrollFrame != null) { | |
918 | updateScrolls(scrollFrame); | |
919 | } | |
920 | } | |
921 | }); | |
922 | } | |
923 | ||
924 | @Override | |
925 | public void dispose() { | |
926 | // dispose parent resources | |
927 | super.dispose(); | |
928 | ||
929 | tsfviewer.removeFilterSelectionListner(this); | |
930 | tsfviewer.removeWidgetSelectionListner(this); | |
931 | tsfviewer.removeWidgetTimeScaleSelectionListner(this); | |
932 | tableViewer = null; | |
933 | tsfviewer = null; | |
934 | } | |
935 | ||
936 | /** | |
937 | * @param tableComposite | |
938 | * @param table | |
939 | */ | |
940 | private synchronized void resizeTableColumns(Table table) { | |
941 | if (table != null) { | |
942 | Composite parent = table.getParent(); | |
943 | int tableWidthSum = parent.getBorderWidth(); | |
944 | ||
945 | TableColumn[] columns = table.getColumns(); | |
946 | for (TableColumn column : columns) { | |
947 | column.pack(); | |
948 | tableWidthSum += column.getWidth(); | |
949 | } | |
950 | } | |
951 | } | |
952 | ||
953 | // @Override | |
954 | public void tmfTaProcessFilterSelection(TmfTimeFilterSelectionEvent event) { | |
955 | if (tableFilter != null) { | |
956 | Vector<ITmfTimeAnalysisEntry> filteredout = event.getFilteredOut(); | |
957 | if (filteredout != null) { | |
958 | tableFilter.setFilter(filteredout); | |
959 | } else { | |
960 | tableFilter.setFilter(new Vector<ITmfTimeAnalysisEntry>()); | |
961 | } | |
962 | tableViewer.refresh(); | |
963 | } | |
964 | } | |
965 | ||
966 | /** | |
967 | * @param scrollFrame | |
968 | * @param wrapper | |
969 | */ | |
970 | private void updateScrolls(final ScrolledComposite scrollFrame) { | |
971 | scrollFrame.setMinSize(tableViewer.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT)); | |
972 | } | |
973 | ||
974 | /** | |
975 | * Registers as listener of time selection from other views | |
976 | * | |
977 | * @param signal | |
978 | */ | |
9aae0442 | 979 | @Override |
6e512b93 ASL |
980 | @TmfSignalHandler |
981 | public void synchToTime(TmfTimeSynchSignal signal) { | |
982 | super.synchToTime(signal); | |
983 | } | |
984 | ||
985 | /** | |
986 | * Annotation Registers as listener of time range selection from other views | |
987 | * The implementation handles the entry of the signal. | |
988 | * | |
989 | * @param signal | |
990 | */ | |
991 | @TmfSignalHandler | |
992 | public void synchToTimeRange(TmfRangeSynchSignal signal) { | |
993 | if (zoomFilter != null) { | |
994 | synchToTimeRange(signal, zoomFilter.isChecked()); | |
995 | } | |
996 | } | |
997 | ||
998 | @Override | |
999 | public void modelIncomplete(ILttngSyntEventRequest request) { | |
1000 | // Nothing to do | |
1001 | // The data will be refreshed on the next request | |
1002 | } | |
1003 | ||
1004 | /* | |
1005 | * (non-Javadoc) | |
1006 | * | |
1007 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# | |
1008 | * getEventProcessor() | |
1009 | */ | |
1010 | @Override | |
1011 | public ITransEventProcessor getEventProcessor() { | |
1012 | return FlowEventToHandlerFactory.getInstance(); | |
1013 | } | |
1014 | ||
1015 | /** | |
1016 | * @param signal | |
1017 | */ | |
1018 | @TmfSignalHandler | |
1019 | public void experimentSelected( | |
1020 | TmfExperimentSelectedSignal<? extends TmfEvent> signal) { | |
1021 | if (signal != null) { | |
1022 | TmfTimeRange experimentTRange = signal.getExperiment() | |
1023 | .getTimeRange(); | |
1024 | ||
1025 | // prepare time intervals in widget | |
1026 | ModelUpdateInit(experimentTRange, experimentTRange, signal | |
1027 | .getSource()); | |
1028 | ||
1029 | // request initial data | |
1030 | initialExperimentDataRequest(signal | |
1031 | .getSource(), experimentTRange); | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | /** | |
1036 | * @param source | |
1037 | * @param experimentTRange | |
1038 | * @return Adjusted time window used for the request (smaller window to | |
1039 | * initialize view) | |
1040 | */ | |
1041 | private TmfTimeRange initialExperimentDataRequest(Object source, | |
1042 | TmfTimeRange experimentTRange) { | |
1043 | // Adjust the initial time window to a shorter interval to allow | |
1044 | // user to select the interesting area based on the perspective | |
1045 | TmfTimeRange initTimeWindow = getInitTRange(experimentTRange); | |
1046 | ||
1047 | dataRequest(initTimeWindow, experimentTRange, true); | |
1048 | if (TraceDebug.isDEBUG()) { | |
1049 | TraceDebug.debug("Initialization request time range is: " | |
1050 | + initTimeWindow.getStartTime().toString() + "-" | |
1051 | + initTimeWindow.getEndTime().toString()); | |
1052 | } | |
1053 | ||
1054 | return initTimeWindow; | |
1055 | } | |
1056 | ||
1057 | // *** HACK *** | |
1058 | // | |
1059 | // | |
1060 | // | |
1061 | public int checkForSWTBugItemHeightAdjustement() { | |
1062 | int returnedAjustement = 0; | |
1063 | String desktopSessionName = System.getenv("DESKTOP_SESSION"); | |
1064 | ||
1065 | // Gnome : most common case, no adjustement | |
1066 | if ( desktopSessionName.equals("gnome") ) { | |
1067 | returnedAjustement = 0; | |
1068 | } | |
1069 | // Kde : ajustement of 2 is needed | |
1070 | else if ( desktopSessionName.equals("kde") ) { | |
1071 | returnedAjustement = 2; | |
1072 | } | |
1073 | ||
1074 | return returnedAjustement; | |
1075 | } | |
1076 | ||
1077 | /* | |
1078 | * (non-Javadoc) | |
1079 | * | |
1080 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# | |
1081 | * getParamsUpdater() | |
1082 | */ | |
1083 | @Override | |
1084 | protected ParamsUpdater getParamsUpdater() { | |
1085 | return FlowModelFactory.getParamsUpdater(); | |
1086 | } | |
1087 | ||
1088 | /* | |
1089 | * (non-Javadoc) | |
1090 | * | |
1091 | * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView# | |
1092 | * getItemContainer() | |
1093 | */ | |
1094 | @Override | |
1095 | protected ItemContainer<?> getItemContainer() { | |
1096 | return FlowModelFactory.getProcContainer(); | |
1097 | } | |
1098 | } |