From: lempinen Date: Mon, 14 Jun 2010 07:23:17 +0000 (+0000) Subject: Active experiment highlight in model browser using experiment activation tag in virtu... X-Git-Tag: simantics-1.2.0~220 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4f8d9a9f9d9f829d24d10ba0673fd4081332344a;p=simantics%2Fsysdyn.git Active experiment highlight in model browser using experiment activation tag in virtual graph git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16146 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java index f0e0361c..d53b1a8b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java @@ -7,23 +7,14 @@ import org.simantics.browsing.ui.content.LabelDecorator; import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; -import org.simantics.simulation.experiment.IExperiment; -import org.simantics.simulation.project.IExperimentManager; -import org.simantics.sysdyn.manager.SysdynExperiment; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode; -import org.simantics.ui.SimanticsUI; public class ExperimentLabelDecorator extends LabelDecoratorContributor { @Override public LabelDecorator getDecorator(ReadGraph graph, ExperimentNode experimentNode) throws DatabaseException { - IExperimentManager manager = - SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); - IExperiment exp = manager.getActiveExperiment(); - if(exp instanceof SysdynExperiment) { - SysdynExperiment experiment = (SysdynExperiment) exp; - if(experiment.getResource().equals(experimentNode.resource)) + if ( graph.hasStatement(experimentNode.resource, graph.getBuiltins().IsActive)) { return new LabelDecorator.Stub() { @Override public String decorateLabel(String label, String column, int itemIndex) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java index a4ec1791..ca75766a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java @@ -12,11 +12,13 @@ import org.simantics.db.Builtins; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.service.VirtualGraphSupport; import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.simulation.experiment.Experiment; import org.simantics.simulation.experiment.ExperimentState; @@ -171,6 +173,8 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { result.setResult(sysdynModel.getSimulationResult()); } }); + + toggleActivation(graph, true); } }); @@ -182,18 +186,43 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { ExperimentState state = getState(); switch(state) { case DISPOSED: + System.out.println("disposed"); session.asyncRequest(new ReadRequest() { @Override public void run(ReadGraph graph) throws DatabaseException { sysdynModel.removeModificationListener(modificationListener); modificationListener = null; - + toggleActivation(graph, false); } }); break; } } + + private void toggleActivation(ReadGraph graph, final boolean activate) { + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + final Session session = graph.getSession(); + session.asyncRequest(new WriteRequest(support.get("experiments")) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VirtualGraph runtime = graph.getService(VirtualGraph.class); + + session.asyncRequest(new WriteRequest(runtime) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Builtins b = graph.getBuiltins(); + if(activate) + graph.claim(experiment, b.IsActive, experiment); + else + graph.deny(experiment, b.IsActive, experiment); + } + + }); + } + }); + } public static class Sample { public double value;