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
.TmfExperimentSelectedSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfRangeSynchSignal
;
37 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
38 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTimeSynchSignal
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.TmfViewerFactory
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeScaleSelectionListener
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeSelectionListener
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeSelectionEvent
;
44 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
45 import org
.eclipse
.swt
.SWT
;
46 import org
.eclipse
.swt
.layout
.FillLayout
;
47 import org
.eclipse
.swt
.widgets
.Composite
;
48 import org
.eclipse
.swt
.widgets
.Display
;
49 import org
.eclipse
.swt
.widgets
.Menu
;
50 import org
.eclipse
.ui
.IActionBars
;
51 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
52 import org
.eclipse
.ui
.PlatformUI
;
53 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
59 public class ResourcesView
extends AbsTimeUpdateView
implements
60 ITmfTimeSelectionListener
, ITmfTimeScaleSelectionListener
{
62 // ========================================================================
64 // ========================================================================
65 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.resources"; //$NON-NLS-1$
67 // private int totalNumItems = 0;
69 private Action resetScale
;
70 private Action nextEvent
;
71 private Action prevEvent
;
72 private Action nextTrace
;
73 private Action prevTrace
;
74 private Action showLegend
;
75 private Action filterTraces
;
76 private Action zoomIn
;
77 private Action zoomOut
;
78 private Action zoomFilter
;
79 private Composite top
;
81 // private static SimpleDateFormat stimeformat = new SimpleDateFormat(
82 // "yy/MM/dd HH:mm:ss");
84 // private TraceModelImplFactory fact;
86 // ========================================================================
88 // ========================================================================
93 public ResourcesView() {
97 // ========================================================================
99 // ========================================================================
102 * This is a callback that will allow us to create the viewer and initialize
106 public void createPartControl(Composite parent
) {
107 top
= new Composite(parent
, SWT
.BORDER
);
109 top
.setLayout(new FillLayout());
110 tsfviewer
= TmfViewerFactory
.createViewer(top
, new ResourcesTimeRangeViewerProvider(getParamsUpdater()));
112 tsfviewer
.addWidgetSelectionListner(this);
113 tsfviewer
.addWidgetTimeScaleSelectionListner(this);
115 // Traces shall not be grouped to allow synchronisation
116 tsfviewer
.groupTraces(true);
117 tsfviewer
.setAcceptSelectionAPIcalls(true);
119 // Viewer to notify selection to this class
120 // This class will synchronise selections with table.
121 // tsfviewer.addWidgetSelectionListner(this);
122 // tsfviewer.addWidgetTimeScaleSelectionListner(this);
124 // Create the help context id for the viewer's control
125 // TODO: Associate with help system
126 PlatformUI
.getWorkbench().getHelpSystem().setHelp(
127 tsfviewer
.getControl(),
128 "org.eclipse.linuxtools.lttng.ui.views.resource.view"); //$NON-NLS-1$
132 contributeToActionBars();
134 // // Read relevant values
135 // int timeSpaceWidth = tsfviewer.getTimeSpace();
136 // if (timeSpaceWidth < 0) {
137 // timeSpaceWidth = -timeSpaceWidth;
140 TmfExperiment
<?
> experiment
= TmfExperiment
.getCurrentExperiment();
141 if (experiment
!= null) {
142 TmfTimeRange experimentTRange
= experiment
.getTimeRange();
143 if (experimentTRange
!= null) {
144 long time0
= experimentTRange
.getStartTime().getValue();
145 long time1
= experimentTRange
.getEndTime().getValue();
146 ParamsUpdater paramUpdater
= getParamsUpdater();
147 paramUpdater
.update(time0
, time1
); // , timeSpaceWidth);
149 // send the initial request and obtained the adjusted time used
150 TmfTimeRange adjustedTimeRange
= initialExperimentDataRequest(this, experimentTRange
);
152 // initialize widget time boundaries and filtering parameters
153 ModelUpdateInit(experimentTRange
, adjustedTimeRange
, this);
155 TraceDebug
.debug("No selected experiment information available"); //$NON-NLS-1$
159 private void hookContextMenu() {
160 MenuManager menuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
161 menuMgr
.setRemoveAllWhenShown(true);
162 menuMgr
.addMenuListener(new IMenuListener() {
164 public void menuAboutToShow(IMenuManager manager
) {
165 ResourcesView
.this.fillContextMenu(manager
);
169 Menu menu
= menuMgr
.createContextMenu(tsfviewer
.getControl());
170 tsfviewer
.getControl().setMenu(menu
);
172 .registerContextMenu(menuMgr
, tsfviewer
.getSelectionProvider());
175 private void contributeToActionBars() {
176 IActionBars bars
= getViewSite().getActionBars();
177 fillLocalPullDown(bars
.getMenuManager());
178 fillLocalToolBar(bars
.getToolBarManager());
181 private void fillLocalPullDown(IMenuManager manager
) {
182 manager
.add(new Separator());
183 manager
.add(showLegend
);
184 manager
.add(new Separator());
185 manager
.add(resetScale
);
186 manager
.add(nextEvent
);
187 manager
.add(prevEvent
);
188 manager
.add(nextTrace
);
189 manager
.add(prevTrace
);
190 // manager.add(filterTraces);
192 manager
.add(zoomOut
);
193 manager
.add(zoomFilter
);
194 manager
.add(new Separator());
197 private void fillContextMenu(IMenuManager manager
) {
198 manager
.add(showLegend
);
199 manager
.add(new Separator());
200 manager
.add(resetScale
);
201 manager
.add(nextEvent
);
202 manager
.add(prevEvent
);
203 manager
.add(nextTrace
);
204 manager
.add(prevTrace
);
205 // manager.add(showLegend);
206 // manager.add(filterTraces);
208 manager
.add(zoomOut
);
209 manager
.add(zoomFilter
);
210 manager
.add(new Separator());
211 manager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
214 private void fillLocalToolBar(IToolBarManager manager
) {
215 manager
.add(showLegend
);
216 manager
.add(new Separator());
217 manager
.add(resetScale
);
218 manager
.add(nextEvent
);
219 manager
.add(prevEvent
);
220 manager
.add(nextTrace
);
221 manager
.add(prevTrace
);
222 // manager.add(filterTraces);
224 manager
.add(zoomOut
);
225 manager
.add(zoomFilter
);
226 manager
.add(new Separator());
229 private void makeActions() {
231 resetScale
= new Action() {
234 if (tsfviewer
!= null) {
235 tsfviewer
.resetStartFinishTime();
240 resetScale
.setText(Messages
.getString("ResourcesView.Action.Reset")); //$NON-NLS-1$
241 resetScale
.setToolTipText(Messages
.getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
242 resetScale
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
243 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/home_nav.gif")); //$NON-NLS-1$ //$NON-NLS-2$
246 nextEvent
= new Action() {
249 if (tsfviewer
!= null) {
250 tsfviewer
.selectNextEvent();
254 nextEvent
.setText(Messages
.getString("ResourcesView.Action.NextEvent")); //$NON-NLS-1$
255 nextEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
256 nextEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
257 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/next_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
260 prevEvent
= new Action() {
263 if (tsfviewer
!= null) {
264 tsfviewer
.selectPrevEvent();
268 prevEvent
.setText(Messages
.getString("ResourcesView.Action.PrevEvent")); //$NON-NLS-1$
269 prevEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
270 prevEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
271 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/prev_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
274 nextTrace
= new Action() {
277 if (tsfviewer
!= null) {
278 tsfviewer
.selectNextTrace();
282 nextTrace
.setText(Messages
.getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
283 nextTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
284 nextTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
285 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/next_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
288 prevTrace
= new Action() {
291 if (tsfviewer
!= null) {
292 tsfviewer
.selectPrevTrace();
296 prevTrace
.setText(Messages
.getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
297 prevTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
298 prevTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
299 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/prev_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
302 showLegend
= new Action() {
305 if (tsfviewer
!= null) {
306 tsfviewer
.showLegend();
310 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
311 showLegend
.setToolTipText(Messages
.getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
314 filterTraces
= new Action() {
317 if (tsfviewer
!= null) {
318 tsfviewer
.filterTraces();
322 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
323 filterTraces
.setToolTipText(Messages
.getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
324 filterTraces
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
325 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
328 zoomIn
= new Action() {
331 if (tsfviewer
!= null) {
336 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
337 zoomIn
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
338 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
339 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/zoomin_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
342 zoomOut
= new Action() {
345 if (tsfviewer
!= null) {
350 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
351 zoomOut
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
352 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
353 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/zoomout_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
356 zoomFilter
= new Action() {
359 // Nothing to do, however the selection status is needed by the
364 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
365 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
366 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
367 Messages
.getString("ResourcesView.tmf.UI"), "icons/elcl16/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
368 zoomFilter
.setChecked(false);
370 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
374 * Passing the focus request to the viewer's control.
377 public void setFocus() {
378 tsfviewer
.getControl().setFocus();
384 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
385 * tsfTmProcessSelEvent
386 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
390 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
391 // common implementation
392 super.tsfTmProcessSelEvent(event
);
398 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
399 * ITmfTimeScaleSelectionListener
400 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
401 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
404 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
405 super.tsfTmProcessTimeScaleEvent(event
);
412 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
413 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
414 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
418 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
419 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
420 final long endVisibleWindow
, final Object source
) {
422 // Return if disposed
423 if ((tsfviewer
== null) || (tsfviewer
.getControl().isDisposed())) return;
425 Display display
= tsfviewer
.getControl().getDisplay();
426 display
.asyncExec(new Runnable() {
429 if ((tsfviewer
!= null) && (!tsfviewer
.getControl().isDisposed())) {
430 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
431 // validate visible boundaries
432 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
433 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
435 tsfviewer
.resizeControls();
442 public void dispose() {
443 // dispose parent resources
446 tsfviewer
.removeWidgetSelectionListner(this);
447 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
452 * Registers as listener of time selection from other tmf views
458 public void synchToTime(TmfTimeSynchSignal signal
) {
459 super.synchToTime(signal
);
463 * Annotation Registers as listener of time range selection from other views
464 * The implementation handles the entry of the signal.
469 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
470 if (zoomFilter
!= null) {
471 synchToTimeRange(signal
, zoomFilter
.isChecked());
476 public void modelIncomplete(ILttngSyntEventRequest request
) {
478 // The data will be refreshed on the next request
484 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
485 * getEventProcessor()
488 public ITransEventProcessor
getEventProcessor() {
489 return ResourcesEventToHandlerFactory
.getInstance();
496 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
497 if (signal
!= null) {
498 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
500 // prepare time intervals in widget
501 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
503 // request initial data
504 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
510 * @param experimentTRange
511 * @return Adjusted time window used for the request (smaller window to
514 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
515 // Adjust the initial time window to a shorter interval to allow
516 // user to select the interesting area based on the perspective
517 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
519 dataRequest(initTimeWindow
, experimentTRange
, true, ExecutionType
.FOREGROUND
);
520 if (TraceDebug
.isDEBUG()) {
521 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-" //$NON-NLS-1$ //$NON-NLS-2$
522 + initTimeWindow
.getEndTime().toString());
525 return initTimeWindow
;
531 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
535 protected ParamsUpdater
getParamsUpdater() {
536 return ResourceModelFactory
.getParamsUpdater();
542 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
546 protected ItemContainer
<?
> getItemContainer() {
547 return ResourceModelFactory
.getResourceContainer();
552 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#getProviderId()
555 protected int getProviderId() {
556 return LttngCoreProviderFactory
.RESOURCE_LTTNG_SYTH_EVENT_PROVIDER
;