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