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