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