1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.impl
;
15 import java
.io
.IOException
;
16 import java
.net
.URISyntaxException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.eclipse
.core
.runtime
.FileLocator
;
22 import org
.eclipse
.core
.runtime
.Path
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
26 import org
.eclipse
.linuxtools
.tmf
.parser
.ITmfEventParser
;
27 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.TmfUITestPlugin
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.trace
.TmfUml2SDTestTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.Criteria
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.FilterCriteria
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.FilterListDialog
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.impl
.TmfUml2SDSyncLoader
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
38 import org
.eclipse
.swt
.widgets
.Display
;
39 import org
.eclipse
.ui
.IViewPart
;
40 import org
.eclipse
.ui
.PartInitException
;
41 import org
.eclipse
.ui
.PlatformUI
;
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.
47 public class Uml2SDTestFacility
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
52 private static Uml2SDTestFacility fInstance
= null;
54 private TmfUml2SDSyncLoader fLoader
;
55 private SDView fSdView
;
56 private TmfTraceStub fTrace
= null;
57 private TmfUml2SDTestTrace fParser
= null;
58 private TmfExperiment
<TmfEvent
> fExperiment
= null;
60 private boolean fIsInitialized
= false;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
65 private Uml2SDTestFacility() {
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
71 public static Uml2SDTestFacility
getInstance() {
72 if (fInstance
== null) {
73 fInstance
= new Uml2SDTestFacility();
79 * Initial the test facility.
83 if (!fIsInitialized
) {
85 fParser
= new TmfUml2SDTestTrace();
86 fTrace
= setupTrace(fParser
);
90 view
= PlatformUI
.getWorkbench()
91 .getActiveWorkbenchWindow()
93 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
95 } catch (PartInitException e
) {
96 throw new RuntimeException(e
);
99 fSdView
= (SDView
) view
;
100 fLoader
= (TmfUml2SDSyncLoader
)LoadersManager
.getInstance().createLoader(
101 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfUml2SDSyncLoader", fSdView
); //$NON-NLS-1$
104 fIsInitialized
= true;
109 private TmfTraceStub
setupTrace(ITmfEventParser parser
) {
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
) {
118 throw new RuntimeException(e
);
119 } catch (IOException e
) {
121 throw new RuntimeException(e
);
126 * Dispose the resource
128 public void dispose() {
129 if (fIsInitialized
) {
130 fExperiment
.dispose();
132 // Wait for all Eclipse jobs to finish
135 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView
);
136 fIsInitialized
= false;
141 * Sleeps current thread or GUI thread for a given time.
142 * @param waitTimeMillis
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()) {
156 Thread
.sleep(waitTimeMillis
);
157 } catch (InterruptedException e
) {
164 * Waits for all Eclipse jobs to finish
166 public void waitForJobs() {
167 while (!Job
.getJobManager().isIdle()) {
168 delay(IUml2SDTestConstants
.WAIT_FOR_JOBS_DELAY
);
173 * @return current UML2SD loader
175 public TmfUml2SDSyncLoader
getLoader() {
180 * @return current SD view
182 public SDView
getSdView() {
187 * @return current trace
189 public TmfTraceStub
getTrace() {
194 * @return Trace parser
196 public TmfUml2SDTestTrace
getParser() {
201 * @return current experiment.
203 public TmfExperiment
<TmfEvent
> getExperiment() {
210 public void nextPage() {
212 fLoader
.waitForCompletion();
213 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
217 * Go to previous page.
219 public void prevPage() {
221 fLoader
.waitForCompletion();
222 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
228 public void lastPage() {
230 fLoader
.waitForCompletion();
231 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
237 public void firstPage() {
239 fLoader
.waitForCompletion();
240 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
244 * @param page number to set
246 public void setPage(int page
) {
247 fLoader
.pageNumberChanged(page
);;
248 fLoader
.waitForCompletion();
249 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
253 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
255 public void selectExperiment() {
256 this.selectExperiment(true);
260 * Selects the experiment.
261 * @param wait true to wait for indexing to finish else false
263 @SuppressWarnings({ "rawtypes", "unchecked" })
264 public void selectExperiment(boolean wait
) {
265 fTrace
= setupTrace(fParser
);
267 ITmfTrace traces
[] = new ITmfTrace
[1];
269 fExperiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, "TestExperiment", traces
); //$NON-NLS-1$
270 fTrace
.broadcast(new TmfExperimentSelectedSignal
<TmfEvent
>(this, fExperiment
));
273 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
278 * Disposes the experiment.
280 public void disposeExperiment() {
281 fExperiment
.dispose();
282 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
286 * Creates some global filter criteria and saves them to disk.
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));
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
);