1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson
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
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
15 *******************************************************************************/
17 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.statistics
;
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
;
35 * The generic Statistics View displays statistics for any kind of traces.
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.
43 * @author Mathieu Denis
45 public class TmfStatisticsView
extends TmfView
{
48 * The ID corresponds to the package in which this class is embedded.
50 public static final @NonNull String ID
= "org.eclipse.linuxtools.tmf.ui.views.statistics"; //$NON-NLS-1$
55 public static final String TMF_STATISTICS_VIEW
= "StatisticsView"; //$NON-NLS-1$
58 * The viewer that builds the columns to show the statistics.
62 protected final TmfViewerFolder fStatsViewers
;
65 * Stores a reference to the selected trace.
67 private ITmfTrace fTrace
;
70 * Constructor of a statistics view.
72 * @param viewName The name to give to the view.
74 public TmfStatisticsView(String viewName
) {
77 * Create a fake parent for initialization purpose, than set the parent
78 * as soon as createPartControl is called.
80 Composite temporaryParent
= new Shell();
81 fStatsViewers
= new TmfViewerFolder(temporaryParent
);
85 * Default constructor.
87 public TmfStatisticsView() {
88 this(TMF_STATISTICS_VIEW
);
92 public void createPartControl(Composite parent
) {
93 fStatsViewers
.setParent(parent
);
94 createStatisticsViewers();
96 ITmfTrace trace
= getActiveTrace();
98 traceSelected(new TmfTraceSelectedSignal(this, trace
));
103 public void dispose() {
105 fStatsViewers
.dispose();
109 * Handler called when an trace is opened.
112 * Contains the information about the selection.
116 public void traceOpened(TmfTraceOpenedSignal signal
) {
118 * Dispose the current viewer and adapt the new one to the trace
119 * type of the trace opened
121 fStatsViewers
.clear();
122 // Update the current trace
123 fTrace
= signal
.getTrace();
124 createStatisticsViewers();
125 fStatsViewers
.layout();
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
134 * Contains the information about the selection.
138 public void traceSelected(TmfTraceSelectedSignal signal
) {
139 // Does not reload the same trace if already opened
140 if (signal
.getTrace() != fTrace
) {
142 * Dispose the current viewer and adapt the new one to the trace
143 * type of the trace selected
145 fStatsViewers
.clear();
146 // Update the current trace
147 fTrace
= signal
.getTrace();
148 createStatisticsViewers();
149 fStatsViewers
.layout();
151 TmfTraceRangeUpdatedSignal updateSignal
= new TmfTraceRangeUpdatedSignal(this, fTrace
, fTrace
.getTimeRange());
153 for (ITmfViewer viewer
: fStatsViewers
.getViewers()) {
154 TmfStatisticsViewer statsViewer
= (TmfStatisticsViewer
) viewer
;
155 statsViewer
.sendPartialRequestOnNextUpdate();
156 statsViewer
.traceRangeUpdated(updateSignal
);
160 * If the same trace is reselected, sends a notification to
161 * the viewers to make sure they reload correctly their partial
164 for (ITmfViewer viewer
: fStatsViewers
.getViewers()) {
165 TmfStatisticsViewer statsViewer
= (TmfStatisticsViewer
) viewer
;
166 // Will update the partial event count if needed.
167 statsViewer
.sendPartialRequestOnNextUpdate();
173 * @param signal the incoming signal
177 public void traceClosed(TmfTraceClosedSignal signal
) {
178 if (signal
.getTrace() != fTrace
) {
182 // Clear the internal data
185 // Clear the UI widgets
186 fStatsViewers
.clear(); // Also cancels ongoing requests
187 createStatisticsViewers();
188 fStatsViewers
.layout();
192 public void setFocus() {
193 fStatsViewers
.setFocus();
197 * Creates the statistics viewers for all traces in an experiment and
198 * populates a viewer folder. Each viewer is placed in a different tab and
199 * the first one is selected automatically.
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
204 * statistics. If there is no trace selected, a global statistics viewer will
209 protected void createStatisticsViewers() {
210 // Default style for the tabs that will be created
211 int defaultStyle
= SWT
.NONE
;
213 // The folder composite that will contain the tabs
214 Composite folder
= fStatsViewers
.getParentFolder();
216 // Instantiation of the global viewer
217 if (fTrace
!= null) {
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$
220 fStatsViewers
.addTab(globalViewer
, Messages
.TmfStatisticsView_GlobalTabName
, defaultStyle
);
223 // There is no trace selected. Shows an empty global tab
224 TmfStatisticsViewer globalViewer
= new TmfStatisticsViewer(folder
, Messages
.TmfStatisticsView_GlobalTabName
, fTrace
);
225 fStatsViewers
.addTab(globalViewer
, Messages
.TmfStatisticsView_GlobalTabName
, defaultStyle
);
227 // Makes the global viewer visible
228 fStatsViewers
.setSelection(0);