import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.simulation.experiment.IExperiment;\r
-import org.simantics.simulation.project.IExperimentManager;\r
-import org.simantics.sysdyn.manager.SysdynExperiment;\r
import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
-import org.simantics.ui.SimanticsUI;\r
\r
public class ExperimentLabelDecorator extends LabelDecoratorContributor<ExperimentNode> {\r
\r
@Override\r
public LabelDecorator getDecorator(ReadGraph graph, ExperimentNode experimentNode) throws DatabaseException {\r
- IExperimentManager manager = \r
- SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
- IExperiment exp = manager.getActiveExperiment();\r
- if(exp instanceof SysdynExperiment) {\r
- SysdynExperiment experiment = (SysdynExperiment) exp;\r
- if(experiment.getResource().equals(experimentNode.resource))\r
+ if ( graph.hasStatement(experimentNode.resource, graph.getBuiltins().IsActive)) {\r
return new LabelDecorator.Stub() {\r
@Override\r
public String decorateLabel(String label, String column, int itemIndex) {\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.service.LifecycleSupport;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.simulation.experiment.Experiment;\r
import org.simantics.simulation.experiment.ExperimentState;\r
result.setResult(sysdynModel.getSimulationResult());\r
}\r
});\r
+ \r
+ toggleActivation(graph, true);\r
}\r
});\r
\r
ExperimentState state = getState();\r
switch(state) {\r
case DISPOSED:\r
+ System.out.println("disposed");\r
session.asyncRequest(new ReadRequest() {\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
sysdynModel.removeModificationListener(modificationListener);\r
modificationListener = null;\r
-\r
+ toggleActivation(graph, false);\r
}\r
});\r
break;\r
}\r
}\r
+ \r
+ private void toggleActivation(ReadGraph graph, final boolean activate) {\r
+ VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
+ final Session session = graph.getSession();\r
+ session.asyncRequest(new WriteRequest(support.get("experiments")) {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ VirtualGraph runtime = graph.getService(VirtualGraph.class);\r
+\r
+ session.asyncRequest(new WriteRequest(runtime) {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ if(activate) \r
+ graph.claim(experiment, b.IsActive, experiment);\r
+ else\r
+ graph.deny(experiment, b.IsActive, experiment);\r
+ }\r
+\r
+ });\r
+ }\r
+ });\r
+ }\r
\r
public static class Sample {\r
public double value;\r