Commit | Line | Data |
---|---|---|
79e08fd0 | 1 | /******************************************************************************* |
09667aa4 | 2 | * Copyright (c) 2011, 2012 Ericsson |
20ff3b75 | 3 | * |
79e08fd0 BH |
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 | |
20ff3b75 | 8 | * |
79e08fd0 | 9 | * Contributors: |
09667aa4 | 10 | * Mathieu Denis <mathieu.denis@polymtl.ca> - Generalized version based on LTTng |
79e08fd0 | 11 | * Bernd Hufmann - Updated to use trace reference in TmfEvent and streaming |
25a042b3 | 12 | * Mathieu Denis - New request added to update the statistics from the selected time range |
cfd22ad0 | 13 | * Mathieu Denis - Generalization of the view to instantiate a viewer specific to a trace type |
20ff3b75 | 14 | * |
79e08fd0 BH |
15 | *******************************************************************************/ |
16 | ||
17 | package org.eclipse.linuxtools.tmf.ui.views.statistics; | |
18 | ||
cfd22ad0 | 19 | import org.eclipse.core.resources.IResource; |
cfd22ad0 | 20 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
05627bda | 21 | import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal; |
ea279a69 | 22 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; |
6c13869b FC |
23 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal; |
24 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; | |
25 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
05627bda | 26 | import org.eclipse.linuxtools.tmf.core.signal.TmfStartSynchSignal; |
6c13869b | 27 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
9e0640dc | 28 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
cfd22ad0 | 29 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; |
05627bda | 30 | import org.eclipse.linuxtools.tmf.ui.viewers.ITmfViewer; |
cfd22ad0 | 31 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.TmfStatisticsViewer; |
79e08fd0 | 32 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
05627bda MD |
33 | import org.eclipse.linuxtools.tmf.ui.widgets.tabsview.TmfViewerFolder; |
34 | import org.eclipse.swt.SWT; | |
79e08fd0 | 35 | import org.eclipse.swt.widgets.Composite; |
05627bda | 36 | import org.eclipse.swt.widgets.Shell; |
79e08fd0 BH |
37 | |
38 | /** | |
79e08fd0 | 39 | * The generic Statistics View displays statistics for any kind of traces. |
20ff3b75 | 40 | * |
09667aa4 MD |
41 | * It is implemented according to the MVC pattern. - The model is a |
42 | * TmfStatisticsTreeNode built by the State Manager. - The view is built with a | |
43 | * TreeViewer. - The controller that keeps model and view synchronized is an | |
44 | * observer of the model. | |
20ff3b75 | 45 | * |
25a042b3 | 46 | * @version 2.0 |
09667aa4 | 47 | * @author Mathieu Denis |
79e08fd0 BH |
48 | */ |
49 | public class TmfStatisticsView extends TmfView { | |
09667aa4 | 50 | |
79e08fd0 | 51 | /** |
05627bda | 52 | * The ID corresponds to the package in which this class is embedded. |
79e08fd0 BH |
53 | */ |
54 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.statistics"; //$NON-NLS-1$ | |
09667aa4 | 55 | |
d26274e7 | 56 | /** |
09667aa4 | 57 | * The view name. |
d26274e7 | 58 | */ |
66711dc8 | 59 | public static final String TMF_STATISTICS_VIEW = "StatisticsView"; //$NON-NLS-1$ |
09667aa4 | 60 | |
d26274e7 | 61 | /** |
05627bda | 62 | * The viewer that builds the columns to show the statistics. |
25a042b3 MD |
63 | * |
64 | * @since 2.0 | |
65 | */ | |
05627bda | 66 | protected final TmfViewerFolder fStatsViewers; |
25a042b3 | 67 | |
d26274e7 | 68 | /** |
05627bda | 69 | * Flag to force request the data from trace. |
cfd22ad0 MD |
70 | */ |
71 | protected boolean fRequestData = false; | |
72 | ||
73 | /** | |
05627bda | 74 | * Stores a reference to the selected experiment. |
25a042b3 | 75 | */ |
05627bda | 76 | private TmfExperiment fExperiment; |
09667aa4 | 77 | |
79e08fd0 BH |
78 | /** |
79 | * Constructor of a statistics view. | |
20ff3b75 | 80 | * |
cfd22ad0 | 81 | * @param viewName The name to give to the view. |
79e08fd0 BH |
82 | */ |
83 | public TmfStatisticsView(String viewName) { | |
84 | super(viewName); | |
05627bda MD |
85 | /* |
86 | * Create a fake parent for initialization purpose, than set the parent | |
87 | * as soon as createPartControl is called. | |
88 | */ | |
89 | Composite temporaryParent = new Shell(); | |
90 | fStatsViewers = new TmfViewerFolder(temporaryParent); | |
79e08fd0 BH |
91 | } |
92 | ||
93 | /** | |
94 | * Default constructor. | |
95 | */ | |
96 | public TmfStatisticsView() { | |
97 | this(TMF_STATISTICS_VIEW); | |
98 | } | |
99 | ||
100 | /* | |
101 | * (non-Javadoc) | |
09667aa4 MD |
102 | * |
103 | * @see | |
104 | * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) | |
79e08fd0 BH |
105 | */ |
106 | @Override | |
107 | public void createPartControl(Composite parent) { | |
05627bda | 108 | fStatsViewers.setParent(parent); |
cfd22ad0 | 109 | TmfExperiment currentExperiment = TmfExperiment.getCurrentExperiment(); |
79e08fd0 | 110 | // Read current data if any available |
cfd22ad0 | 111 | if (currentExperiment != null) { |
1b70b6dc | 112 | fRequestData = true; |
79e08fd0 | 113 | // Insert the statistics data into the tree |
cfd22ad0 | 114 | TmfExperimentSelectedSignal signal = new TmfExperimentSelectedSignal(this, currentExperiment); |
79e08fd0 | 115 | experimentSelected(signal); |
cfd22ad0 | 116 | return; |
09667aa4 | 117 | } |
05627bda | 118 | createStatisticsViewers(); |
cfd22ad0 MD |
119 | /* |
120 | * Updates the experiment field only at the end because | |
121 | * experimentSelected signal verifies the old selected experiment to | |
122 | * avoid reloading the same trace. | |
123 | */ | |
124 | fExperiment = currentExperiment; | |
79e08fd0 BH |
125 | } |
126 | ||
cfd22ad0 MD |
127 | /** |
128 | * Handler called when an experiment is selected. Checks if the experiment | |
129 | * has changed and requests the selected experiment if it has not yet been | |
130 | * cached. | |
09667aa4 | 131 | * |
cfd22ad0 MD |
132 | * @param signal |
133 | * Contains the information about the selection. | |
79e08fd0 | 134 | */ |
cfd22ad0 MD |
135 | @TmfSignalHandler |
136 | public void experimentSelected(TmfExperimentSelectedSignal signal) { | |
137 | if (signal != null) { | |
138 | // Does not reload the same trace if already opened | |
139 | if (fExperiment == null | |
140 | || signal.getExperiment().toString().compareTo(fExperiment.toString()) != 0) { | |
141 | /* | |
142 | * Dispose the current viewer and adapt the new one to the trace | |
143 | * type of the experiment selected | |
144 | */ | |
05627bda | 145 | fStatsViewers.clear(); |
cfd22ad0 MD |
146 | // Update the current experiment |
147 | fExperiment = signal.getExperiment(); | |
05627bda MD |
148 | createStatisticsViewers(); |
149 | fStatsViewers.layout(); | |
150 | ||
cfd22ad0 | 151 | if (fRequestData) { |
73fbf6be | 152 | TmfExperimentRangeUpdatedSignal updateSignal = new TmfExperimentRangeUpdatedSignal(this, fExperiment, fExperiment.getTimeRange()); |
05627bda MD |
153 | TmfStatisticsViewer statsViewer; |
154 | // Synchronizes the request to make them coalesced | |
155 | fExperiment.startSynch(new TmfStartSynchSignal(0)); | |
156 | for (ITmfViewer viewer : fStatsViewers.getViewers()) { | |
157 | if (!(viewer instanceof TmfStatisticsViewer)) { | |
158 | Activator.getDefault().logError("Error - cannot cast viewer to a statistics viewer"); //$NON-NLS-1$ | |
159 | continue; | |
160 | } | |
161 | statsViewer = (TmfStatisticsViewer) viewer; | |
162 | statsViewer.experimentRangeUpdated(updateSignal); | |
163 | } | |
164 | fExperiment.endSynch(new TmfEndSynchSignal(0)); | |
cfd22ad0 MD |
165 | fRequestData = false; |
166 | } | |
3c934968 MD |
167 | } else { |
168 | /* | |
169 | * If the same experiment is reselected, sends a notification to | |
170 | * the viewers to make sure they reload correctly their partial | |
171 | * event count. | |
172 | */ | |
173 | TmfStatisticsViewer statsViewer; | |
174 | for (ITmfViewer viewer : fStatsViewers.getViewers()) { | |
175 | if (!(viewer instanceof TmfStatisticsViewer)) { | |
176 | Activator.getDefault().logError("Error - cannot cast viewer to a statistics viewer"); //$NON-NLS-1$ | |
177 | continue; | |
178 | } | |
179 | statsViewer = (TmfStatisticsViewer) viewer; | |
180 | // Will update the partial event count if needed. | |
181 | statsViewer.sendPartialRequestOnNextUpdate(); | |
182 | } | |
cfd22ad0 MD |
183 | } |
184 | } | |
185 | } | |
186 | ||
cfd22ad0 MD |
187 | /* |
188 | * (non-Javadoc) | |
189 | * | |
190 | * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#dispose() | |
191 | */ | |
192 | @Override | |
193 | public void dispose() { | |
194 | super.dispose(); | |
05627bda | 195 | fStatsViewers.dispose(); |
cfd22ad0 MD |
196 | } |
197 | ||
ea279a69 FC |
198 | /** |
199 | * @param signal the incoming signal | |
200 | * @since 2.0 | |
201 | */ | |
202 | @TmfSignalHandler | |
203 | public void experimentDisposed(TmfExperimentDisposedSignal signal) { | |
204 | ||
205 | // Clear the internal data | |
206 | fExperiment = null; | |
207 | fRequestData = false; | |
208 | ||
209 | // Clear the UI widgets | |
210 | fStatsViewers.clear(); // Also cancels ongoing requests | |
211 | createStatisticsViewers(); | |
212 | fStatsViewers.layout(); | |
213 | } | |
214 | ||
cfd22ad0 MD |
215 | /* |
216 | * (non-Javadoc) | |
217 | * | |
218 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
219 | */ | |
220 | @Override | |
221 | public void setFocus() { | |
05627bda | 222 | fStatsViewers.setFocus(); |
cfd22ad0 MD |
223 | } |
224 | ||
c0341b86 | 225 | /** |
05627bda | 226 | * Creates the statistics viewers for all traces in the experiment and |
eeb388b1 | 227 | * populates a viewer folder. Each viewer is placed in a different tab and |
05627bda | 228 | * the first one is selected automatically. |
09667aa4 | 229 | * |
05627bda MD |
230 | * It uses the extension point that defines the statistics viewer to build |
231 | * from the trace type. If no viewer is defined, another tab won't be | |
232 | * created, since the global viewer already contains all the basic | |
233 | * statistics. If the experiment is empty, a global statistics viewer will | |
234 | * still be created. | |
c0341b86 | 235 | * |
25a042b3 MD |
236 | * @since 2.0 |
237 | */ | |
05627bda MD |
238 | protected void createStatisticsViewers() { |
239 | // Default style for the tabs that will be created | |
240 | int defaultStyle = SWT.NONE; | |
25a042b3 | 241 | |
05627bda MD |
242 | // The folder composite that will contain the tabs |
243 | Composite folder = fStatsViewers.getParentFolder(); | |
25a042b3 | 244 | |
05627bda | 245 | // Instantiation of the global viewer |
73fbf6be | 246 | TmfStatisticsViewer globalViewer = getGlobalViewer(); |
05627bda | 247 | if (fExperiment != null) { |
73fbf6be MD |
248 | if (globalViewer != null) { |
249 | // Shows the name of the experiment in the global tab | |
250 | globalViewer.init(folder, Messages.TmfStatisticsView_GlobalTabName + " - " + fExperiment.getName(), fExperiment); //$NON-NLS-1$ | |
251 | } | |
05627bda MD |
252 | fStatsViewers.addTab(globalViewer, Messages.TmfStatisticsView_GlobalTabName, defaultStyle); |
253 | ||
254 | String traceName; | |
255 | IResource traceResource; | |
256 | // Creates a statistics viewer for each traces. | |
cfd22ad0 | 257 | for (ITmfTrace trace : fExperiment.getTraces()) { |
05627bda MD |
258 | traceName = trace.getName(); |
259 | traceResource = trace.getResource(); | |
260 | TmfStatisticsViewer viewer = getStatisticsViewer(traceResource); | |
261 | /* | |
262 | * Adds a new viewer only if there is one defined for the | |
263 | * selected trace type, since the global tab already contains | |
264 | * all the basic event counts for the trace(s) | |
265 | */ | |
266 | if (viewer != null) { | |
267 | viewer.init(folder, traceName, trace); | |
268 | fStatsViewers.addTab(viewer, viewer.getName(), defaultStyle); | |
79e08fd0 BH |
269 | } |
270 | } | |
05627bda | 271 | } else { |
73fbf6be MD |
272 | if (globalViewer != null) { |
273 | // There is no experiment selected. Shows an empty global tab | |
274 | globalViewer.init(folder, Messages.TmfStatisticsView_GlobalTabName, fExperiment); | |
275 | } | |
05627bda | 276 | fStatsViewers.addTab(globalViewer, Messages.TmfStatisticsView_GlobalTabName, defaultStyle); |
79e08fd0 | 277 | } |
05627bda MD |
278 | // Makes the global viewer visible |
279 | fStatsViewers.setSelection(0); | |
79e08fd0 BH |
280 | } |
281 | ||
25a042b3 | 282 | /** |
05627bda MD |
283 | * Retrieves and instantiates a viewer based on his plug-in definition for a |
284 | * specific trace type. It is specific to the statistics viewer. | |
25a042b3 | 285 | * |
05627bda MD |
286 | * It only calls the 0-parameter constructor without performing any other |
287 | * initialization on the viewer. | |
25a042b3 | 288 | * |
05627bda MD |
289 | * @param resource |
290 | * The resource where to find the information about the trace | |
291 | * properties | |
292 | * @return a new statistics viewer based on his plug-in definition, or null | |
293 | * if no statistics definition was found for the trace type. | |
25a042b3 MD |
294 | * @since 2.0 |
295 | */ | |
05627bda MD |
296 | protected static TmfStatisticsViewer getStatisticsViewer(IResource resource) { |
297 | return (TmfStatisticsViewer) TmfTraceType.getTraceTypeElement(resource, TmfTraceType.STATISTICS_VIEWER_ELEM); | |
79e08fd0 | 298 | } |
73fbf6be MD |
299 | |
300 | /** | |
301 | * @return The class to use to instantiate the global statistics viewer | |
302 | * @since 2.0 | |
303 | */ | |
304 | protected TmfStatisticsViewer getGlobalViewer() { | |
305 | return new TmfStatisticsViewer(); | |
306 | } | |
79e08fd0 | 307 | } |