]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java
Multiple readers and variable optimization
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / Functions.java
index d9d8857af77210acfa2be0f1d170981f547ca2a5..19c2e8c800d2562a5fbfdfa519ad33d37157edd7 100644 (file)
@@ -67,13 +67,10 @@ import org.simantics.structural2.queries.PossibleConnectionPointInfo;
 import org.simantics.structural2.scl.CompileStructuralValueRequest;
 import org.simantics.structural2.scl.procedural.CompileProceduralComponentTypeRequest;
 import org.simantics.structural2.variables.Connection;
-import org.simantics.structural2.variables.ConnectionBrowser;
 import org.simantics.structural2.variables.StandardProceduralChildVariable;
-import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
 import org.simantics.utils.datastructures.MapList;
 
 import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
 
 public class Functions {
        
@@ -153,39 +150,6 @@ public class Functions {
                
        };
        
-       static class ConnectionImpl implements Connection {
-
-               final private StandardGraphPropertyVariable connectionPoint;
-               
-               public ConnectionImpl(StandardGraphPropertyVariable connectionPoint) {
-                       this.connectionPoint = connectionPoint;
-               }
-               
-               @Override
-               public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-                   Set<Variable> result = new THashSet<Variable>();
-                   for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, connectionPoint.parent, connectionPoint.property.predicate, relationType)) {
-                       result.add(desc.getVariable(graph));
-                   }
-                   return result;
-               }
-               
-               @Override
-               public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-                   Set<String> result = new THashSet<String>();
-                   for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, connectionPoint.parent, connectionPoint.property.predicate, relationType)) {
-                       result.add(desc.getURI(graph));
-                   }
-                   return result;
-               }
-
-               @Override
-               public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
-                   return ConnectionBrowser.flatten(graph, connectionPoint.parent, connectionPoint.property.predicate, relationType);
-               }
-
-       }
-       
        @SCLValue(type="ValueAccessor")
        public static final ValueAccessor connectionValueAccessor = new ValueAccessor() {
 
@@ -213,7 +177,7 @@ public class Functions {
                @Override
                public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
                        StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context; 
-                       return new ConnectionImpl(variable);
+                       return new ConnectionImpl(variable.property.predicate);
                }
 
                @Override
@@ -233,10 +197,10 @@ public class Functions {
        
                public Variable getPossibleConnectionPointFromContext(ReadGraph graph, Variable variable, Resource context, String name) throws DatabaseException {
 
-                       Map<String, Resource> connectionPoints = graph.syncRequest(new ConnectionPointMapOfResource(graph, context), TransientCacheAsyncListener.<Map<String,Resource>>instance());
-                       Resource cp = connectionPoints.get(name);
+                       Map<String, PropertyInfo> connectionPoints = graph.syncRequest(new ConnectionPointMapOfResource(graph, context), TransientCacheAsyncListener.<Map<String,PropertyInfo>>instance());
+                       PropertyInfo cp = connectionPoints.get(name);
                        if(cp == null) return null;
-                       else return new StandardGraphPropertyVariable(graph, variable, cp);
+                       else return new StandardGraphPropertyVariable(graph, variable, cp.predicate);
                        
                }
                
@@ -244,16 +208,16 @@ public class Functions {
                        
                        if(graph.isImmutable(context)) {
 
-                               Map<String, Resource> cps = graph.syncRequest(new ConnectionPointMapOfResource(graph, context), TransientCacheAsyncListener.<Map<String,Resource>>instance());
+                               Map<String, PropertyInfo> cps = graph.syncRequest(new ConnectionPointMapOfResource(graph, context), TransientCacheAsyncListener.<Map<String,PropertyInfo>>instance());
                                if(cps.size() == 0) return map;
                                
                                if(map == null) map = new THashMap<String,Variable>(cps.size());
                                
-                               for(Map.Entry<String, Resource> entry : cps.entrySet()) {
+                               for(Map.Entry<String, PropertyInfo> entry : cps.entrySet()) {
                                        String name = entry.getKey();
-                                       Resource cp = entry.getValue();
-                                       if(needSynchronized && !graph.isInstanceOf(cp, STR.SynchronizedConnectionRelation)) continue;
-                                       map.put(name, new StandardGraphPropertyVariable(graph, variable, cp));
+                                       PropertyInfo cp = entry.getValue();
+                                       if(needSynchronized && !graph.isInstanceOf(cp.predicate, STR.SynchronizedConnectionRelation)) continue;
+                                       map.put(name, new StandardGraphPropertyVariable(graph, variable, cp.predicate));
                                }
                                
                                return map;
@@ -313,7 +277,7 @@ public class Functions {
                
        };
 
-       static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+       public static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {
 
                public StructuralChildMapOfResource(Resource resource) {
                        super(resource);
@@ -337,7 +301,7 @@ public class Functions {
 
        }
 
-    static class StructuralChildMapOfResourceT extends ResourceRead<Map<String, Resource>> {
+    public static class StructuralChildMapOfResourceT extends ResourceRead<Map<String, Resource>> {
 
         public StructuralChildMapOfResourceT(Resource resource) {
             super(resource);