]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java
Merge "Refactoring of simulator toolkit"
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / ConnectionBrowser.java
index 7f43f59d171bb0177c855d869026457a256cffa6..b2b92039f87f4f35870c31ed0564c624a89cec75 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.request.TransientUnaryRead;
 import org.simantics.db.common.utils.CommonDBUtils;
 import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.common.utils.NearestOwnerFinder;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.layer0.exception.MissingVariableException;
@@ -81,7 +82,7 @@ public class ConnectionBrowser {
                  Resource relation = graph.getInverse(stat.getPredicate());
                  //System.out.println(NameUtils.getSafeName(graph, component) + "." + NameUtils.getSafeName(graph, relation));
                  Resource boundConnection = graph.getPossibleObject(relation, STR.IsBoundBy);
-                 Resource type = StructuralUtils.getComponentType(graph, configuration, component);
+                 Resource type = StructuralUtils.getPossibleComponentType(graph, configuration, component);
                  Resource def = type != null ? graph.getPossibleObject(type, STR.IsDefinedBy) : null;
                  if(boundConnection != null && def != null) {
                      // The connection point is bound in component type
@@ -276,7 +277,7 @@ public class ConnectionBrowser {
                for (Resource composite : graph.getObjects(join, STR.JoinsComposite))
                        ancestorGenerators.add(composite);
             }
-            Resource ancestor = ancestorGenerators.size() == 1 ? ancestorGenerators.iterator().next() : CommonDBUtils.getNearestOwner(graph, ancestorGenerators);
+            Resource ancestor = ancestorGenerators.size() == 1 ? ancestorGenerators.iterator().next() : NearestOwnerFinder.getNearestOwnerFromDirectOwners(graph, ancestorGenerators);
             
             List<Resource> result = colls.createList();
             result.add(ancestor);
@@ -456,9 +457,19 @@ public class ConnectionBrowser {
                        String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
                        Variable possibleChild = parameter.getPossibleChild(graph, componentName);
                        if(possibleChild != null) {
-                               result.add(new ActualConnectionDescriptor(parameter, component, possibleChild.getType(graph), connectionPoint));
+                           Resource type = possibleChild.getPossibleType(graph, STR.Component);
+                           if(type != null) {
+                            result.add(new ActualConnectionDescriptor(parameter, component, possibleChild.getType(graph), connectionPoint));
+                           } else {
+                            throw new DatabaseException("Child does not have a structural type: " + possibleChild.getURI(graph));
+                           }
                        } else {
-                               throw new DatabaseException("No child with name " + componentName + " could be resolved for variable " + parameter.getURI(graph));
+                           Resource type = graph.getPossibleType(component, STR.Component);
+                           if(type != null) {
+                            result.add(new ActualConnectionDescriptor(parameter, component, type, connectionPoint));
+                           } else {
+                            throw new DatabaseException("Child with name " + componentName + " does not have a structural type: " + parameter.getURI(graph));
+                           }
                        }
                }
             }