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
.signal
.TmfExperimentSelectedSignal
;
32 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfRangeSynchSignal
;
33 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
34 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTimeSynchSignal
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.TmfViewerFactory
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeScaleSelectionListener
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.ITmfTimeSelectionListener
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeScaleSelectionEvent
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeSelectionEvent
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
41 import org
.eclipse
.swt
.SWT
;
42 import org
.eclipse
.swt
.layout
.FillLayout
;
43 import org
.eclipse
.swt
.widgets
.Composite
;
44 import org
.eclipse
.swt
.widgets
.Display
;
45 import org
.eclipse
.swt
.widgets
.Menu
;
46 import org
.eclipse
.ui
.IActionBars
;
47 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
48 import org
.eclipse
.ui
.PlatformUI
;
49 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
55 public class ResourcesView
extends AbsTimeUpdateView
implements
56 ITmfTimeSelectionListener
, ITmfTimeScaleSelectionListener
{
58 // ========================================================================
60 // ========================================================================
61 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.resources";
63 // private int totalNumItems = 0;
65 private Action resetScale
;
66 private Action nextEvent
;
67 private Action prevEvent
;
68 private Action nextTrace
;
69 private Action prevTrace
;
70 private Action showLegend
;
71 private Action filterTraces
;
72 private Action zoomIn
;
73 private Action zoomOut
;
74 private Action zoomFilter
;
75 private Composite top
;
77 // private static SimpleDateFormat stimeformat = new SimpleDateFormat(
78 // "yy/MM/dd HH:mm:ss");
80 // private TraceModelImplFactory fact;
82 // ========================================================================
84 // ========================================================================
89 public ResourcesView() {
93 // ========================================================================
95 // ========================================================================
98 * This is a callback that will allow us to create the viewer and initialize
102 public void createPartControl(Composite parent
) {
103 top
= new Composite(parent
, SWT
.BORDER
);
105 top
.setLayout(new FillLayout());
106 tsfviewer
= TmfViewerFactory
.createViewer(top
,
107 new TimeRangeViewerProvider());
109 tsfviewer
.addWidgetSelectionListner(this);
110 tsfviewer
.addWidgetTimeScaleSelectionListner(this);
112 // Traces shall not be grouped to allow synchronisation
113 tsfviewer
.groupTraces(true);
114 tsfviewer
.setAcceptSelectionAPIcalls(true);
116 // Viewer to notify selection to this class
117 // This class will synchronise selections with table.
118 tsfviewer
.addWidgetSelectionListner(this);
119 tsfviewer
.addWidgetTimeScaleSelectionListner(this);
121 // Create the help context id for the viewer's control
122 // TODO: Associate with help system
123 PlatformUI
.getWorkbench().getHelpSystem().setHelp(
124 tsfviewer
.getControl(),
125 "org.eclipse.linuxtools.lttng.ui.views.resource.view"); //$NON-NLS-1$
129 contributeToActionBars();
131 // Read relevant values
132 int timeSpaceWidth
= tsfviewer
.getTimeSpace();
133 if (timeSpaceWidth
< 0) {
134 timeSpaceWidth
= -timeSpaceWidth
;
137 TmfExperiment
<?
> experiment
= TmfExperiment
.getCurrentExperiment();
138 if (experiment
!= null) {
139 TmfTimeRange experimentTRange
= experiment
.getTimeRange();
140 if (experimentTRange
!= null) {
141 long time0
= experimentTRange
.getStartTime().getValue();
142 long time1
= experimentTRange
.getEndTime().getValue();
143 ParamsUpdater paramUpdater
= getParamsUpdater();
144 paramUpdater
.update(time0
, time1
, timeSpaceWidth
);
146 // send the initial request and obtained the adjusted time used
147 TmfTimeRange adjustedTimeRange
= initialExperimentDataRequest(this, experimentTRange
);
149 // initialize widget time boundaries and filtering parameters
150 ModelUpdateInit(experimentTRange
, adjustedTimeRange
, this);
152 TraceDebug
.debug("No selected experiment information available");
156 private void hookContextMenu() {
157 MenuManager menuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
158 menuMgr
.setRemoveAllWhenShown(true);
159 menuMgr
.addMenuListener(new IMenuListener() {
160 public void menuAboutToShow(IMenuManager manager
) {
161 ResourcesView
.this.fillContextMenu(manager
);
165 Menu menu
= menuMgr
.createContextMenu(tsfviewer
.getControl());
166 tsfviewer
.getControl().setMenu(menu
);
168 .registerContextMenu(menuMgr
, tsfviewer
.getSelectionProvider());
171 private void contributeToActionBars() {
172 IActionBars bars
= getViewSite().getActionBars();
173 fillLocalPullDown(bars
.getMenuManager());
174 fillLocalToolBar(bars
.getToolBarManager());
177 private void fillLocalPullDown(IMenuManager manager
) {
178 manager
.add(new Separator());
179 // manager.add(showLegend);
180 manager
.add(new Separator());
181 manager
.add(resetScale
);
182 manager
.add(nextEvent
);
183 manager
.add(prevEvent
);
184 manager
.add(nextTrace
);
185 manager
.add(prevTrace
);
186 // manager.add(filterTraces);
188 manager
.add(zoomOut
);
189 manager
.add(zoomFilter
);
190 manager
.add(new Separator());
193 private void fillContextMenu(IMenuManager manager
) {
194 // manager.add(showLegend);
195 manager
.add(new Separator());
196 manager
.add(resetScale
);
197 manager
.add(nextEvent
);
198 manager
.add(prevEvent
);
199 manager
.add(nextTrace
);
200 manager
.add(prevTrace
);
201 // manager.add(showLegend);
202 // manager.add(filterTraces);
204 manager
.add(zoomOut
);
205 manager
.add(zoomFilter
);
206 manager
.add(new Separator());
207 manager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
210 private void fillLocalToolBar(IToolBarManager manager
) {
211 // manager.add(showLegend);
212 manager
.add(new Separator());
213 manager
.add(resetScale
);
214 manager
.add(nextEvent
);
215 manager
.add(prevEvent
);
216 manager
.add(nextTrace
);
217 manager
.add(prevTrace
);
218 // manager.add(filterTraces);
220 manager
.add(zoomOut
);
221 manager
.add(zoomFilter
);
222 manager
.add(new Separator());
225 private void makeActions() {
227 resetScale
= new Action() {
230 if (tsfviewer
!= null) {
231 tsfviewer
.resetStartFinishTime();
236 resetScale
.setText(Messages
.getString("ResourcesView.Action.Reset")); //$NON-NLS-1$
237 resetScale
.setToolTipText(Messages
238 .getString("ResourcesView.Action.Reset.ToolTip")); //$NON-NLS-1$
239 resetScale
.setImageDescriptor(AbstractUIPlugin
240 .imageDescriptorFromPlugin(Messages
241 .getString("ResourcesView.tmf.UI"),
242 "icons/home_nav.gif"));
245 nextEvent
= new Action() {
248 if (tsfviewer
!= null) {
249 tsfviewer
.selectNextEvent();
253 nextEvent
.setText(Messages
.getString("ResourcesView.Action.NextEvent")); //$NON-NLS-1$
254 nextEvent
.setToolTipText(Messages
255 .getString("ResourcesView.Action.NextEvent.Tooltip")); //$NON-NLS-1$
256 nextEvent
.setImageDescriptor(AbstractUIPlugin
257 .imageDescriptorFromPlugin(Messages
258 .getString("ResourcesView.tmf.UI"),
259 "icons/next_event.gif"));
262 prevEvent
= new Action() {
265 if (tsfviewer
!= null) {
266 tsfviewer
.selectPrevEvent();
270 prevEvent
.setText(Messages
.getString("ResourcesView.Action.PrevEvent")); //$NON-NLS-1$
271 prevEvent
.setToolTipText(Messages
272 .getString("ResourcesView.Action.PrevEvent.Tooltip")); //$NON-NLS-1$
273 prevEvent
.setImageDescriptor(AbstractUIPlugin
274 .imageDescriptorFromPlugin(Messages
275 .getString("ResourcesView.tmf.UI"),
276 "icons/prev_event.gif"));
279 nextTrace
= new Action() {
282 if (tsfviewer
!= null) {
283 tsfviewer
.selectNextTrace();
287 nextTrace
.setText(Messages
288 .getString("ResourcesView.Action.NextResource")); //$NON-NLS-1$
289 nextTrace
.setToolTipText(Messages
290 .getString("ResourcesView.Action.NextResource.ToolTip")); //$NON-NLS-1$
291 nextTrace
.setImageDescriptor(AbstractUIPlugin
292 .imageDescriptorFromPlugin(Messages
293 .getString("ResourcesView.tmf.UI"),
294 "icons/next_item.gif"));
297 prevTrace
= new Action() {
300 if (tsfviewer
!= null) {
301 tsfviewer
.selectPrevTrace();
305 prevTrace
.setText(Messages
306 .getString("ResourcesView.Action.PreviousResource")); //$NON-NLS-1$
307 prevTrace
.setToolTipText(Messages
308 .getString("ResourcesView.Action.PreviousResource.Tooltip")); //$NON-NLS-1$
309 prevTrace
.setImageDescriptor(AbstractUIPlugin
310 .imageDescriptorFromPlugin(Messages
311 .getString("ResourcesView.tmf.UI"),
312 "icons/prev_item.gif"));
315 showLegend
= new Action() {
318 if (tsfviewer
!= null) {
319 tsfviewer
.showLegend();
323 showLegend
.setText(Messages
.getString("ResourcesView.Action.Legend")); //$NON-NLS-1$
324 showLegend
.setToolTipText(Messages
325 .getString("ResourcesView.Action.Legend.ToolTip")); //$NON-NLS-1$
328 filterTraces
= new Action() {
331 if (tsfviewer
!= null) {
332 tsfviewer
.filterTraces();
336 filterTraces
.setText(Messages
.getString("ResourcesView.Action.Filter")); //$NON-NLS-1$
337 filterTraces
.setToolTipText(Messages
338 .getString("ResourcesView.Action.Filter.ToolTip")); //$NON-NLS-1$
339 filterTraces
.setImageDescriptor(AbstractUIPlugin
340 .imageDescriptorFromPlugin(Messages
341 .getString("ResourcesView.tmf.UI"),
342 "icons/filter_items.gif"));
345 zoomIn
= new Action() {
348 if (tsfviewer
!= null) {
353 zoomIn
.setText(Messages
.getString("ResourcesView.Action.ZoomIn")); //$NON-NLS-1$
354 zoomIn
.setToolTipText(Messages
355 .getString("ResourcesView.Action.ZoomIn.Tooltip")); //$NON-NLS-1$
356 zoomIn
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
357 Messages
.getString("ResourcesView.tmf.UI"),
358 "icons/zoomin_nav.gif"));
361 zoomOut
= new Action() {
364 if (tsfviewer
!= null) {
369 zoomOut
.setText(Messages
.getString("ResourcesView.Action.ZoomOut")); //$NON-NLS-1$
370 zoomOut
.setToolTipText(Messages
371 .getString("ResourcesView.Action.ZoomOut.tooltip")); //$NON-NLS-1$
372 zoomOut
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(
373 Messages
.getString("ResourcesView.tmf.UI"),
374 "icons/zoomout_nav.gif"));
377 zoomFilter
= new Action() {
380 // Nothing to do, however the selection status is needed by the
385 zoomFilter
.setText(Messages
.getString("ResourcesView.Action.ZoomFilter")); //$NON-NLS-1$
386 zoomFilter
.setToolTipText(Messages
.getString("ResourcesView.Action.ZoomFilter.tooltip")); //$NON-NLS-1$
387 zoomFilter
.setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(Messages
388 .getString("ResourcesView.tmf.UI"), "icons/filter_items.gif"));
389 zoomFilter
.setChecked(false);
391 // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED);
395 * Passing the focus request to the viewer's control.
398 public void setFocus() {
399 tsfviewer
.getControl().setFocus();
405 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
406 * tsfTmProcessSelEvent
407 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeSelectionEvent
410 public void tsfTmProcessSelEvent(TmfTimeSelectionEvent event
) {
411 // common implementation
412 super.tsfTmProcessSelEvent(event
);
418 * @seeorg.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.
419 * ITmfTimeScaleSelectionListener
420 * #tsfTmProcessTimeScaleEvent(org.eclipse.linuxtools
421 * .tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent)
423 public void tsfTmProcessTimeScaleEvent(TmfTimeScaleSelectionEvent event
) {
424 super.tsfTmProcessTimeScaleEvent(event
);
431 * org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#displayModel
432 * (org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.
433 * ITmfTimeAnalysisEntry[], long, long, boolean, long, long,
436 public void displayModel(final ITmfTimeAnalysisEntry
[] items
, final long startBoundTime
,
437 final long endBoundTime
, final boolean updateTimeBounds
, final long startVisibleWindow
,
438 final long endVisibleWindow
, final Object source
) {
440 Display display
= tsfviewer
.getControl().getDisplay();
441 display
.asyncExec(new Runnable() {
444 tsfviewer
.display(items
, startBoundTime
, endBoundTime
, updateTimeBounds
);
445 // validate visible boundaries
446 if (startVisibleWindow
> -1 && endVisibleWindow
> -1) {
447 tsfviewer
.setSelectVisTimeWindow(startVisibleWindow
, endVisibleWindow
, source
);
449 tsfviewer
.resizeControls();
455 public void dispose() {
456 // dispose parent resources
459 tsfviewer
.removeWidgetSelectionListner(this);
460 tsfviewer
.removeWidgetTimeScaleSelectionListner(this);
465 * Registers as listener of time selection from other tmf views
470 public void synchToTime(TmfTimeSynchSignal signal
) {
471 super.synchToTime(signal
);
475 * Annotation Registers as listener of time range selection from other views
476 * The implementation handles the entry of the signal.
481 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
482 if (zoomFilter
!= null) {
483 synchToTimeRange(signal
, zoomFilter
.isChecked());
488 public void modelIncomplete(ILttngSyntEventRequest request
) {
490 // The data will be refreshed on the next request
496 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
497 * getEventProcessor()
500 public ITransEventProcessor
getEventProcessor() {
501 return ResourcesEventToHandlerFactory
.getInstance();
508 public void experimentSelected(TmfExperimentSelectedSignal
<?
extends TmfEvent
> signal
) {
509 if (signal
!= null) {
510 TmfTimeRange experimentTRange
= signal
.getExperiment().getTimeRange();
512 // prepare time intervals in widget
513 ModelUpdateInit(experimentTRange
, experimentTRange
, signal
.getSource());
515 // request initial data
516 initialExperimentDataRequest(signal
.getSource(), experimentTRange
);
522 * @param experimentTRange
523 * @return Adjusted time window used for the request (smaller window to
526 private TmfTimeRange
initialExperimentDataRequest(Object source
, TmfTimeRange experimentTRange
) {
527 // Adjust the initial time window to a shorter interval to allow
528 // user to select the interesting area based on the perspective
529 TmfTimeRange initTimeWindow
= getInitTRange(experimentTRange
);
531 dataRequest(initTimeWindow
, experimentTRange
, true);
532 if (TraceDebug
.isDEBUG()) {
533 TraceDebug
.debug("Initialization request time range is: " + initTimeWindow
.getStartTime().toString() + "-"
534 + initTimeWindow
.getEndTime().toString());
537 return initTimeWindow
;
543 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
546 protected ParamsUpdater
getParamsUpdater() {
547 return ResourceModelFactory
.getParamsUpdater();
553 * @see org.eclipse.linuxtools.lttng.ui.views.common.AbsTimeUpdateView#
557 protected ItemContainer
<?
> getItemContainer() {
558 return ResourceModelFactory
.getResourceContainer();