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