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
.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
.lttng
.control
.LttngCoreProviderFactory
;
22 import org
.eclipse
.linuxtools
.lttng
.request
.ILttngSyntEventRequest
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ITransEventProcessor
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.ItemContainer
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.AbsTimeUpdateView
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.ParamsUpdater
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
.ResourcesEventToHandlerFactory
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.model
.ResourceModelFactory
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.model
.ResourcesTimeRangeViewerProvider
;
31 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
33 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
34 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
.ExecutionType
;
35 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentRangeUpdatedSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
37 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfRangeSynchSignal
;
38 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
39 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTimeSynchSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.TmfViewerFactory
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeScaleSelectionListener
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeSelectionListener
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
44 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeSelectionEvent
;
45 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
46 import org
.eclipse
.swt
.SWT
;
47 import org
.eclipse
.swt
.layout
.FillLayout
;
48 import org
.eclipse
.swt
.widgets
.Composite
;
49 import org
.eclipse
.swt
.widgets
.Display
;
50 import org
.eclipse
.swt
.widgets
.Menu
;
51 import org
.eclipse
.ui
.IActionBars
;
52 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
53 import org
.eclipse
.ui
.PlatformUI
;
54 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
60 public class ResourcesView
extends AbsTimeUpdateView
implements
61 ITmfTimeSelectionListener
, ITmfTimeScaleSelectionListener
{
63 // ========================================================================
65 // ========================================================================
66 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.resources"; //$NON-NLS-1$
68 // private int totalNumItems = 0;
70 private Action resetScale
;
71 private Action nextEvent
;
72 private Action prevEvent
;
73 private Action nextTrace
;
74 private Action prevTrace
;
75 private Action showLegend
;
76 private Action filterTraces
;
77 private Action zoomIn
;
78 private Action zoomOut
;
79 private Action zoomFilter
;
80 private Composite top
;
82 private TmfTimeRange initTimeRange
= TmfTimeRange
.Null
;
84 // private static SimpleDateFormat stimeformat = new SimpleDateFormat(
85 // "yy/MM/dd HH:mm:ss");
87 // private TraceModelImplFactory fact;
89 // ========================================================================
91 // ========================================================================
96 public ResourcesView() {
100 // ========================================================================
102 // ========================================================================
105 * This is a callback that will allow us to create the viewer and initialize
109 public void createPartControl(Composite parent
) {
110 top
= new Composite(parent
, SWT
.BORDER
);
112 top
.setLayout(new FillLayout());
113 tsfviewer
= TmfViewerFactory
.createViewer(top
, new ResourcesTimeRangeViewerProvider(getParamsUpdater()));
115 tsfviewer
.addWidgetSelectionListner(this);
116 tsfviewer
.addWidgetTimeScaleSelectionListner(this);
118 // Traces shall not be grouped to allow synchronisation
119 tsfviewer
.groupTraces(true);
120 tsfviewer
.setAcceptSelectionAPIcalls(true);
122 // Viewer to notify selection to this class
123 // This class will synchronise selections with table.
124 // tsfviewer.addWidgetSelectionListner(this);
125 // tsfviewer.addWidgetTimeScaleSelectionListner(this);
127 // Create the help context id for the viewer's control
128 // TODO: Associate with help system
129 PlatformUI
.getWorkbench().getHelpSystem().setHelp(
130 tsfviewer
.getControl(),
131 "org.eclipse.linuxtools.lttng.ui.views.resource.view"); //$NON-NLS-1$
135 contributeToActionBars();
137 // // Read relevant values
138 // int timeSpaceWidth = tsfviewer.getTimeSpace();
139 // if (timeSpaceWidth < 0) {
140 // timeSpaceWidth = -timeSpaceWidth;
143 TmfExperiment
<?
> experiment
= TmfExperiment
.getCurrentExperiment();
144 if (experiment
!= null) {
145 TmfTimeRange experimentTRange
= experiment
.getTimeRange();
146 if (experimentTRange
!= TmfTimeRange
.Null
) {
147 long time0
= experimentTRange
.getStartTime().getValue();
148 long time1
= experimentTRange
.getEndTime().getValue();
149 ParamsUpdater paramUpdater
= getParamsUpdater();
150 paramUpdater
.update(time0
, time1
); // , timeSpaceWidth);
152 // send the initial request and obtained the adjusted time used
153 TmfTimeRange adjustedTimeRange
= initialExperimentDataRequest(this, experimentTRange
);
155 // initialize widget time boundaries and filtering parameters
156 ModelUpdateInit(experimentTRange
, adjustedTimeRange
, this);
159 TraceDebug
.debug("No selected experiment information available"); //$NON-NLS-1$
163 private void hookContextMenu() {
164 MenuManager menuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
165 menuMgr
.setRemoveAllWhenShown(true);
166 menuMgr
.addMenuListener(new IMenuListener() {
168 public void menuAboutToShow(IMenuManager manager
) {
169 ResourcesView
.this.fillContextMenu(manager
);
173 Menu menu
= menuMgr
.createContextMenu(tsfviewer
.getControl());
174 tsfviewer
.getControl().setMenu(menu
);
176 .registerContextMenu(menuMgr
, tsfviewer
.getSelectionProvider());
179 private void contributeToActionBars() {
180 IActionBars bars
= getViewSite().getActionBars();
181 fillLocalPullDown(bars
.getMenuManager());
182 fillLocalToolBar(bars
.getToolBarManager());
185 private void fillLocalPullDown(IMenuManager manager
) {
186 manager
.add(new Separator());
187 manager
.add(showLegend
);
188 manager
.add(new Separator());
189 manager
.add(resetScale
);
190 manager
.add(nextEvent
);
191 manager
.add(prevEvent
);
192 manager
.add(nextTrace
);
193 manager
.add(prevTrace
);
194 // manager.add(filterTraces);
196 manager
.add(zoomOut
);
197 manager
.add(zoomFilter
);
198 manager
.add(new Separator());
201 private void fillContextMenu(IMenuManager manager
) {
202 manager
.add(showLegend
);
203 manager
.add(new Separator());
204 manager
.add(resetScale
);
205 manager
.add(nextEvent
);
206 manager
.add(prevEvent
);
207 manager
.add(nextTrace
);
208 manager
.add(prevTrace
);
209 // manager.add(showLegend);
210 // manager.add(filterTraces);
212 manager
.add(zoomOut
);
213 manager
.add(zoomFilter
);
214 manager
.add(new Separator());
215 manager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
218 private void fillLocalToolBar(IToolBarManager manager
) {
219 manager
.add(showLegend
);
220 manager
.add(new Separator());
221 manager
.add(resetScale
);
222 manager
.add(nextEvent
);
223 manager
.add(prevEvent
);
224 manager
.add(nextTrace
);
225 manager
.add(prevTrace
);
226 // manager.add(filterTraces);
228 manager
.add(zoomOut
);
229 manager
.add(zoomFilter
);
230 manager
.add(new Separator());
233 private void makeActions() {
235 resetScale
= new Action() {
238 if (tsfviewer
!= null) {
239 tsfviewer
.resetStartFinishTime();
244 resetScale
.setText(Messages
.getString("ResourcesView.Action.Reset")); //$NON-NLS-1$
245 resetScale
.setToolTipText(Messages
.getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
246 resetScale
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
247 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/home_nav.gif")); //$NON-NLS-1$ //$NON-NLS-2$
250 nextEvent
= new Action() {
253 if (tsfviewer
!= null) {
254 tsfviewer
.selectNextEvent();
258 nextEvent
.setText(Messages
.getString("ResourcesView.Action.NextEvent")); //$NON-NLS-1$
259 nextEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
260 nextEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
261 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/next_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
264 prevEvent
= new Action() {
267 if (tsfviewer
!= null) {
268 tsfviewer
.selectPrevEvent();
272 prevEvent
.setText(Messages
.getString("ResourcesView.Action.PrevEvent")); //$NON-NLS-1$
273 prevEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
274 prevEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
275 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/prev_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
278 nextTrace
= new Action() {
281 if (tsfviewer
!= null) {
282 tsfviewer
.selectNextTrace();
286 nextTrace
.setText(Messages
.getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
287 nextTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
288 nextTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
289 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/next_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
292 prevTrace
= new Action() {
295 if (tsfviewer
!= null) {
296 tsfviewer
.selectPrevTrace();
300 prevTrace
.setText(Messages
.getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
301 prevTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
302 prevTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
303 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/prev_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
306 showLegend
= new Action() {
309 if (tsfviewer
!= null) {
310 tsfviewer
.showLegend();
314 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
315 showLegend
.setToolTipText(Messages
.getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
318 filterTraces
= new Action() {
321 if (tsfviewer
!= null) {
322 tsfviewer
.filterTraces();
326 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
327 filterTraces
.setToolTipText(Messages
.getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
328 filterTraces
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
329 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
332 zoomIn
= new Action() {
335 if (tsfviewer
!= null) {
340 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
341 zoomIn
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
342 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
343 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/zoomin_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
346 zoomOut
= new Action() {
349 if (tsfviewer
!= null) {
354 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
355 zoomOut
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
356 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
357 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/zoomout_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
360 zoomFilter
= new Action() {
363 // Nothing to do, however the selection status is needed by the
368 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
369 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
370 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
371 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
372 zoomFilter
.setChecked(false);
374 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
378 * Passing the focus request to the viewer's control.
381 public void setFocus() {
382 tsfviewer
.getControl().setFocus();
388 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
389 * tsfTmProcessSelEvent
390 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
394 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
395 // common implementation
396 super.tsfTmProcessSelEvent(event
);
402 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
403 * ITmfTimeScaleSelectionListener
404 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
405 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
408 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
409 super.tsfTmProcessTimeScaleEvent(event
);
416 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
417 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
418 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
422 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
423 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
424 final long endVisibleWindow
, final Object source
) {
426 // Return if disposed
427 if ((tsfviewer
== null) || (tsfviewer
.getControl().isDisposed())) return;
429 Display display
= tsfviewer
.getControl().getDisplay();
430 display
.asyncExec(new Runnable() {
433 if ((tsfviewer
!= null) && (!tsfviewer
.getControl().isDisposed())) {
434 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
435 // validate visible boundaries
436 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
437 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
439 tsfviewer
.resizeControls();
446 public void dispose() {
447 // dispose parent resources
450 tsfviewer
.removeWidgetSelectionListner(this);
451 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
456 * Registers as listener of time selection from other tmf views
462 public void synchToTime(TmfTimeSynchSignal signal
) {
463 super.synchToTime(signal
);
467 * Annotation Registers as listener of time range selection from other views
468 * The implementation handles the entry of the signal.
473 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
474 if (zoomFilter
!= null) {
475 synchToTimeRange(signal
, zoomFilter
.isChecked());
480 public void modelIncomplete(ILttngSyntEventRequest request
) {
482 // The data will be refreshed on the next request
488 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
489 * getEventProcessor()
492 public ITransEventProcessor
getEventProcessor() {
493 return ResourcesEventToHandlerFactory
.getInstance();
500 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
501 if (signal
!= null) {
502 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
504 initTimeRange
= TmfTimeRange
.Null
;
505 if (experimentTRange
!= TmfTimeRange
.Null
) {
506 // prepare time intervals in widget
507 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
509 // request initial data
510 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
516 public void experimentRangeUpdated(TmfExperimentRangeUpdatedSignal signal
) {
517 if (initTimeRange
== TmfTimeRange
.Null
&& signal
.getExperiment().equals(TmfExperiment
.getCurrentExperiment())) {
518 TmfTimeRange experimentTRange
= signal
.getRange();
520 if (experimentTRange
!= TmfTimeRange
.Null
) {
521 // prepare time intervals in widget
522 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
524 // request initial data
525 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
532 * @param experimentTRange
533 * @return Adjusted time window used for the request (smaller window to
536 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
537 // Adjust the initial time window to a shorter interval to allow
538 // user to select the interesting area based on the perspective
539 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
541 eventRequest(initTimeWindow
, experimentTRange
, true, ExecutionType
.FOREGROUND
);
542 if (TraceDebug
.isDEBUG()) {
543 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-" //$NON-NLS-1$ //$NON-NLS-2$
544 + initTimeWindow
.getEndTime().toString());
547 initTimeRange
= initTimeWindow
;
548 return initTimeWindow
;
554 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
558 protected ParamsUpdater
getParamsUpdater() {
559 return ResourceModelFactory
.getParamsUpdater();
565 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
569 protected ItemContainer
<?
> getItemContainer() {
570 return ResourceModelFactory
.getResourceContainer();
575 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#getProviderId()
578 protected int getProviderId() {
579 return LttngCoreProviderFactory
.RESOURCE_LTTNG_SYTH_EVENT_PROVIDER
;