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