f76cc923d3f89cbfbb49026c62e207957f87a5d6
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / common / AbsTimeUpdateView.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.common;
13
14 import org.eclipse.linuxtools.lttng.state.IStateDataRequestListener;
15 import org.eclipse.linuxtools.lttng.state.RequestCompletedSignal;
16 import org.eclipse.linuxtools.lttng.state.RequestStartedSignal;
17 import org.eclipse.linuxtools.lttng.state.StateDataRequest;
18 import org.eclipse.linuxtools.lttng.state.StateManager;
19 import org.eclipse.linuxtools.lttng.state.experiment.StateManagerFactory;
20 import org.eclipse.linuxtools.lttng.ui.TraceDebug;
21 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
22 import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
23 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
24
25 /**
26 * <p>
27 * Abstract class used as a base for views handling specific time range data
28 * requests
29 * </p>
30 * <p>
31 * The class handles a single element queue of data requests, and a list of
32 * requests in progress i.e. request can be triggered from different sources
33 * e.g. opening a file as well as a new selected time window
34 * </p>
35 *
36 * @author alvaro
37 *
38 */
39 public abstract class AbsTimeUpdateView extends TmfView implements
40 IStateDataRequestListener {
41
42 // ========================================================================
43 // Data
44 // ========================================================================
45 private DataRequestQueue reqState = UiCommonFactory.getQueue();
46 private String viewID = "";
47
48 // ========================================================================
49 // Constructor
50 // ========================================================================
51 public AbsTimeUpdateView(String viewID) {
52 this.viewID = viewID;
53 }
54
55 // ========================================================================
56 // Methods
57 // ========================================================================
58 /*
59 * (non-Javadoc)
60 *
61 * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener#
62 * processingStarted(org.eclipse.linuxtools.lttng.state.StateDataRequest)
63 */
64 @TmfSignalHandler
65 public synchronized void processingStarted(RequestStartedSignal signal) {
66 StateDataRequest request = signal.getRequest();
67 if (request != null) {
68 // update queue with the id of the current request.
69 reqState.requestStarted(request);
70 // if there was no new request then this one is still on
71 // prepare for the reception of new data
72
73 waitCursor(true);
74
75 StateManager smanager = request.getStateManager();
76 // Clear the children on the Processes related to this
77 // manager.
78 // Leave the GUI in charge of the updated data.
79 String traceId = smanager.getEventLog().getName();
80
81 // indicate if the data model needs to be cleared e.g. a new
82 // experiment is being selected
83 boolean clearData = request.isclearDataInd();
84 // no new time range for zoom orders
85 TmfTimeRange trange = null;
86 if (clearData) {
87 // Time Range will be used to filter out events which are
88 // not visible in one pixel
89 trange = StateManagerFactory.getExperimentManager()
90 .getExperimentTimeRange();
91 }
92
93 // Indicate if current data needs to be cleared and if so
94 // specify the new experiment time range that applies
95 ModelUpdatePrep(traceId, clearData, trange);
96 }
97 }
98
99 /*
100 * (non-Javadoc)
101 *
102 * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener#
103 * processingCompleted(org.eclipse.linuxtools.lttng.state.StateDataRequest)
104 */
105 @TmfSignalHandler
106 public synchronized void processingCompleted(RequestCompletedSignal signal) {
107 StateDataRequest request = signal.getRequest();
108
109 if (request == null) {
110 return;
111 } else {
112 reqState.requestCompleted(request);
113
114 }
115
116 // Update wait cursor
117 requestStateUpdate();
118 // No data refresh actions for cancelled requests.
119 if (request.isCancelled() || request.isFailed()) {
120 if (TraceDebug.isDEBUG()) {
121 TmfTimeRange trange = request.getRange();
122 if (request.isCancelled()) {
123 TraceDebug.debug("Request cancelled "
124 + trange.getStartTime() + "-" + trange.getEndTime()
125 + " Handled Events: " + request.getNumOfEvents());
126 } else if (request.isFailed()) {
127 TraceDebug.debug("Request Failed " + trange.getStartTime()
128 + "-" + trange.getEndTime() + " Handled Events: "
129 + request.getNumOfEvents());
130 }
131 }
132
133 return;
134 } else {
135 ModelUpdateComplete(request);
136 }
137 }
138
139 /**
140 * Evaluates the need to either send a new data request or queue the request
141 * till next available opportunity. One element queue to keep the latest
142 * request only.
143 *
144 * @param trange
145 */
146 public synchronized void dataRequest(TmfTimeRange trange) {
147 boolean sent = reqState.processDataRequest(trange, viewID, this);
148
149 if (sent) {
150 waitCursor(true);
151 }
152 }
153
154 /**
155 * Disable the wait cursor if the state is back to idle
156 */
157 private synchronized void requestStateUpdate() {
158 // disable the wait cursor if the state is back to idle
159 if (reqState.isIdle()) {
160 // no more in the queue
161 waitCursor(false);
162 }
163 }
164
165 /**
166 * Request the Time Analysis widget to enable or disable the wait cursor
167 * e.g. data request in progress or data request completed
168 *
169 * @param waitInd
170 */
171 protected abstract void waitCursor(boolean waitInd);
172
173 /**
174 * View preparation to override the current local information related to the
175 * given traceId
176 *
177 * @param traceId
178 * @param clearAllData
179 * - reset all data e.g when a new experiment is selected
180 * @param timeRange
181 * - new total time range e.g. Experiment level
182 */
183 public abstract void ModelUpdatePrep(String traceId, boolean clearAllData,
184 TmfTimeRange timeRange);
185
186 /**
187 * Actions taken by the view to refresh its widget(s) with the updated data
188 * model
189 *
190 * @param request
191 */
192 public abstract void ModelUpdateComplete(StateDataRequest request);
193 }
This page took 0.036118 seconds and 4 git commands to generate.