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
.request
.ILttngSyntEventRequest
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ITransEventProcessor
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.ItemContainer
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeViewerProvider
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.AbsTimeUpdateView
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.ParamsUpdater
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
.ResourcesEventToHandlerFactory
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.model
.ResourceModelFactory
;
28 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
30 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
31 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
.ExecutionType
;
32 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
33 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfRangeSynchSignal
;
34 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
35 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTimeSynchSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.TmfViewerFactory
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeScaleSelectionListener
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeSelectionListener
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeSelectionEvent
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
42 import org
.eclipse
.swt
.SWT
;
43 import org
.eclipse
.swt
.layout
.FillLayout
;
44 import org
.eclipse
.swt
.widgets
.Composite
;
45 import org
.eclipse
.swt
.widgets
.Display
;
46 import org
.eclipse
.swt
.widgets
.Menu
;
47 import org
.eclipse
.ui
.IActionBars
;
48 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
49 import org
.eclipse
.ui
.PlatformUI
;
50 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
56 public class ResourcesView
extends AbsTimeUpdateView
implements
57 ITmfTimeSelectionListener
, ITmfTimeScaleSelectionListener
{
59 // ========================================================================
61 // ========================================================================
62 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.resources";
64 // private int totalNumItems = 0;
66 private Action resetScale
;
67 private Action nextEvent
;
68 private Action prevEvent
;
69 private Action nextTrace
;
70 private Action prevTrace
;
71 private Action showLegend
;
72 private Action filterTraces
;
73 private Action zoomIn
;
74 private Action zoomOut
;
75 private Action zoomFilter
;
76 private Composite top
;
78 // private static SimpleDateFormat stimeformat = new SimpleDateFormat(
79 // "yy/MM/dd HH:mm:ss");
81 // private TraceModelImplFactory fact;
83 // ========================================================================
85 // ========================================================================
90 public ResourcesView() {
94 // ========================================================================
96 // ========================================================================
99 * This is a callback that will allow us to create the viewer and initialize
103 public void createPartControl(Composite parent
) {
104 top
= new Composite(parent
, SWT
.BORDER
);
106 top
.setLayout(new FillLayout());
107 tsfviewer
= TmfViewerFactory
.createViewer(top
,
108 new TimeRangeViewerProvider());
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() {
161 public void menuAboutToShow(IMenuManager manager
) {
162 ResourcesView
.this.fillContextMenu(manager
);
166 Menu menu
= menuMgr
.createContextMenu(tsfviewer
.getControl());
167 tsfviewer
.getControl().setMenu(menu
);
169 .registerContextMenu(menuMgr
, tsfviewer
.getSelectionProvider());
172 private void contributeToActionBars() {
173 IActionBars bars
= getViewSite().getActionBars();
174 fillLocalPullDown(bars
.getMenuManager());
175 fillLocalToolBar(bars
.getToolBarManager());
178 private void fillLocalPullDown(IMenuManager manager
) {
179 manager
.add(new Separator());
180 // manager.add(showLegend);
181 manager
.add(new Separator());
182 manager
.add(resetScale
);
183 manager
.add(nextEvent
);
184 manager
.add(prevEvent
);
185 manager
.add(nextTrace
);
186 manager
.add(prevTrace
);
187 // manager.add(filterTraces);
189 manager
.add(zoomOut
);
190 manager
.add(zoomFilter
);
191 manager
.add(new Separator());
194 private void fillContextMenu(IMenuManager manager
) {
195 // manager.add(showLegend);
196 manager
.add(new Separator());
197 manager
.add(resetScale
);
198 manager
.add(nextEvent
);
199 manager
.add(prevEvent
);
200 manager
.add(nextTrace
);
201 manager
.add(prevTrace
);
202 // manager.add(showLegend);
203 // manager.add(filterTraces);
205 manager
.add(zoomOut
);
206 manager
.add(zoomFilter
);
207 manager
.add(new Separator());
208 manager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
211 private void fillLocalToolBar(IToolBarManager manager
) {
212 // manager.add(showLegend);
213 manager
.add(new Separator());
214 manager
.add(resetScale
);
215 manager
.add(nextEvent
);
216 manager
.add(prevEvent
);
217 manager
.add(nextTrace
);
218 manager
.add(prevTrace
);
219 // manager.add(filterTraces);
221 manager
.add(zoomOut
);
222 manager
.add(zoomFilter
);
223 manager
.add(new Separator());
226 private void makeActions() {
228 resetScale
= new Action() {
231 if (tsfviewer
!= null) {
232 tsfviewer
.resetStartFinishTime();
237 resetScale
.setText(Messages
.getString("ResourcesView.Action.Reset")); //$NON-NLS-1$
238 resetScale
.setToolTipText(Messages
239 .getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
240 resetScale
.setImageDescriptor(AbstractUIPlugin
241 .imageDescriptorFromPlugin(Messages
242 .getString("ResourcesView.tmf.UI"),
243 "icons/home_nav.gif"));
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
256 .getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
257 nextEvent
.setImageDescriptor(AbstractUIPlugin
258 .imageDescriptorFromPlugin(Messages
259 .getString("ResourcesView.tmf.UI"),
260 "icons/next_event.gif"));
263 prevEvent
= new Action() {
266 if (tsfviewer
!= null) {
267 tsfviewer
.selectPrevEvent();
271 prevEvent
.setText(Messages
.getString("ResourcesView.Action.PrevEvent")); //$NON-NLS-1$
272 prevEvent
.setToolTipText(Messages
273 .getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
274 prevEvent
.setImageDescriptor(AbstractUIPlugin
275 .imageDescriptorFromPlugin(Messages
276 .getString("ResourcesView.tmf.UI"),
277 "icons/prev_event.gif"));
280 nextTrace
= new Action() {
283 if (tsfviewer
!= null) {
284 tsfviewer
.selectNextTrace();
288 nextTrace
.setText(Messages
289 .getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
290 nextTrace
.setToolTipText(Messages
291 .getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
292 nextTrace
.setImageDescriptor(AbstractUIPlugin
293 .imageDescriptorFromPlugin(Messages
294 .getString("ResourcesView.tmf.UI"),
295 "icons/next_item.gif"));
298 prevTrace
= new Action() {
301 if (tsfviewer
!= null) {
302 tsfviewer
.selectPrevTrace();
306 prevTrace
.setText(Messages
307 .getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
308 prevTrace
.setToolTipText(Messages
309 .getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
310 prevTrace
.setImageDescriptor(AbstractUIPlugin
311 .imageDescriptorFromPlugin(Messages
312 .getString("ResourcesView.tmf.UI"),
313 "icons/prev_item.gif"));
316 showLegend
= new Action() {
319 if (tsfviewer
!= null) {
320 tsfviewer
.showLegend();
324 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
325 showLegend
.setToolTipText(Messages
326 .getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
329 filterTraces
= new Action() {
332 if (tsfviewer
!= null) {
333 tsfviewer
.filterTraces();
337 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
338 filterTraces
.setToolTipText(Messages
339 .getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
340 filterTraces
.setImageDescriptor(AbstractUIPlugin
341 .imageDescriptorFromPlugin(Messages
342 .getString("ResourcesView.tmf.UI"),
343 "icons/filter_items.gif"));
346 zoomIn
= new Action() {
349 if (tsfviewer
!= null) {
354 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
355 zoomIn
.setToolTipText(Messages
356 .getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
357 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
358 Messages
.getString("ResourcesView.tmf.UI"),
359 "icons/zoomin_nav.gif"));
362 zoomOut
= new Action() {
365 if (tsfviewer
!= null) {
370 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
371 zoomOut
.setToolTipText(Messages
372 .getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
373 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
374 Messages
.getString("ResourcesView.tmf.UI"),
375 "icons/zoomout_nav.gif"));
378 zoomFilter
= new Action() {
381 // Nothing to do, however the selection status is needed by the
386 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
387 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
388 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(Messages
389 .getString("ResourcesView.tmf.UI"), "icons/filter_items.gif"));
390 zoomFilter
.setChecked(false);
392 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
396 * Passing the focus request to the viewer's control.
399 public void setFocus() {
400 tsfviewer
.getControl().setFocus();
406 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
407 * tsfTmProcessSelEvent
408 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
412 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
413 // common implementation
414 super.tsfTmProcessSelEvent(event
);
420 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
421 * ITmfTimeScaleSelectionListener
422 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
423 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
426 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
427 super.tsfTmProcessTimeScaleEvent(event
);
434 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
435 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
436 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
440 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
441 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
442 final long endVisibleWindow
, final Object source
) {
444 Display display
= tsfviewer
.getControl().getDisplay();
445 display
.asyncExec(new Runnable() {
448 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
449 // validate visible boundaries
450 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
451 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
453 tsfviewer
.resizeControls();
459 public void dispose() {
460 // dispose parent resources
463 tsfviewer
.removeWidgetSelectionListner(this);
464 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
469 * Registers as listener of time selection from other tmf views
475 public void synchToTime(TmfTimeSynchSignal signal
) {
476 super.synchToTime(signal
);
480 * Annotation Registers as listener of time range selection from other views
481 * The implementation handles the entry of the signal.
486 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
487 if (zoomFilter
!= null) {
488 synchToTimeRange(signal
, zoomFilter
.isChecked());
493 public void modelIncomplete(ILttngSyntEventRequest request
) {
495 // The data will be refreshed on the next request
501 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
502 * getEventProcessor()
505 public ITransEventProcessor
getEventProcessor() {
506 return ResourcesEventToHandlerFactory
.getInstance();
513 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
514 if (signal
!= null) {
515 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
517 // prepare time intervals in widget
518 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
520 // request initial data
521 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
527 * @param experimentTRange
528 * @return Adjusted time window used for the request (smaller window to
531 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
532 // Adjust the initial time window to a shorter interval to allow
533 // user to select the interesting area based on the perspective
534 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
536 dataRequest(initTimeWindow
, experimentTRange
, true, ExecutionType
.SHORT
);
537 if (TraceDebug
.isDEBUG()) {
538 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-"
539 + initTimeWindow
.getEndTime().toString());
542 return initTimeWindow
;
548 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
552 protected ParamsUpdater
getParamsUpdater() {
553 return ResourceModelFactory
.getParamsUpdater();
559 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
563 protected ItemContainer
<?
> getItemContainer() {
564 return ResourceModelFactory
.getResourceContainer();