X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fvariables%2FConnectionBrowser.java;h=11a49f01705e002a73a44c7e1d2d36aa90d4fafc;hb=c433e87787fb162d3f5d966678aaedf491266080;hp=7f43f59d171bb0177c855d869026457a256cffa6;hpb=7402926f3949dbb38e9f8f45e864ba4dd65b59b9;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java index 7f43f59d1..11a49f017 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java @@ -17,8 +17,8 @@ import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.request.BinaryRead; 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; @@ -35,8 +35,6 @@ import org.simantics.structural2.Functions.InterfaceResolution; import org.simantics.structural2.queries.ConnectionSet; import org.simantics.structural2.utils.StructuralUtils; import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass; -import org.simantics.structural2.variables.StandardProceduralChildVariable.FixedConnection; -import org.simantics.utils.datastructures.Pair; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; @@ -81,7 +79,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 +274,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 result = colls.createList(); result.add(ancestor); @@ -337,14 +335,9 @@ public class ConnectionBrowser { Variable conn = child.getPossibleProperty(graph, cp); FixedConnection fc = (FixedConnection)conn.getValue(graph); - Set result = new THashSet(1+fc.cps.size()); - result.add(new ComponentConnectionDescriptor(child, cp));// (graph, STR, curConfiguration, "/" + c.name + "#" + conn.getName(graph))); - for(Pair cpzz : fc.cps) { - if(cpzz.first == null) { - throw new DatabaseException("Lifted connection was not resolved."); - } - result.add(new PairConnectionDescriptor(curConfiguration, cpzz)); - } + Set result = new THashSet(1+fc.size()); + result.add(new ComponentConnectionDescriptor(child, cp)); + fc.addConnectionDescriptors(graph, curConfiguration, result); return result; } else { @@ -456,9 +449,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)); + } } } } @@ -621,47 +624,41 @@ public class ConnectionBrowser { needDrill = new THashSet(climbed.size()); needDrill.add(desc); } else { + if(relationType != null) { + if(!filterByRelationType(graph, desc, relationType)) + continue; + } if(result == null) result = new THashSet(climbed.size()); result.add(desc); } } - if(needDrill == null) { - /* - * All descriptors were already flat - just take case of filtering - */ - if(relationType != null) { - ArrayList filtered = new ArrayList(climbed.size()); - for(VariableConnectionPointDescriptor desc : climbed) - if(filterByRelationType(graph, desc, relationType)) - filtered.add(desc); - return filtered; - } else { - return climbed; + if(needDrill != null) { + /* + * There were some descriptors that require drill + */ + for(VariableConnectionPointDescriptor top : needDrill) { + Collection drilled = drill(graph, top); + if(drilled != null) { + for(VariableConnectionPointDescriptor drill : drilled) { + if(relationType != null) { + if(!filterByRelationType(graph, drill, relationType)) + continue; + } + if(result == null) + result = new THashSet(climbed.size()); + result.add(drill); + } + } } } - - /* - * There were some descriptors that require drill - */ - for(VariableConnectionPointDescriptor top : needDrill) { - Collection drilled = drill(graph, top); - if(drilled != null) { - for(VariableConnectionPointDescriptor drill : drilled) { - if(relationType != null) { - if(!filterByRelationType(graph, drill, relationType)) - continue; - } - if(result == null) - result = new THashSet(climbed.size()); - result.add(drill); - } - } + if (result != null) { + return result; + } else { + return Collections.emptySet(); } - return result; - } private static boolean filterByRelationType(ReadGraph graph, VariableConnectionPointDescriptor desc, Resource relationType) throws DatabaseException {