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