]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Active experiment highlight in model browser using experiment activation tag in virtu...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 14 Jun 2010 07:23:17 +0000 (07:23 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 14 Jun 2010 07:23:17 +0000 (07:23 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16146 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java

index f0e0361cc04ecd2f28b35c2ca825d11096f338aa..d53b1a8bc2280bdbf8f06e411f9b7451999531d1 100644 (file)
@@ -7,23 +7,14 @@ import org.simantics.browsing.ui.content.LabelDecorator;
 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
index a4ec1791b8b19ab6f8215b1dc938f4a0196b0c72..ca75766aac30b0609306f79ceb055487d7829efb 100644 (file)
@@ -12,11 +12,13 @@ import org.simantics.db.Builtins;
 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
@@ -171,6 +173,8 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                         result.setResult(sysdynModel.getSimulationResult());\r
                     }\r
                 });\r
+                \r
+                toggleActivation(graph, true);\r
             }\r
         });\r
         \r
@@ -182,18 +186,43 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
         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