]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ActualConnectionDescriptor.java
Replaceable Defined Component Types
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / ActualConnectionDescriptor.java
index e0b93837ee9765deac16ba1ba2ce4dc1af5e6198..716d4a0017014e3cb727a4d1b26c587f71411680 100644 (file)
@@ -14,50 +14,93 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;
 import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.DefinedUCInterfaceMap;
 import org.simantics.structural2.Functions;
 import org.simantics.structural2.Functions.InterfaceResolution;
+import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
 import org.simantics.structural2.variables.ConnectionBrowser.IsLeafType;
 
 /*
- * This connection descriptor variable 
+ * This connection descriptor
+ * 
  * -has not been lifted into interface
  * -has a structural configuration defined as resources
- * -has not been drilled
+ * -might not be drilled
+ * 
+ * Note: these are constructed after climb (before drill) phase of the connection browser. This means that
+ * the component can still contain sub structure during connection browsing. This means that some descriptors
+ * are not final and are replaced by correct descriptors during drill phase.
+ * 
  */
 class ActualConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {
        
-       final private Variable root;
-       final private Resource component;
-       final private Resource cp;
+       /*
+        * This is the nearest known ancestor variable
+        */
+       final Variable root;
+       /*
+        * A component on variable path under the root variable.
+        */
+       final Resource component;
+       /*
+        * TODO
+        */
+       final Resource componentType;
+       /*
+        * The connection point that has type of the component as its domain
+        */
+       final Resource cp;
        
-       public ActualConnectionDescriptor(Variable root, Resource component, Resource cp) {
+       public ActualConnectionDescriptor(Variable root, Resource component, Resource componentType, Resource cp) {
                this.root = root;
                this.component = component;
+               this.componentType = componentType;
                this.cp = cp;
        }
        
-       static class ComputeInterfaceDescription extends UnaryRead<ActualConnectionDescriptor, Collection<InterfaceResolution>> {
+       static class ActualConnectionDescriptorInterfaceDescription extends UnaryRead<ActualConnectionDescriptor, Collection<InterfaceResolution>> {
 
-               public ComputeInterfaceDescription(ActualConnectionDescriptor desc) {
+               public ActualConnectionDescriptorInterfaceDescription(ActualConnectionDescriptor desc) {
                        super(desc);
                }
 
                @Override
                public Collection<InterfaceResolution> perform(ReadGraph graph) throws DatabaseException {
                        
-               StructuralResource2 STR = StructuralResource2.getInstance(graph);
-               Resource type = graph.getPossibleType(parameter.component, STR.Component);
-               if(graph.syncRequest(new IsLeafType(type))) return null;
-
-                       return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));
+//                     ConnectionBrowser.reportDescriptor(graph, parameter);
+               
+               /*
+                * The componentType is the possibly replaced (STR.ReplaceableDefinedComponentType) type
+                */
+               StructuralComponentClass clazz = StructuralComponentClass.get(graph, parameter.componentType);
+               if(StructuralComponentClass.PRIMITIVE.equals(clazz)) {
+                       return null;
+               } else if(StructuralComponentClass.DEFINED.equals(clazz)) {
+                       final Collection<InterfaceResolution> interfaces = graph.syncRequest(new DefinedUCInterfaceMap(parameter.componentType));
+                       if(interfaces != null) return interfaces;
+                       else return Functions.BUILTIN_STRUCTURAL_CPS;
+               } else if(StructuralComponentClass.REPLACEABLE.equals(clazz)) {
+                       throw new DatabaseException("ConnectionBrowser does not support nested replaceable defined structural types.");
+               } else {
+                       return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));   
+               }
                        
                }
                
        }
        
+       @Override
+       public boolean isLeaf(ReadGraph graph) throws DatabaseException {
+               
+               StructuralResource2 STR = StructuralResource2.getInstance(graph);
+               Resource type = graph.getPossibleType(component, STR.Component);
+               return graph.syncRequest(new IsLeafType(type));
+               
+       }
+       
        @Override
        public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException {
-               return graph.syncRequest(new ComputeInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());
+               return graph.syncRequest(new ActualConnectionDescriptorInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());
        }
        
        public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {