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