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