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";
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
240 .getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
241 resetScale
.setImageDescriptor(AbstractUIPlugin
242 .imageDescriptorFromPlugin(Messages
243 .getString("ResourcesView.tmf.UI"),
244 "icons/home_nav.gif"));
247 nextEvent
= new Action() {
250 if (tsfviewer
!= null) {
251 tsfviewer
.selectNextEvent();
255 nextEvent
.setText(Messages
.getString("ResourcesView.Action.NextEvent")); //$NON-NLS-1$
256 nextEvent
.setToolTipText(Messages
257 .getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
258 nextEvent
.setImageDescriptor(AbstractUIPlugin
259 .imageDescriptorFromPlugin(Messages
260 .getString("ResourcesView.tmf.UI"),
261 "icons/next_event.gif"));
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
274 .getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
275 prevEvent
.setImageDescriptor(AbstractUIPlugin
276 .imageDescriptorFromPlugin(Messages
277 .getString("ResourcesView.tmf.UI"),
278 "icons/prev_event.gif"));
281 nextTrace
= new Action() {
284 if (tsfviewer
!= null) {
285 tsfviewer
.selectNextTrace();
289 nextTrace
.setText(Messages
290 .getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
291 nextTrace
.setToolTipText(Messages
292 .getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
293 nextTrace
.setImageDescriptor(AbstractUIPlugin
294 .imageDescriptorFromPlugin(Messages
295 .getString("ResourcesView.tmf.UI"),
296 "icons/next_item.gif"));
299 prevTrace
= new Action() {
302 if (tsfviewer
!= null) {
303 tsfviewer
.selectPrevTrace();
307 prevTrace
.setText(Messages
308 .getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
309 prevTrace
.setToolTipText(Messages
310 .getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
311 prevTrace
.setImageDescriptor(AbstractUIPlugin
312 .imageDescriptorFromPlugin(Messages
313 .getString("ResourcesView.tmf.UI"),
314 "icons/prev_item.gif"));
317 showLegend
= new Action() {
320 if (tsfviewer
!= null) {
321 tsfviewer
.showLegend();
325 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
326 showLegend
.setToolTipText(Messages
327 .getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
330 filterTraces
= new Action() {
333 if (tsfviewer
!= null) {
334 tsfviewer
.filterTraces();
338 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
339 filterTraces
.setToolTipText(Messages
340 .getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
341 filterTraces
.setImageDescriptor(AbstractUIPlugin
342 .imageDescriptorFromPlugin(Messages
343 .getString("ResourcesView.tmf.UI"),
344 "icons/filter_items.gif"));
347 zoomIn
= new Action() {
350 if (tsfviewer
!= null) {
355 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
356 zoomIn
.setToolTipText(Messages
357 .getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
358 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
359 Messages
.getString("ResourcesView.tmf.UI"),
360 "icons/zoomin_nav.gif"));
363 zoomOut
= new Action() {
366 if (tsfviewer
!= null) {
371 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
372 zoomOut
.setToolTipText(Messages
373 .getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
374 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
375 Messages
.getString("ResourcesView.tmf.UI"),
376 "icons/zoomout_nav.gif"));
379 zoomFilter
= new Action() {
382 // Nothing to do, however the selection status is needed by the
387 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
388 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
389 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(Messages
390 .getString("ResourcesView.tmf.UI"), "icons/filter_items.gif"));
391 zoomFilter
.setChecked(false);
393 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
397 * Passing the focus request to the viewer's control.
400 public void setFocus() {
401 tsfviewer
.getControl().setFocus();
407 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
408 * tsfTmProcessSelEvent
409 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
413 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
414 // common implementation
415 super.tsfTmProcessSelEvent(event
);
421 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
422 * ITmfTimeScaleSelectionListener
423 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
424 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
427 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
428 super.tsfTmProcessTimeScaleEvent(event
);
435 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
436 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
437 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
441 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
442 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
443 final long endVisibleWindow
, final Object source
) {
445 // Return if disposed
446 if ((tsfviewer
== null) || (tsfviewer
.getControl().isDisposed())) return;
448 Display display
= tsfviewer
.getControl().getDisplay();
449 display
.asyncExec(new Runnable() {
452 if ((tsfviewer
!= null) && (!tsfviewer
.getControl().isDisposed())) {
453 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
454 // validate visible boundaries
455 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
456 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
458 tsfviewer
.resizeControls();
465 public void dispose() {
466 // dispose parent resources
469 tsfviewer
.removeWidgetSelectionListner(this);
470 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
475 * Registers as listener of time selection from other tmf views
481 public void synchToTime(TmfTimeSynchSignal signal
) {
482 super.synchToTime(signal
);
486 * Annotation Registers as listener of time range selection from other views
487 * The implementation handles the entry of the signal.
492 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
493 if (zoomFilter
!= null) {
494 synchToTimeRange(signal
, zoomFilter
.isChecked());
499 public void modelIncomplete(ILttngSyntEventRequest request
) {
501 // The data will be refreshed on the next request
507 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
508 * getEventProcessor()
511 public ITransEventProcessor
getEventProcessor() {
512 return ResourcesEventToHandlerFactory
.getInstance();
519 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
520 if (signal
!= null) {
521 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
523 // prepare time intervals in widget
524 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
526 // request initial data
527 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
533 * @param experimentTRange
534 * @return Adjusted time window used for the request (smaller window to
537 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
538 // Adjust the initial time window to a shorter interval to allow
539 // user to select the interesting area based on the perspective
540 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
542 dataRequest(initTimeWindow
, experimentTRange
, true, ExecutionType
.FOREGROUND
);
543 if (TraceDebug
.isDEBUG()) {
544 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-"
545 + initTimeWindow
.getEndTime().toString());
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
;