]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added new ExperimentRuns.createRun utility 99/2199/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 18 Sep 2018 20:45:22 +0000 (23:45 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 18 Sep 2018 20:45:22 +0000 (23:45 +0300)
The new method was added because more control was needed on whether
attachStateListener is invoked or not.

gitlab #126

Change-Id: I7132cb1bd2bd734403382b2d35c169510c8ea433

bundles/org.simantics.simulation/src/org/simantics/simulation/project/ExperimentRuns.java

index 21fcf2c268847704ad00375f60dcbe525dca309b..5edf6c856ca80a020e394afeab4ba53e0e883fb6 100644 (file)
@@ -82,6 +82,37 @@ public class ExperimentRuns {
             final IExperimentActivationListener listener,
             final Function2<WriteGraph, Resource, Object> externalWrite,
             final Consumer<Resource> successCallback)
+    {
+        createRun(session, vg,
+                experimentResource, experiment, experimentRunTypeURI,
+                listener, externalWrite, successCallback, true);
+    }
+
+    /**
+     * Create new experiment run in a selected virtual graph.
+     * 
+     * @param session
+     * @param vg
+     * @param experimentResource
+     * @param experiment
+     * @param experimentRunTypeURI
+     * @param listener
+     * @param successCallback if non-null invoked with the created run resource
+     *        as an argument, just before invoking
+     *        listener.onExperimentActivated(experiment)
+     * @param attachDeactivationListener <code>true</code> to run for the created run-resource
+     *        {@link #attachStateListener(Session, IExperiment, Resource)}
+     */
+    public static void createRun(
+            Session session,
+            VirtualGraph vg,
+            Resource experimentResource,
+            IExperiment experiment,
+            String experimentRunTypeURI,
+            IExperimentActivationListener listener,
+            Function2<WriteGraph, Resource, Object> externalWrite,
+            Consumer<Resource> successCallback,
+            boolean attachDeactivationListener)
     {
         final AtomicReference<Resource> run = new AtomicReference<>();
         session.asyncRequest(new WriteRequest(vg) {
@@ -97,7 +128,8 @@ public class ExperimentRuns {
                 else
                     ErrorLogger.defaultLogError(e);
             } else {
-                attachStateListener(session, experiment, run.get());
+                if (attachDeactivationListener)
+                    attachStateListener(session, experiment, run.get());
                 if (successCallback != null)
                     successCallback.accept(run.get());
                 if (listener != null)