]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
HistoryRealization names stay up-to-date in experiments
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 28 Sep 2010 14:42:11 +0000 (14:42 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 28 Sep 2010 14:42:11 +0000 (14:42 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18113 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java

index d637d8a862ab0fe297ac55585a3cef610b589f91..d015a1c3e6eaf704cb5bbf618d26b5d8fda4748d 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.db.request.Read;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
 public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {\r
 \r
@@ -43,13 +44,11 @@ public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {
                     if(graph.isInstanceOf(config, SIMU.Experiment)) {\r
                         for(Resource run : graph.getObjects(config, l0.ConsistsOf)) {\r
                             if(graph.isInstanceOf(run, SIMU.Run)) {\r
-//                                                             System.out.println("found run " + run);\r
                                 result.add(run);\r
                             }\r
                         }\r
                     }\r
                 }\r
-//                             System.out.println("Compute runs ends");\r
                 return result;\r
             }\r
 \r
@@ -61,53 +60,48 @@ public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {
                final Layer0 l0 = Layer0.getInstance(graph);\r
                 final String experimentName = graph.getPossibleRelatedValue(run, l0.HasName, StringBindingDefault.INSTANCE);\r
 \r
-//                             System.out.println("RealizationVirtualGraph new experiment " + experimentName);\r
-\r
                 RuntimeValuations vs = graph.getService(RuntimeValuations.class);\r
                 if(vs.supports(experimentName)) {\r
 \r
-//                                     System.out.println("RealizationVirtualGraph scheduling " + experimentName);\r
-\r
-\r
-                    graph.asyncRequest(new Read<Collection<Resource>>() {\r
+                    graph.asyncRequest(new Read<Collection<Pair<String, Resource>>>() {\r
 \r
                         @Override\r
-                        public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
-                            HashSet<Resource> result = new HashSet<Resource>();\r
+                        public Collection<Pair<String, Resource>> perform(ReadGraph graph) throws DatabaseException {\r
+                            HashSet<Pair<String, Resource>> result = new HashSet<Pair<String, Resource>>();\r
                             Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
                             for(Resource part : graph.getObjects(configuration, l0.ConsistsOf)) {\r
-                                result.add(part);\r
+                                String partName = graph.getPossibleRelatedValue(part, l0.HasName, StringBindingDefault.INSTANCE);\r
+                                result.add(new Pair<String, Resource>(partName, part));\r
                             }\r
                             return result;\r
                         }\r
-                    }, new SingleSetSyncListener<Resource>() {\r
+                    }, new SingleSetSyncListener<Pair<String, Resource>>() {\r
 \r
                         @Override\r
-                        public void add(ReadGraph graph, final Resource part) throws DatabaseException {\r
+                        public void add(ReadGraph graph, final Pair<String, Resource> part) throws DatabaseException {\r
                             graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
                                 @Override\r
                                 public void perform(WriteGraph graph) throws DatabaseException {\r
                                     int runNode = context.getIndex(run);\r
-                                    String partName = graph.getPossibleRelatedValue(part, l0.HasName, StringBindingDefault.INSTANCE);\r
-                                    if(partName != null) {\r
+                                    if(part.first != null) {\r
                                         Resource partResource = graph.newResource();\r
                                         int partNode = context.getIndex(partResource);\r
                                         graph.claim(run, l0.ConsistsOf, null, partResource);\r
-                                        undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
+                                        undiscovered.put(partNode, new ResourceData(runNode, part.second, valuation, part.first, experimentName, null));\r
                                     }\r
                                 }\r
                             });\r
                         }\r
 \r
                         @Override\r
-                        public void remove(ReadGraph graph, final Resource part) throws DatabaseException {\r
-                            \r
+                        public void remove(ReadGraph graph, final Pair<String, Resource> part) throws DatabaseException {\r
                             graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
                                 @Override\r
                                 public void perform(WriteGraph graph) throws DatabaseException {\r
                                     Integer key = null;\r
                                     for(int k : undiscovered.keySet()) {\r
-                                        if (undiscovered.get(k).structureResource.equals(part)) {\r
+                                       ResourceData rd = undiscovered.get(k);\r
+                                        if (rd.name.equals(part.first) && rd.structureResource.equals(part.second)) {\r
                                             key = k;\r
                                             break;\r
                                         }\r
@@ -116,7 +110,6 @@ public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {
                                         Resource r = context.getResource(key);\r
                                         RemoverUtil.remove(graph, r);\r
                                         undiscovered.remove(key);\r
-                                        \r
                                     }\r
                                 }\r
                             });\r
@@ -128,31 +121,6 @@ public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {
                         }\r
 \r
                     });\r
-\r
-/*\r
-                    graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
-\r
-                        @Override\r
-                        public void perform(WriteGraph graph) throws DatabaseException {\r
-\r
-//                                                     System.out.println("RealizationVirtualGraph about to serve " + experimentName);\r
-\r
-                            int runNode = context.getIndex(run);\r
-\r
-                            Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
-                            for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
-                                String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
-                                if(partName != null) {\r
-                                    Resource partResource = graph.newResource();\r
-                                    int partNode = context.getIndex(partResource);\r
-                                    graph.claim(run, b.ConsistsOf, null, partResource);\r
-                                    undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
-                                }\r
-                            }\r
-\r
-                        }\r
-                    });\r
-*/\r
                     \r
                 }\r
 \r