From: Tuukka Lehtonen Date: Tue, 18 Sep 2018 20:45:22 +0000 (+0300) Subject: Added new ExperimentRuns.createRun utility X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F01%2F2201%2F1;p=simantics%2Fplatform.git Added new ExperimentRuns.createRun utility The new method was added because more control was needed on whether attachStateListener is invoked or not. gitlab #126 Change-Id: I7132cb1bd2bd734403382b2d35c169510c8ea433 (cherry picked from commit 7903eb7d1e0e004cfa05a8775fda95e556b5727b) --- diff --git a/bundles/org.simantics.simulation/src/org/simantics/simulation/project/ExperimentRuns.java b/bundles/org.simantics.simulation/src/org/simantics/simulation/project/ExperimentRuns.java index 21fcf2c26..5edf6c856 100644 --- a/bundles/org.simantics.simulation/src/org/simantics/simulation/project/ExperimentRuns.java +++ b/bundles/org.simantics.simulation/src/org/simantics/simulation/project/ExperimentRuns.java @@ -82,6 +82,37 @@ public class ExperimentRuns { final IExperimentActivationListener listener, final Function2 externalWrite, final Consumer 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 true 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 externalWrite, + Consumer successCallback, + boolean attachDeactivationListener) { final AtomicReference 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)