1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Alvaro Sanchez-Leon - Initial implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.resources
;
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
.linuxtools
.internal
.lttng
.core
.control
.LttngCoreProviderFactory
;
22 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.request
.ILttngSyntEventRequest
;
23 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.evProcessor
.ITransEventProcessor
;
24 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.TraceDebug
;
25 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.model
.trange
.ItemContainer
;
26 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.viewers
.timeAnalysis
.ITmfTimeScaleSelectionListener
;
27 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.viewers
.timeAnalysis
.ITmfTimeSelectionListener
;
28 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
29 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.viewers
.timeAnalysis
.TmfTimeSelectionEvent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.viewers
.timeAnalysis
.TmfViewerFactory
;
31 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
32 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.common
.AbsTimeUpdateView
;
33 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.common
.ParamsUpdater
;
34 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.resources
.evProcessor
.ResourcesEventToHandlerFactory
;
35 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.resources
.model
.ResourceModelFactory
;
36 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.resources
.model
.ResourcesTimeRangeViewerProvider
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.experiment
.TmfExperiment
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
.ExecutionType
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentRangeUpdatedSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentUpdatedSignal
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
47 import org
.eclipse
.swt
.SWT
;
48 import org
.eclipse
.swt
.layout
.FillLayout
;
49 import org
.eclipse
.swt
.widgets
.Composite
;
50 import org
.eclipse
.swt
.widgets
.Display
;
51 import org
.eclipse
.swt
.widgets
.Menu
;
52 import org
.eclipse
.ui
.IActionBars
;
53 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
54 import org
.eclipse
.ui
.PlatformUI
;
55 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
61 public class ResourcesView
extends AbsTimeUpdateView
implements
62 ITmfTimeSelectionListener
, ITmfTimeScaleSelectionListener
{
64 // ========================================================================
66 // ========================================================================
67 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.resources"; //$NON-NLS-1$
69 // private int totalNumItems = 0;
71 private Action resetScale
;
72 private Action nextEvent
;
73 private Action prevEvent
;
74 private Action nextTrace
;
75 private Action prevTrace
;
76 private Action showLegend
;
77 private Action filterTraces
;
78 private Action zoomIn
;
79 private Action zoomOut
;
80 private Action zoomFilter
;
81 private Composite top
;
83 private TmfTimeRange initTimeRange
= TmfTimeRange
.NULL_RANGE
;
85 // private static SimpleDateFormat stimeformat = new SimpleDateFormat(
86 // "yy/MM/dd HH:mm:ss");
88 // private TraceModelImplFactory fact;
90 // ========================================================================
92 // ========================================================================
97 public ResourcesView() {
101 // ========================================================================
103 // ========================================================================
106 * This is a callback that will allow us to create the viewer and initialize
110 public void createPartControl(Composite parent
) {
111 top
= new Composite(parent
, SWT
.BORDER
);
113 top
.setLayout(new FillLayout());
114 tsfviewer
= TmfViewerFactory
.createViewer(top
, new ResourcesTimeRangeViewerProvider(getParamsUpdater()));
116 tsfviewer
.addWidgetSelectionListner(this);
117 tsfviewer
.addWidgetTimeScaleSelectionListner(this);
119 // Traces shall not be grouped to allow synchronisation
120 tsfviewer
.groupTraces(true);
121 tsfviewer
.setAcceptSelectionAPIcalls(true);
123 // Viewer to notify selection to this class
124 // This class will synchronise selections with table.
125 // tsfviewer.addWidgetSelectionListner(this);
126 // tsfviewer.addWidgetTimeScaleSelectionListner(this);
128 // Create the help context id for the viewer's control
129 // TODO: Associate with help system
130 PlatformUI
.getWorkbench().getHelpSystem().setHelp(
131 tsfviewer
.getControl(),
132 "org.eclipse.linuxtools.lttng.ui.views.resource.view"); //$NON-NLS-1$
136 contributeToActionBars();
138 // // Read relevant values
139 // int timeSpaceWidth = tsfviewer.getTimeSpace();
140 // if (timeSpaceWidth < 0) {
141 // timeSpaceWidth = -timeSpaceWidth;
144 TmfExperiment
<?
> experiment
= TmfExperiment
.getCurrentExperiment();
145 if (experiment
!= null) {
146 TmfTimeRange experimentTRange
= experiment
.getTimeRange();
147 if (experimentTRange
!= TmfTimeRange
.NULL_RANGE
) {
148 long time0
= experimentTRange
.getStartTime().getValue();
149 long time1
= experimentTRange
.getEndTime().getValue();
150 ParamsUpdater paramUpdater
= getParamsUpdater();
151 paramUpdater
.update(time0
, time1
); // , timeSpaceWidth);
153 // send the initial request and obtained the adjusted time used
154 TmfTimeRange adjustedTimeRange
= initialExperimentDataRequest(this, experimentTRange
);
156 // initialize widget time boundaries and filtering parameters
157 modelUpdateInit(experimentTRange
, adjustedTimeRange
, this);
160 TraceDebug
.debug("No selected experiment information available"); //$NON-NLS-1$
164 private void hookContextMenu() {
165 MenuManager menuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
166 menuMgr
.setRemoveAllWhenShown(true);
167 menuMgr
.addMenuListener(new IMenuListener() {
169 public void menuAboutToShow(IMenuManager manager
) {
170 ResourcesView
.this.fillContextMenu(manager
);
174 Menu menu
= menuMgr
.createContextMenu(tsfviewer
.getControl());
175 tsfviewer
.getControl().setMenu(menu
);
177 .registerContextMenu(menuMgr
, tsfviewer
.getSelectionProvider());
180 private void contributeToActionBars() {
181 IActionBars bars
= getViewSite().getActionBars();
182 fillLocalPullDown(bars
.getMenuManager());
183 fillLocalToolBar(bars
.getToolBarManager());
186 private void fillLocalPullDown(IMenuManager manager
) {
187 manager
.add(new Separator());
188 manager
.add(showLegend
);
189 manager
.add(new Separator());
190 manager
.add(resetScale
);
191 manager
.add(nextEvent
);
192 manager
.add(prevEvent
);
193 manager
.add(nextTrace
);
194 manager
.add(prevTrace
);
195 // manager.add(filterTraces);
197 manager
.add(zoomOut
);
198 manager
.add(zoomFilter
);
199 manager
.add(new Separator());
202 private void fillContextMenu(IMenuManager manager
) {
203 manager
.add(showLegend
);
204 manager
.add(new Separator());
205 manager
.add(resetScale
);
206 manager
.add(nextEvent
);
207 manager
.add(prevEvent
);
208 manager
.add(nextTrace
);
209 manager
.add(prevTrace
);
210 // manager.add(showLegend);
211 // manager.add(filterTraces);
213 manager
.add(zoomOut
);
214 manager
.add(zoomFilter
);
215 manager
.add(new Separator());
216 manager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
219 private void fillLocalToolBar(IToolBarManager manager
) {
220 manager
.add(showLegend
);
221 manager
.add(new Separator());
222 manager
.add(resetScale
);
223 manager
.add(nextEvent
);
224 manager
.add(prevEvent
);
225 manager
.add(nextTrace
);
226 manager
.add(prevTrace
);
227 // manager.add(filterTraces);
229 manager
.add(zoomOut
);
230 manager
.add(zoomFilter
);
231 manager
.add(new Separator());
234 private void makeActions() {
236 resetScale
= new Action() {
239 if (tsfviewer
!= null) {
240 tsfviewer
.resetStartFinishTime();
245 resetScale
.setText(Messages
.getString("ResourcesView.Action.Reset")); //$NON-NLS-1$
246 resetScale
.setToolTipText(Messages
.getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
247 resetScale
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
248 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/home_nav.gif")); //$NON-NLS-1$ //$NON-NLS-2$
251 nextEvent
= new Action() {
254 if (tsfviewer
!= null) {
255 tsfviewer
.selectNextEvent();
259 nextEvent
.setText(Messages
.getString("ResourcesView.Action.NextEvent")); //$NON-NLS-1$
260 nextEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
261 nextEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
262 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/next_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
265 prevEvent
= new Action() {
268 if (tsfviewer
!= null) {
269 tsfviewer
.selectPrevEvent();
273 prevEvent
.setText(Messages
.getString("ResourcesView.Action.PrevEvent")); //$NON-NLS-1$
274 prevEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
275 prevEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
276 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/prev_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
279 nextTrace
= new Action() {
282 if (tsfviewer
!= null) {
283 tsfviewer
.selectNextTrace();
287 nextTrace
.setText(Messages
.getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
288 nextTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
289 nextTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
290 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/next_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
293 prevTrace
= new Action() {
296 if (tsfviewer
!= null) {
297 tsfviewer
.selectPrevTrace();
301 prevTrace
.setText(Messages
.getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
302 prevTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
303 prevTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
304 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/prev_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
307 showLegend
= new Action() {
310 if (tsfviewer
!= null) {
311 tsfviewer
.showLegend();
315 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
316 showLegend
.setToolTipText(Messages
.getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
319 filterTraces
= new Action() {
322 if (tsfviewer
!= null) {
323 tsfviewer
.filterTraces();
327 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
328 filterTraces
.setToolTipText(Messages
.getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
329 filterTraces
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
330 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
333 zoomIn
= new Action() {
336 if (tsfviewer
!= null) {
341 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
342 zoomIn
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
343 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
344 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/zoomin_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
347 zoomOut
= new Action() {
350 if (tsfviewer
!= null) {
355 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
356 zoomOut
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
357 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
358 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/zoomout_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
361 zoomFilter
= new Action() {
364 // Nothing to do, however the selection status is needed by the
369 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
370 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
371 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
372 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
373 zoomFilter
.setChecked(false);
375 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
379 * Passing the focus request to the viewer's control.
382 public void setFocus() {
383 tsfviewer
.getControl().setFocus();
389 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
390 * tsfTmProcessSelEvent
391 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
395 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
396 // common implementation
397 super.tsfTmProcessSelEvent(event
);
403 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
404 * ITmfTimeScaleSelectionListener
405 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
406 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
409 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
410 super.tsfTmProcessTimeScaleEvent(event
);
417 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
418 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
419 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
423 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
424 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
425 final long endVisibleWindow
, final Object source
) {
427 // Return if disposed
428 if ((tsfviewer
== null) || (tsfviewer
.getControl().isDisposed())) return;
430 Display display
= tsfviewer
.getControl().getDisplay();
431 display
.asyncExec(new Runnable() {
434 if ((tsfviewer
!= null) && (!tsfviewer
.getControl().isDisposed())) {
435 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
436 // validate visible boundaries
437 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
438 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
440 tsfviewer
.resizeControls();
447 public void dispose() {
448 // dispose parent resources
451 tsfviewer
.removeWidgetSelectionListner(this);
452 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
457 * Registers as listener of time selection from other tmf views
463 public void synchToTime(TmfTimeSynchSignal signal
) {
464 super.synchToTime(signal
);
468 * Annotation Registers as listener of time range selection from other views
469 * The implementation handles the entry of the signal.
474 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
475 if (zoomFilter
!= null) {
476 synchToTimeRange(signal
, zoomFilter
.isChecked());
481 public void modelIncomplete(ILttngSyntEventRequest request
) {
483 // The data will be refreshed on the next request
489 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
490 * getEventProcessor()
493 public ITransEventProcessor
getEventProcessor() {
494 return ResourcesEventToHandlerFactory
.getInstance();
501 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
502 if (signal
!= null) {
503 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
505 initTimeRange
= TmfTimeRange
.NULL_RANGE
;
506 if (experimentTRange
!= TmfTimeRange
.NULL_RANGE
) {
507 // prepare time intervals in widget
508 modelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
510 // request initial data
511 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
517 public void experimentRangeUpdated(TmfExperimentRangeUpdatedSignal signal
) {
518 if (initTimeRange
== TmfTimeRange
.NULL_RANGE
&& signal
.getExperiment().equals(TmfExperiment
.getCurrentExperiment())) {
519 TmfTimeRange experimentTRange
= signal
.getRange();
521 if (experimentTRange
!= TmfTimeRange
.NULL_RANGE
) {
522 // prepare time intervals in widget
523 modelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
525 // request initial data
526 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
532 public void experimentUpdated(TmfExperimentUpdatedSignal signal
) {
533 if (signal
.getExperiment().equals(TmfExperiment
.getCurrentExperiment())) {
534 final TmfTimeRange range
= signal
.getExperiment().getTimeRange();
535 if (range
!= TmfTimeRange
.NULL_RANGE
) {
536 Display
.getDefault().asyncExec(new Runnable() {
539 if ((tsfviewer
!= null) && (!tsfviewer
.getControl().isDisposed())) {
540 tsfviewer
.setTimeBounds(range
.getStartTime().getValue(), range
.getEndTime().getValue());
549 * @param experimentTRange
550 * @return Adjusted time window used for the request (smaller window to
553 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
554 // Adjust the initial time window to a shorter interval to allow
555 // user to select the interesting area based on the perspective
556 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
558 eventRequest(initTimeWindow
, experimentTRange
, true, ExecutionType
.FOREGROUND
);
559 if (TraceDebug
.isDEBUG()) {
560 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-" //$NON-NLS-1$ //$NON-NLS-2$
561 + initTimeWindow
.getEndTime().toString());
564 initTimeRange
= initTimeWindow
;
565 return initTimeWindow
;
571 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
575 protected ParamsUpdater
getParamsUpdater() {
576 return ResourceModelFactory
.getParamsUpdater();
582 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
586 protected ItemContainer
<?
> getItemContainer() {
587 return ResourceModelFactory
.getResourceContainer();
592 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#getProviderId()
595 protected int getProviderId() {
596 return LttngCoreProviderFactory
.RESOURCE_LTTNG_SYTH_EVENT_PROVIDER
;