lttng: Convert performance results from Derby to JSON
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statistics / TmfStatisticsView.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Generalized version based on LTTng
11 * Bernd Hufmann - Updated to use trace reference in TmfEvent and streaming
12 * Mathieu Denis - New request added to update the statistics from the selected time range
13 * Mathieu Denis - Generalization of the view to instantiate a viewer specific to a trace type
14 *
15 *******************************************************************************/
16
17 package org.eclipse.linuxtools.tmf.ui.views.statistics;
18
19 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
20 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
21 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
22 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
23 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
24 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
25 import org.eclipse.linuxtools.tmf.ui.viewers.ITmfViewer;
26 import org.eclipse.linuxtools.tmf.ui.viewers.statistics.TmfStatisticsViewer;
27 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
28 import org.eclipse.linuxtools.tmf.ui.widgets.tabsview.TmfViewerFolder;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Shell;
32
33 /**
34 * The generic Statistics View displays statistics for any kind of traces.
35 *
36 * It is implemented according to the MVC pattern. - The model is a
37 * TmfStatisticsTreeNode built by the State Manager. - The view is built with a
38 * TreeViewer. - The controller that keeps model and view synchronized is an
39 * observer of the model.
40 *
41 * @version 2.0
42 * @author Mathieu Denis
43 */
44 public class TmfStatisticsView extends TmfView {
45
46 /**
47 * The ID corresponds to the package in which this class is embedded.
48 */
49 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.statistics"; //$NON-NLS-1$
50
51 /**
52 * The view name.
53 */
54 public static final String TMF_STATISTICS_VIEW = "StatisticsView"; //$NON-NLS-1$
55
56 /**
57 * The viewer that builds the columns to show the statistics.
58 *
59 * @since 2.0
60 */
61 protected final TmfViewerFolder fStatsViewers;
62
63 /**
64 * Stores a reference to the selected trace.
65 */
66 private ITmfTrace fTrace;
67
68 /**
69 * Constructor of a statistics view.
70 *
71 * @param viewName The name to give to the view.
72 */
73 public TmfStatisticsView(String viewName) {
74 super(viewName);
75 /*
76 * Create a fake parent for initialization purpose, than set the parent
77 * as soon as createPartControl is called.
78 */
79 Composite temporaryParent = new Shell();
80 fStatsViewers = new TmfViewerFolder(temporaryParent);
81 }
82
83 /**
84 * Default constructor.
85 */
86 public TmfStatisticsView() {
87 this(TMF_STATISTICS_VIEW);
88 }
89
90 @Override
91 public void createPartControl(Composite parent) {
92 fStatsViewers.setParent(parent);
93 createStatisticsViewers();
94
95 ITmfTrace trace = getActiveTrace();
96 if (trace != null) {
97 traceSelected(new TmfTraceSelectedSignal(this, trace));
98 }
99 }
100
101 @Override
102 public void dispose() {
103 super.dispose();
104 fStatsViewers.dispose();
105 }
106
107 /**
108 * Handler called when an trace is opened.
109 *
110 * @param signal
111 * Contains the information about the selection.
112 * @since 2.0
113 */
114 @TmfSignalHandler
115 public void traceOpened(TmfTraceOpenedSignal signal) {
116 /*
117 * Dispose the current viewer and adapt the new one to the trace
118 * type of the trace opened
119 */
120 fStatsViewers.clear();
121 // Update the current trace
122 fTrace = signal.getTrace();
123 createStatisticsViewers();
124 fStatsViewers.layout();
125 }
126
127 /**
128 * Handler called when an trace is selected. Checks if the trace
129 * has changed and requests the selected trace if it has not yet been
130 * cached.
131 *
132 * @param signal
133 * Contains the information about the selection.
134 * @since 2.0
135 */
136 @TmfSignalHandler
137 public void traceSelected(TmfTraceSelectedSignal signal) {
138 // Does not reload the same trace if already opened
139 if (signal.getTrace() != fTrace) {
140 /*
141 * Dispose the current viewer and adapt the new one to the trace
142 * type of the trace selected
143 */
144 fStatsViewers.clear();
145 // Update the current trace
146 fTrace = signal.getTrace();
147 createStatisticsViewers();
148 fStatsViewers.layout();
149
150 TmfTraceRangeUpdatedSignal updateSignal = new TmfTraceRangeUpdatedSignal(this, fTrace, fTrace.getTimeRange());
151
152 for (ITmfViewer viewer : fStatsViewers.getViewers()) {
153 TmfStatisticsViewer statsViewer = (TmfStatisticsViewer) viewer;
154 statsViewer.sendPartialRequestOnNextUpdate();
155 statsViewer.traceRangeUpdated(updateSignal);
156 }
157 } else {
158 /*
159 * If the same trace is reselected, sends a notification to
160 * the viewers to make sure they reload correctly their partial
161 * event count.
162 */
163 for (ITmfViewer viewer : fStatsViewers.getViewers()) {
164 TmfStatisticsViewer statsViewer = (TmfStatisticsViewer) viewer;
165 // Will update the partial event count if needed.
166 statsViewer.sendPartialRequestOnNextUpdate();
167 }
168 }
169 }
170
171 /**
172 * @param signal the incoming signal
173 * @since 2.0
174 */
175 @TmfSignalHandler
176 public void traceClosed(TmfTraceClosedSignal signal) {
177 if (signal.getTrace() != fTrace) {
178 return;
179 }
180
181 // Clear the internal data
182 fTrace = null;
183
184 // Clear the UI widgets
185 fStatsViewers.clear(); // Also cancels ongoing requests
186 createStatisticsViewers();
187 fStatsViewers.layout();
188 }
189
190 @Override
191 public void setFocus() {
192 fStatsViewers.setFocus();
193 }
194
195 /**
196 * Creates the statistics viewers for all traces in an experiment and
197 * populates a viewer folder. Each viewer is placed in a different tab and
198 * the first one is selected automatically.
199 *
200 * It uses the extension point that defines the statistics viewer to build
201 * from the trace type. If no viewer is defined, another tab won't be
202 * created, since the global viewer already contains all the basic
203 * statistics. If there is no trace selected, a global statistics viewer will
204 * still be created.
205 *
206 * @since 2.0
207 */
208 protected void createStatisticsViewers() {
209 // Default style for the tabs that will be created
210 int defaultStyle = SWT.NONE;
211
212 // The folder composite that will contain the tabs
213 Composite folder = fStatsViewers.getParentFolder();
214
215 // Instantiation of the global viewer
216 if (fTrace != null) {
217 // Shows the name of the trace in the global tab
218 TmfStatisticsViewer globalViewer = new TmfStatisticsViewer(folder, Messages.TmfStatisticsView_GlobalTabName + " - " + fTrace.getName(), fTrace); //$NON-NLS-1$
219 fStatsViewers.addTab(globalViewer, Messages.TmfStatisticsView_GlobalTabName, defaultStyle);
220
221 } else {
222 // There is no trace selected. Shows an empty global tab
223 TmfStatisticsViewer globalViewer = new TmfStatisticsViewer(folder, Messages.TmfStatisticsView_GlobalTabName, fTrace);
224 fStatsViewers.addTab(globalViewer, Messages.TmfStatisticsView_GlobalTabName, defaultStyle);
225 }
226 // Makes the global viewer visible
227 fStatsViewers.setSelection(0);
228 }
229 }
This page took 0.038237 seconds and 6 git commands to generate.