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