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