]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java
foobaz
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / Functions.java
index f429fdc91d104fabcaf53d6fd6c5752bdb1699ad..96b1c882098c7ea8dc7a622ac370bfd26402809a 100644 (file)
@@ -180,7 +180,7 @@ public class Functions {
                @Override
                public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
                        StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context; 
-                       return new ConnectionImpl2(context.getParent(graph), variable.property.predicate);
+                       return new ConnectionImpl(context.getParent(graph), variable.property.predicate);
                }
 
                @Override
@@ -308,6 +308,82 @@ public class Functions {
                
        }
        
+    public static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+
+        public StructuralChildMapOfResource(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
+            StructuralResource2 STR = StructuralResource2.getInstance(graph);
+            Resource type = graph.getPossibleType(resource, STR.Component);
+            if(type != null) {
+                Resource definition = graph.getPossibleObject(type, STR.IsDefinedBy);
+                if(definition != null) {
+                    Map<String, Resource> map = graph.syncRequest(new UnescapedChildMapOfResource(definition));
+                    if (!map.isEmpty())
+                        return map;
+                } 
+            }
+            Map<String, Resource> directChildren = graph.syncRequest(new UnescapedChildMapOfResource(resource));
+            return directChildren;
+        }
+
+    }
+
+    public static class StructuralChildMapOfResourceT extends ResourceRead<Map<String, Resource>> {
+
+        public StructuralChildMapOfResourceT(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
+            StructuralResource2 STR = StructuralResource2.getInstance(graph);
+            Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy);
+            if(definition != null) {
+                Map<String, Resource> map = graph.syncRequest(new UnescapedChildMapOfResource(definition));
+                if (!map.isEmpty())
+                    return map;
+            } 
+            return Collections.emptyMap();
+        }
+
+    }
+
+    static class StructuralRunChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+
+        public StructuralRunChildMapOfResource(Resource resource) {
+            super(resource);
+        }
+
+        public Map<String, Resource> fromContext(ReadGraph graph, Resource context) throws DatabaseException {
+            return graph.sync(new StructuralChildMapOfResource(context));
+        }
+        
+        @Override
+        public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
+
+            Layer0 L0 = Layer0.getInstance(graph);
+            SimulationResource SIMU = SimulationResource.getInstance(graph);
+            Resource model = graph.sync(new PossibleIndexRoot(resource));
+            if(graph.isInstanceOf(model, L0.RVIContext)) {
+                return fromContext(graph, model);
+            }
+            Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);
+            if(configuration != null) {
+                if(graph.isInstanceOf(configuration, L0.RVIContext)) {
+                    return fromContext(graph, configuration);
+                }
+            }
+            
+            return Collections.emptyMap();
+            
+        }
+        
+    }
+
        private static class SubstructureRequest extends VariableRead<List<SubstructureElement>> {
            public SubstructureRequest(Variable context) {
             super(context);