Added new ExperimentRuns.createRun utility
[simantics/platform.git] / 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)