ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / Uml2SDTestFacility.java
index 2821a55dca52aebb306908f176d56ed489be2351..94020d9dcd62f3e9c9ba059f8dc428c748c1387b 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
- * 
+ * Copyright (c) 2011, 2013 Ericsson
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
  *******************************************************************************/
@@ -21,12 +21,16 @@ import java.util.List;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 import org.eclipse.linuxtools.tmf.ui.tests.uml2sd.trace.TmfUml2SDTestTrace;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
@@ -44,6 +48,8 @@ import org.osgi.framework.FrameworkUtil;
 /**
  *  Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
  *  utility methods for interacting with the loader/view.
+ *
+ *  @author Bernd Hufmann
  */
 public class Uml2SDTestFacility {
 
@@ -56,9 +62,9 @@ public class Uml2SDTestFacility {
     private SDView fSdView;
     private TmfTraceStub fTrace = null;
     private TmfUml2SDTestTrace    fParser = null;
-    private TmfExperiment<TmfEvent> fExperiment = null;
+    private TmfExperiment fExperiment = null;
 
-    private boolean fIsInitialized = false;
+    private volatile boolean fIsInitialized = false;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -69,6 +75,9 @@ public class Uml2SDTestFacility {
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
+    /**
+     * @return the singleton instance.
+     */
     public synchronized static Uml2SDTestFacility getInstance() {
         if (fInstance == null) {
             fInstance = new Uml2SDTestFacility();
@@ -94,7 +103,7 @@ public class Uml2SDTestFacility {
                 view = PlatformUI.getWorkbench()
                         .getActiveWorkbenchWindow()
                         .getActivePage()
-                        .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
+                        .findView("org.eclipse.ui.internal.introview");
 
                 if (view != null) {
                     PlatformUI.getWorkbench()
@@ -105,7 +114,7 @@ public class Uml2SDTestFacility {
                 view = PlatformUI.getWorkbench()
                         .getActiveWorkbenchWindow()
                         .getActivePage()
-                        .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
+                        .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView");
 
             } catch (final PartInitException e) {
                 throw new RuntimeException(e);
@@ -113,7 +122,7 @@ public class Uml2SDTestFacility {
 
             fSdView = (SDView) view;
             fLoader = (TmfUml2SDSyncLoader)LoadersManager.getInstance().createLoader(
-                    "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView); //$NON-NLS-1$
+                    "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView);
 
             delay(3000);
             fIsInitialized = true;
@@ -121,13 +130,13 @@ public class Uml2SDTestFacility {
     }
 
 
-    private TmfTraceStub setupTrace(final ITmfEventParser<TmfEvent> parser) {
+    private TmfTraceStub setupTrace(final ITmfEventParser parser) {
 
         try {
             // Create test trace object
-            final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
+            final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null);
             final File test = new File(FileLocator.toFileURL(location).toURI());
-            return new TmfTraceStub(test.getPath(), 500, true, parser, null);
+            return new TmfTraceStub(test.getPath(), 500, true, parser);
         } catch (final TmfTraceException e) {
             e.printStackTrace();
             throw new RuntimeException(e);
@@ -145,7 +154,14 @@ public class Uml2SDTestFacility {
      */
     public void dispose() {
         if (fIsInitialized) {
-            fExperiment.dispose();
+            ITmfTrace trace = fTrace;
+            TmfExperiment experiment = fExperiment;
+            if (trace == null || experiment == null) {
+                throw new IllegalStateException();
+            }
+
+            trace.broadcast(new TmfTraceClosedSignal(this, experiment));
+            experiment.dispose();
 
             // Wait for all Eclipse jobs to finish
             waitForJobs();
@@ -157,7 +173,7 @@ public class Uml2SDTestFacility {
 
     /**
      * Sleeps current thread or GUI thread for a given time.
-     * @param waitTimeMillis
+     * @param waitTimeMillis time in milliseconds to wait
      */
     public void delay(final long waitTimeMillis) {
         final Display display = Display.getCurrent();
@@ -165,7 +181,13 @@ public class Uml2SDTestFacility {
             final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
             while(System.currentTimeMillis() < endTimeMillis) {
                 if (!display.readAndDispatch()) {
-                    display.sleep();
+                    // We do not use Display.sleep because it might never wake up
+                    // if there is no user interaction
+                    try {
+                        Thread.sleep(Math.min(waitTimeMillis, 10));
+                    } catch (final InterruptedException e) {
+                        // Ignored
+                    }
                 }
                 display.update();
             }
@@ -218,7 +240,7 @@ public class Uml2SDTestFacility {
     /**
      * @return current experiment.
      */
-    public TmfExperiment<TmfEvent> getExperiment() {
+    public TmfExperiment getExperiment() {
         return fExperiment;
     }
 
@@ -268,7 +290,7 @@ public class Uml2SDTestFacility {
     }
 
     /**
-     * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
+     * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader.Uml2SDTestFacility#selectExperiment(boolean)
      */
     public void selectExperiment() {
         this.selectExperiment(true);
@@ -278,18 +300,21 @@ public class Uml2SDTestFacility {
      * Selects the experiment.
      * @param wait true to wait for indexing to finish else false
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
     public void selectExperiment(final boolean wait) {
         fParser = new TmfUml2SDTestTrace();
         fTrace = setupTrace(fParser);
         fParser.setTrace(fTrace);
 
-//        fTrace = setupTrace(fParser);
-
         final ITmfTrace traces[] = new ITmfTrace[1];
         traces[0] = fTrace;
-        fExperiment = new TmfExperiment<TmfEvent>(TmfEvent.class, "TestExperiment", traces); //$NON-NLS-1$
-        fTrace.broadcast(new TmfExperimentSelectedSignal<TmfEvent>(this, fExperiment));
+        fExperiment = new TmfExperiment(ITmfEvent.class, "TestExperiment", traces) {
+            @Override
+            protected ITmfTraceIndexer createIndexer(int interval) {
+                return new TmfCheckpointIndexer(this, interval);
+            }
+        };
+        fTrace.broadcast(new TmfTraceOpenedSignal(this, fExperiment, null));
+        fTrace.broadcast(new TmfTraceSelectedSignal(this, fExperiment));
         if (wait) {
             while (fExperiment.getNbEvents() == 0) {
                 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
@@ -303,7 +328,13 @@ public class Uml2SDTestFacility {
      * Disposes the experiment.
      */
     public void disposeExperiment() {
-        fExperiment.dispose();
+        ITmfTrace trace = fTrace;
+        TmfExperiment experiment = fExperiment;
+        if (trace == null || experiment == null) {
+            throw new IllegalStateException();
+        }
+        trace.broadcast(new TmfTraceClosedSignal(this, experiment));
+        experiment.dispose();
         delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
     }
 
@@ -312,7 +343,7 @@ public class Uml2SDTestFacility {
      */
     public void createFilterCriteria() {
         // Create Filter Criteria and save tme
-        final List<FilterCriteria> filterToSave = new ArrayList<FilterCriteria>();
+        final List<FilterCriteria> filterToSave = new ArrayList<>();
         Criteria criteria = new Criteria();
         criteria.setLifeLineSelected(true);
         criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
@@ -320,7 +351,7 @@ public class Uml2SDTestFacility {
 
         criteria = new Criteria();
         criteria.setSyncMessageSelected(true);
-        criteria.setExpression("BALL_.*"); //$NON-NLS-1$
+        criteria.setExpression("BALL_.*");
         filterToSave.add(new FilterCriteria(criteria, true, false));
         FilterListDialog.saveFiltersCriteria(filterToSave);
     }
This page took 0.02909 seconds and 5 git commands to generate.