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
9 * Contributors: Alvaro Sanchez-Leon - Initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
;
13 import org
.eclipse
.jface
.action
.Action
;
14 import org
.eclipse
.jface
.action
.IMenuListener
;
15 import org
.eclipse
.jface
.action
.IMenuManager
;
16 import org
.eclipse
.jface
.action
.IToolBarManager
;
17 import org
.eclipse
.jface
.action
.MenuManager
;
18 import org
.eclipse
.jface
.action
.Separator
;
19 import org
.eclipse
.linuxtools
.lttng
.control
.LttngCoreProviderFactory
;
20 import org
.eclipse
.linuxtools
.lttng
.request
.ILttngSyntEventRequest
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ITransEventProcessor
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.ItemContainer
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeViewerProvider
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.AbsTimeUpdateView
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.ParamsUpdater
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
.ResourcesEventToHandlerFactory
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.model
.ResourceModelFactory
;
29 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
31 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
32 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
.ExecutionType
;
33 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
34 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfRangeSynchSignal
;
35 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
36 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTimeSynchSignal
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.TmfViewerFactory
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeScaleSelectionListener
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeSelectionListener
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeSelectionEvent
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
43 import org
.eclipse
.swt
.SWT
;
44 import org
.eclipse
.swt
.layout
.FillLayout
;
45 import org
.eclipse
.swt
.widgets
.Composite
;
46 import org
.eclipse
.swt
.widgets
.Display
;
47 import org
.eclipse
.swt
.widgets
.Menu
;
48 import org
.eclipse
.ui
.IActionBars
;
49 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
50 import org
.eclipse
.ui
.PlatformUI
;
51 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
57 public class ResourcesView
extends AbsTimeUpdateView
implements
58 ITmfTimeSelectionListener
, ITmfTimeScaleSelectionListener
{
60 // ========================================================================
62 // ========================================================================
63 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.resources"; //$NON-NLS-1$
65 // private int totalNumItems = 0;
67 private Action resetScale
;
68 private Action nextEvent
;
69 private Action prevEvent
;
70 private Action nextTrace
;
71 private Action prevTrace
;
72 private Action showLegend
;
73 private Action filterTraces
;
74 private Action zoomIn
;
75 private Action zoomOut
;
76 private Action zoomFilter
;
77 private Composite top
;
79 // private static SimpleDateFormat stimeformat = new SimpleDateFormat(
80 // "yy/MM/dd HH:mm:ss");
82 // private TraceModelImplFactory fact;
84 // ========================================================================
86 // ========================================================================
91 public ResourcesView() {
95 // ========================================================================
97 // ========================================================================
100 * This is a callback that will allow us to create the viewer and initialize
104 public void createPartControl(Composite parent
) {
105 top
= new Composite(parent
, SWT
.BORDER
);
107 top
.setLayout(new FillLayout());
108 tsfviewer
= TmfViewerFactory
.createViewer(top
, new TimeRangeViewerProvider(getParamsUpdater()));
110 tsfviewer
.addWidgetSelectionListner(this);
111 tsfviewer
.addWidgetTimeScaleSelectionListner(this);
113 // Traces shall not be grouped to allow synchronisation
114 tsfviewer
.groupTraces(true);
115 tsfviewer
.setAcceptSelectionAPIcalls(true);
117 // Viewer to notify selection to this class
118 // This class will synchronise selections with table.
119 // tsfviewer.addWidgetSelectionListner(this);
120 // tsfviewer.addWidgetTimeScaleSelectionListner(this);
122 // Create the help context id for the viewer's control
123 // TODO: Associate with help system
124 PlatformUI
.getWorkbench().getHelpSystem().setHelp(
125 tsfviewer
.getControl(),
126 "org.eclipse.linuxtools.lttng.ui.views.resource.view"); //$NON-NLS-1$
130 contributeToActionBars();
132 // // Read relevant values
133 // int timeSpaceWidth = tsfviewer.getTimeSpace();
134 // if (timeSpaceWidth < 0) {
135 // timeSpaceWidth = -timeSpaceWidth;
138 TmfExperiment
<?
> experiment
= TmfExperiment
.getCurrentExperiment();
139 if (experiment
!= null) {
140 TmfTimeRange experimentTRange
= experiment
.getTimeRange();
141 if (experimentTRange
!= null) {
142 long time0
= experimentTRange
.getStartTime().getValue();
143 long time1
= experimentTRange
.getEndTime().getValue();
144 ParamsUpdater paramUpdater
= getParamsUpdater();
145 paramUpdater
.update(time0
, time1
); // , timeSpaceWidth);
147 // send the initial request and obtained the adjusted time used
148 TmfTimeRange adjustedTimeRange
= initialExperimentDataRequest(this, experimentTRange
);
150 // initialize widget time boundaries and filtering parameters
151 ModelUpdateInit(experimentTRange
, adjustedTimeRange
, this);
153 TraceDebug
.debug("No selected experiment information available");
157 private void hookContextMenu() {
158 MenuManager menuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
159 menuMgr
.setRemoveAllWhenShown(true);
160 menuMgr
.addMenuListener(new IMenuListener() {
162 public void menuAboutToShow(IMenuManager manager
) {
163 ResourcesView
.this.fillContextMenu(manager
);
167 Menu menu
= menuMgr
.createContextMenu(tsfviewer
.getControl());
168 tsfviewer
.getControl().setMenu(menu
);
170 .registerContextMenu(menuMgr
, tsfviewer
.getSelectionProvider());
173 private void contributeToActionBars() {
174 IActionBars bars
= getViewSite().getActionBars();
175 fillLocalPullDown(bars
.getMenuManager());
176 fillLocalToolBar(bars
.getToolBarManager());
179 private void fillLocalPullDown(IMenuManager manager
) {
180 manager
.add(new Separator());
181 // manager.add(showLegend);
182 manager
.add(new Separator());
183 manager
.add(resetScale
);
184 manager
.add(nextEvent
);
185 manager
.add(prevEvent
);
186 manager
.add(nextTrace
);
187 manager
.add(prevTrace
);
188 // manager.add(filterTraces);
190 manager
.add(zoomOut
);
191 manager
.add(zoomFilter
);
192 manager
.add(new Separator());
195 private void fillContextMenu(IMenuManager manager
) {
196 // manager.add(showLegend);
197 manager
.add(new Separator());
198 manager
.add(resetScale
);
199 manager
.add(nextEvent
);
200 manager
.add(prevEvent
);
201 manager
.add(nextTrace
);
202 manager
.add(prevTrace
);
203 // manager.add(showLegend);
204 // manager.add(filterTraces);
206 manager
.add(zoomOut
);
207 manager
.add(zoomFilter
);
208 manager
.add(new Separator());
209 manager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
212 private void fillLocalToolBar(IToolBarManager manager
) {
213 // manager.add(showLegend);
214 manager
.add(new Separator());
215 manager
.add(resetScale
);
216 manager
.add(nextEvent
);
217 manager
.add(prevEvent
);
218 manager
.add(nextTrace
);
219 manager
.add(prevTrace
);
220 // manager.add(filterTraces);
222 manager
.add(zoomOut
);
223 manager
.add(zoomFilter
);
224 manager
.add(new Separator());
227 private void makeActions() {
229 resetScale
= new Action() {
232 if (tsfviewer
!= null) {
233 tsfviewer
.resetStartFinishTime();
238 resetScale
.setText(Messages
.getString("ResourcesView.Action.Reset")); //$NON-NLS-1$
239 resetScale
.setToolTipText(Messages
.getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
240 resetScale
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
241 Messages
.getString("ResourcesView.tmf.UI"), "icons/home_nav.gif")); //$NON-NLS-1$ //$NON-NLS-2$
244 nextEvent
= new Action() {
247 if (tsfviewer
!= null) {
248 tsfviewer
.selectNextEvent();
252 nextEvent
.setText(Messages
.getString("ResourcesView.Action.NextEvent")); //$NON-NLS-1$
253 nextEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
254 nextEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
255 Messages
.getString("ResourcesView.tmf.UI"), "icons/next_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
258 prevEvent
= new Action() {
261 if (tsfviewer
!= null) {
262 tsfviewer
.selectPrevEvent();
266 prevEvent
.setText(Messages
.getString("ResourcesView.Action.PrevEvent")); //$NON-NLS-1$
267 prevEvent
.setToolTipText(Messages
.getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
268 prevEvent
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
269 Messages
.getString("ResourcesView.tmf.UI"), "icons/prev_event.gif")); //$NON-NLS-1$//$NON-NLS-2$
272 nextTrace
= new Action() {
275 if (tsfviewer
!= null) {
276 tsfviewer
.selectNextTrace();
280 nextTrace
.setText(Messages
.getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
281 nextTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
282 nextTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
283 Messages
.getString("ResourcesView.tmf.UI"), "icons/next_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
286 prevTrace
= new Action() {
289 if (tsfviewer
!= null) {
290 tsfviewer
.selectPrevTrace();
294 prevTrace
.setText(Messages
.getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
295 prevTrace
.setToolTipText(Messages
.getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
296 prevTrace
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
297 Messages
.getString("ResourcesView.tmf.UI"), "icons/prev_item.gif")); //$NON-NLS-1$//$NON-NLS-2$
300 showLegend
= new Action() {
303 if (tsfviewer
!= null) {
304 tsfviewer
.showLegend();
308 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
309 showLegend
.setToolTipText(Messages
.getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
312 filterTraces
= new Action() {
315 if (tsfviewer
!= null) {
316 tsfviewer
.filterTraces();
320 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
321 filterTraces
.setToolTipText(Messages
.getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
322 filterTraces
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
323 Messages
.getString("ResourcesView.tmf.UI"), "icons/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
326 zoomIn
= new Action() {
329 if (tsfviewer
!= null) {
334 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
335 zoomIn
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
336 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
337 Messages
.getString("ResourcesView.tmf.UI"), "icons/zoomin_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
340 zoomOut
= new Action() {
343 if (tsfviewer
!= null) {
348 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
349 zoomOut
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
350 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
351 Messages
.getString("ResourcesView.tmf.UI"), "icons/zoomout_nav.gif")); //$NON-NLS-1$//$NON-NLS-2$
354 zoomFilter
= new Action() {
357 // Nothing to do, however the selection status is needed by the
362 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
363 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
364 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
365 Messages
.getString("ResourcesView.tmf.UI"), "icons/filter_items.gif")); //$NON-NLS-1$//$NON-NLS-2$
366 zoomFilter
.setChecked(false);
368 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
372 * Passing the focus request to the viewer's control.
375 public void setFocus() {
376 tsfviewer
.getControl().setFocus();
382 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
383 * tsfTmProcessSelEvent
384 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
388 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
389 // common implementation
390 super.tsfTmProcessSelEvent(event
);
396 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
397 * ITmfTimeScaleSelectionListener
398 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
399 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
402 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
403 super.tsfTmProcessTimeScaleEvent(event
);
410 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
411 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
412 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
416 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
417 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
418 final long endVisibleWindow
, final Object source
) {
420 // Return if disposed
421 if ((tsfviewer
== null) || (tsfviewer
.getControl().isDisposed())) return;
423 Display display
= tsfviewer
.getControl().getDisplay();
424 display
.asyncExec(new Runnable() {
427 if ((tsfviewer
!= null) && (!tsfviewer
.getControl().isDisposed())) {
428 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
429 // validate visible boundaries
430 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
431 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
433 tsfviewer
.resizeControls();
440 public void dispose() {
441 // dispose parent resources
444 tsfviewer
.removeWidgetSelectionListner(this);
445 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
450 * Registers as listener of time selection from other tmf views
456 public void synchToTime(TmfTimeSynchSignal signal
) {
457 super.synchToTime(signal
);
461 * Annotation Registers as listener of time range selection from other views
462 * The implementation handles the entry of the signal.
467 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
468 if (zoomFilter
!= null) {
469 synchToTimeRange(signal
, zoomFilter
.isChecked());
474 public void modelIncomplete(ILttngSyntEventRequest request
) {
476 // The data will be refreshed on the next request
482 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
483 * getEventProcessor()
486 public ITransEventProcessor
getEventProcessor() {
487 return ResourcesEventToHandlerFactory
.getInstance();
494 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
495 if (signal
!= null) {
496 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
498 // prepare time intervals in widget
499 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
501 // request initial data
502 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
508 * @param experimentTRange
509 * @return Adjusted time window used for the request (smaller window to
512 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
513 // Adjust the initial time window to a shorter interval to allow
514 // user to select the interesting area based on the perspective
515 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
517 dataRequest(initTimeWindow
, experimentTRange
, true, ExecutionType
.FOREGROUND
);
518 if (TraceDebug
.isDEBUG()) {
519 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-" //$NON-NLS-1$ //$NON-NLS-2$
520 + initTimeWindow
.getEndTime().toString());
523 return initTimeWindow
;
529 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
533 protected ParamsUpdater
getParamsUpdater() {
534 return ResourceModelFactory
.getParamsUpdater();
540 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
544 protected ItemContainer
<?
> getItemContainer() {
545 return ResourceModelFactory
.getResourceContainer();
550 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#getProviderId()
553 protected int getProviderId() {
554 return LttngCoreProviderFactory
.RESOURCE_LTTNG_SYTH_EVENT_PROVIDER
;