1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 * Mathieu Denis <mathieu.denis@polymtl.ca> - Generalized version based on LTTng
11 * Bernd Hufmann - Updated to use trace reference in TmfEvent and streaming
12 * Mathieu Denis - New request added to update the statistics from the selected time range
13 * Mathieu Denis - Generalization of the view to instantiate a viewer specific to a trace type
15 *******************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TmfTraceType
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceRangeUpdatedSignal
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.ITmfViewer
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.TmfStatisticsViewer
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.tabsview
.TmfViewerFolder
;
32 import org
.eclipse
.swt
.SWT
;
33 import org
.eclipse
.swt
.widgets
.Composite
;
34 import org
.eclipse
.swt
.widgets
.Shell
;
37 * The generic Statistics View displays statistics for any kind of traces.
39 * It is implemented according to the MVC pattern. - The model is a
40 * TmfStatisticsTreeNode built by the State Manager. - The view is built with a
41 * TreeViewer. - The controller that keeps model and view synchronized is an
42 * observer of the model.
45 * @author Mathieu Denis
47 public class TmfStatisticsView
extends TmfView
{
50 * The ID corresponds to the package in which this class is embedded.
52 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.statistics"; //$NON-NLS-1$
57 public static final String TMF_STATISTICS_VIEW
= "StatisticsView"; //$NON-NLS-1$
60 * The viewer that builds the columns to show the statistics.
64 protected final TmfViewerFolder fStatsViewers
;
67 * Stores a reference to the selected trace.
69 private ITmfTrace fTrace
;
72 * Constructor of a statistics view.
74 * @param viewName The name to give to the view.
76 public TmfStatisticsView(String viewName
) {
79 * Create a fake parent for initialization purpose, than set the parent
80 * as soon as createPartControl is called.
82 Composite temporaryParent
= new Shell();
83 fStatsViewers
= new TmfViewerFolder(temporaryParent
);
87 * Default constructor.
89 public TmfStatisticsView() {
90 this(TMF_STATISTICS_VIEW
);
94 public void createPartControl(Composite parent
) {
95 fStatsViewers
.setParent(parent
);
96 createStatisticsViewers();
98 ITmfTrace trace
= getActiveTrace();
100 traceSelected(new TmfTraceSelectedSignal(this, trace
));
105 public void dispose() {
107 fStatsViewers
.dispose();
111 * Handler called when an trace is opened.
114 * Contains the information about the selection.
118 public void traceOpened(TmfTraceOpenedSignal signal
) {
120 * Dispose the current viewer and adapt the new one to the trace
121 * type of the trace opened
123 fStatsViewers
.clear();
124 // Update the current trace
125 fTrace
= signal
.getTrace();
126 createStatisticsViewers();
127 fStatsViewers
.layout();
131 * Handler called when an trace is selected. Checks if the trace
132 * has changed and requests the selected trace if it has not yet been
136 * Contains the information about the selection.
140 public void traceSelected(TmfTraceSelectedSignal signal
) {
141 // Does not reload the same trace if already opened
142 if (signal
.getTrace() != fTrace
) {
144 * Dispose the current viewer and adapt the new one to the trace
145 * type of the trace selected
147 fStatsViewers
.clear();
148 // Update the current trace
149 fTrace
= signal
.getTrace();
150 createStatisticsViewers();
151 fStatsViewers
.layout();
153 TmfTraceRangeUpdatedSignal updateSignal
= new TmfTraceRangeUpdatedSignal(this, fTrace
, fTrace
.getTimeRange());
155 for (ITmfViewer viewer
: fStatsViewers
.getViewers()) {
156 TmfStatisticsViewer statsViewer
= (TmfStatisticsViewer
) viewer
;
157 statsViewer
.sendPartialRequestOnNextUpdate();
158 statsViewer
.traceRangeUpdated(updateSignal
);
162 * If the same trace is reselected, sends a notification to
163 * the viewers to make sure they reload correctly their partial
166 for (ITmfViewer viewer
: fStatsViewers
.getViewers()) {
167 TmfStatisticsViewer statsViewer
= (TmfStatisticsViewer
) viewer
;
168 // Will update the partial event count if needed.
169 statsViewer
.sendPartialRequestOnNextUpdate();
175 * @param signal the incoming signal
179 public void traceClosed(TmfTraceClosedSignal signal
) {
180 if (signal
.getTrace() != fTrace
) {
184 // Clear the internal data
187 // Clear the UI widgets
188 fStatsViewers
.clear(); // Also cancels ongoing requests
189 createStatisticsViewers();
190 fStatsViewers
.layout();
194 public void setFocus() {
195 fStatsViewers
.setFocus();
199 * Creates the statistics viewers for all traces in an experiment and
200 * populates a viewer folder. Each viewer is placed in a different tab and
201 * the first one is selected automatically.
203 * It uses the extension point that defines the statistics viewer to build
204 * from the trace type. If no viewer is defined, another tab won't be
205 * created, since the global viewer already contains all the basic
206 * statistics. If there is no trace selected, a global statistics viewer will
211 protected void createStatisticsViewers() {
212 // Default style for the tabs that will be created
213 int defaultStyle
= SWT
.NONE
;
215 // The folder composite that will contain the tabs
216 Composite folder
= fStatsViewers
.getParentFolder();
218 // Instantiation of the global viewer
219 TmfStatisticsViewer globalViewer
= getGlobalViewer();
220 if (fTrace
!= null) {
221 if (globalViewer
!= null) {
222 // Shows the name of the trace in the global tab
223 globalViewer
.init(folder
, Messages
.TmfStatisticsView_GlobalTabName
+ " - " + fTrace
.getName(), fTrace
); //$NON-NLS-1$
225 fStatsViewers
.addTab(globalViewer
, Messages
.TmfStatisticsView_GlobalTabName
, defaultStyle
);
228 IResource traceResource
;
229 // Creates a statistics viewer for each trace.
230 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(fTrace
)) {
231 traceName
= trace
.getName();
232 traceResource
= trace
.getResource();
233 TmfStatisticsViewer viewer
= getStatisticsViewer(traceResource
);
235 * Adds a new viewer only if there is one defined for the
236 * selected trace type, since the global tab already contains
237 * all the basic event counts for the trace(s)
239 if (viewer
!= null) {
240 viewer
.init(folder
, traceName
, trace
);
241 fStatsViewers
.addTab(viewer
, viewer
.getName(), defaultStyle
);
245 if (globalViewer
!= null) {
246 // There is no trace selected. Shows an empty global tab
247 globalViewer
.init(folder
, Messages
.TmfStatisticsView_GlobalTabName
, fTrace
);
249 fStatsViewers
.addTab(globalViewer
, Messages
.TmfStatisticsView_GlobalTabName
, defaultStyle
);
251 // Makes the global viewer visible
252 fStatsViewers
.setSelection(0);
256 * Retrieves and instantiates a viewer based on his plug-in definition for a
257 * specific trace type. It is specific to the statistics viewer.
259 * It only calls the 0-parameter constructor without performing any other
260 * initialization on the viewer.
263 * The resource where to find the information about the trace
265 * @return a new statistics viewer based on his plug-in definition, or null
266 * if no statistics definition was found for the trace type.
269 protected static TmfStatisticsViewer
getStatisticsViewer(IResource resource
) {
270 return (TmfStatisticsViewer
) TmfTraceType
.getTraceTypeElement(resource
, TmfTraceType
.STATISTICS_VIEWER_ELEM
);
274 * @return The class to use to instantiate the global statistics viewer
277 protected TmfStatisticsViewer
getGlobalViewer() {
278 return new TmfStatisticsViewer();