ctf: Fix remaining warnings the CTF plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / Uml2SDTestFacility.java
CommitLineData
73005152 1/*******************************************************************************
df0b8ff4 2 * Copyright (c) 2011, 2012 Ericsson
73005152
BH
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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
df0b8ff4 12package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
73005152
BH
13
14import java.io.File;
15import java.io.IOException;
16import java.net.URISyntaxException;
17import java.net.URL;
18import java.util.ArrayList;
19import java.util.List;
20
21import org.eclipse.core.runtime.FileLocator;
22import org.eclipse.core.runtime.Path;
23import org.eclipse.core.runtime.jobs.Job;
6c13869b 24import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
b4f71e4a 25import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
6c13869b 26import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
7e6347b0 27import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
6c13869b 28import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
9e0640dc 29import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
4918b8f2 30import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
73005152
BH
31import org.eclipse.linuxtools.tmf.ui.tests.uml2sd.trace.TmfUml2SDTestTrace;
32import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
df0b8ff4
BH
33import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria;
34import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
35import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterListDialog;
73005152 36import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.LoadersManager;
df0b8ff4 37import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader;
73005152
BH
38import org.eclipse.swt.widgets.Display;
39import org.eclipse.ui.IViewPart;
40import org.eclipse.ui.PartInitException;
41import org.eclipse.ui.PlatformUI;
9269df72 42import org.osgi.framework.FrameworkUtil;
73005152
BH
43
44/**
45 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
20658947 46 * utility methods for interacting with the loader/view.
73005152
BH
47 */
48public class Uml2SDTestFacility {
20658947 49
73005152
BH
50 // ------------------------------------------------------------------------
51 // Attributes
52 // ------------------------------------------------------------------------
53 private static Uml2SDTestFacility fInstance = null;
20658947 54
73005152
BH
55 private TmfUml2SDSyncLoader fLoader;
56 private SDView fSdView;
57 private TmfTraceStub fTrace = null;
58 private TmfUml2SDTestTrace fParser = null;
59 private TmfExperiment<TmfEvent> fExperiment = null;
20658947 60
73005152 61 private boolean fIsInitialized = false;
20658947 62
73005152
BH
63 // ------------------------------------------------------------------------
64 // Constructors
65 // ------------------------------------------------------------------------
66 private Uml2SDTestFacility() {
67 }
68
69 // ------------------------------------------------------------------------
70 // Operations
71 // ------------------------------------------------------------------------
1f2f091b 72 public synchronized static Uml2SDTestFacility getInstance() {
73005152
BH
73 if (fInstance == null) {
74 fInstance = new Uml2SDTestFacility();
3ef62bac 75 fInstance.init();
73005152
BH
76 }
77 return fInstance;
78 }
79
80 /**
81 * Initial the test facility.
73005152 82 */
4f5d9f9b 83 public void init() {
20658947 84
73005152 85 if (!fIsInitialized) {
73005152
BH
86
87 fParser = new TmfUml2SDTestTrace();
88 fTrace = setupTrace(fParser);
7e6347b0 89 fParser.setTrace(fTrace);
20658947 90
73005152
BH
91 IViewPart view;
92 try {
1e412478
BH
93 // Remove welcome view to avoid interference during test execution
94 view = PlatformUI.getWorkbench()
95 .getActiveWorkbenchWindow()
96 .getActivePage()
97 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
20658947 98
1e412478
BH
99 if (view != null) {
100 PlatformUI.getWorkbench()
101 .getActiveWorkbenchWindow()
20658947 102 .getActivePage().hideView(view);
1e412478 103 }
20658947 104
73005152 105 view = PlatformUI.getWorkbench()
20658947
FC
106 .getActiveWorkbenchWindow()
107 .getActivePage()
108 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
109
110 } catch (final PartInitException e) {
73005152
BH
111 throw new RuntimeException(e);
112 }
113
114 fSdView = (SDView) view;
115 fLoader = (TmfUml2SDSyncLoader)LoadersManager.getInstance().createLoader(
df0b8ff4 116 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView); //$NON-NLS-1$
73005152
BH
117
118 delay(3000);
119 fIsInitialized = true;
120 }
121 }
122
20658947
FC
123
124 private TmfTraceStub setupTrace(final ITmfEventParser<TmfEvent> parser) {
125
126 try {
127 // Create test trace object
128 final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
129 final File test = new File(FileLocator.toFileURL(location).toURI());
130 return new TmfTraceStub(test.getPath(), 500, true, parser, null);
b4f71e4a
FC
131 } catch (final TmfTraceException e) {
132 e.printStackTrace();
133 throw new RuntimeException(e);
20658947
FC
134 } catch (final URISyntaxException e) {
135 e.printStackTrace();
136 throw new RuntimeException(e);
137 } catch (final IOException e) {
138 e.printStackTrace();
139 throw new RuntimeException(e);
140 }
73005152 141 }
20658947 142
73005152
BH
143 /**
144 * Dispose the resource
145 */
146 public void dispose() {
4f5d9f9b 147 if (fIsInitialized) {
73005152
BH
148 fExperiment.dispose();
149
150 // Wait for all Eclipse jobs to finish
151 waitForJobs();
152
153 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView);
154 fIsInitialized = false;
155 }
156 }
20658947 157
73005152 158 /**
20658947 159 * Sleeps current thread or GUI thread for a given time.
73005152
BH
160 * @param waitTimeMillis
161 */
20658947
FC
162 public void delay(final long waitTimeMillis) {
163 final Display display = Display.getCurrent();
73005152 164 if (display != null) {
20658947 165 final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
73005152
BH
166 while(System.currentTimeMillis() < endTimeMillis) {
167 if (!display.readAndDispatch()) {
168 display.sleep();
169 }
170 display.update();
171 }
172 } else {
173 try {
174 Thread.sleep(waitTimeMillis);
20658947 175 } catch (final InterruptedException e) {
73005152
BH
176 // Ignored
177 }
178 }
179 }
180
181 /**
182 * Waits for all Eclipse jobs to finish
183 */
184 public void waitForJobs() {
185 while (!Job.getJobManager().isIdle()) {
186 delay(IUml2SDTestConstants.WAIT_FOR_JOBS_DELAY);
187 }
188 }
189
190 /**
191 * @return current UML2SD loader
192 */
193 public TmfUml2SDSyncLoader getLoader() {
194 return fLoader;
195 }
196
197 /**
198 * @return current SD view
199 */
200 public SDView getSdView() {
201 return fSdView;
202 }
203
204 /**
205 * @return current trace
206 */
207 public TmfTraceStub getTrace() {
208 return fTrace;
209 }
210
211 /**
212 * @return Trace parser
213 */
214 public TmfUml2SDTestTrace getParser() {
215 return fParser;
216 }
217
218 /**
219 * @return current experiment.
220 */
221 public TmfExperiment<TmfEvent> getExperiment() {
222 return fExperiment;
223 }
20658947 224
73005152
BH
225 /**
226 * Go to next page;
227 */
228 public void nextPage() {
229 fLoader.nextPage();
230 fLoader.waitForCompletion();
231 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
232 }
233
234 /**
235 * Go to previous page.
236 */
237 public void prevPage() {
238 fLoader.prevPage();
239 fLoader.waitForCompletion();
240 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
241 }
20658947 242
73005152
BH
243 /**
244 * Go to last page.
245 */
246 public void lastPage() {
247 fLoader.lastPage();
248 fLoader.waitForCompletion();
249 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
250 }
251
252 /**
253 * Go to first page.
254 */
255 public void firstPage() {
256 fLoader.firstPage();
257 fLoader.waitForCompletion();
258 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
259 }
20658947 260
73005152
BH
261 /**
262 * @param page number to set
263 */
20658947 264 public void setPage(final int page) {
abbdd66a 265 fLoader.pageNumberChanged(page);
73005152
BH
266 fLoader.waitForCompletion();
267 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
268 }
20658947 269
73005152
BH
270 /**
271 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
272 */
273 public void selectExperiment() {
274 this.selectExperiment(true);
275 }
20658947 276
73005152 277 /**
20658947 278 * Selects the experiment.
73005152
BH
279 * @param wait true to wait for indexing to finish else false
280 */
4f5d9f9b 281 @SuppressWarnings({ "rawtypes", "unchecked" })
20658947 282 public void selectExperiment(final boolean wait) {
7e6347b0 283 fParser = new TmfUml2SDTestTrace();
73005152 284 fTrace = setupTrace(fParser);
7e6347b0
FC
285 fParser.setTrace(fTrace);
286
287// fTrace = setupTrace(fParser);
73005152 288
20658947 289 final ITmfTrace traces[] = new ITmfTrace[1];
73005152
BH
290 traces[0] = fTrace;
291 fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, "TestExperiment", traces); //$NON-NLS-1$
292 fTrace.broadcast(new TmfExperimentSelectedSignal<TmfEvent>(this, fExperiment));
293 if (wait) {
2717e7ec
PT
294 while (fExperiment.getNbEvents() == 0) {
295 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
296 }
73005152
BH
297 waitForJobs();
298 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
299 }
300 }
20658947 301
73005152
BH
302 /**
303 * Disposes the experiment.
304 */
305 public void disposeExperiment() {
306 fExperiment.dispose();
307 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
308 }
20658947 309
73005152 310 /**
20658947 311 * Creates some global filter criteria and saves them to disk.
73005152
BH
312 */
313 public void createFilterCriteria() {
314 // Create Filter Criteria and save tme
20658947 315 final List<FilterCriteria> filterToSave = new ArrayList<FilterCriteria>();
73005152
BH
316 Criteria criteria = new Criteria();
317 criteria.setLifeLineSelected(true);
318 criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
319 filterToSave.add(new FilterCriteria(criteria, true, false));
20658947 320
73005152
BH
321 criteria = new Criteria();
322 criteria.setSyncMessageSelected(true);
323 criteria.setExpression("BALL_.*"); //$NON-NLS-1$
324 filterToSave.add(new FilterCriteria(criteria, true, false));
325 FilterListDialog.saveFiltersCriteria(filterToSave);
326 }
327
328
329}
This page took 0.045867 seconds and 5 git commands to generate.