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