From 4b2ffb1be3b95a8d7b87fc9267e2b3921643a9b3 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Mon, 1 Oct 2018 13:24:20 +0300 Subject: [PATCH] Replaceable Defined Component Types fixes gitlab #83 Change-Id: I581cc150ec8d042868428c1d47da10a3864afca6 --- .../structural2/utils/StructuralUtils.java | 8 ++++++-- .../structural2/variables/ConnectionBrowser.java | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java index 584b4acf7..c5b0087e2 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java @@ -329,12 +329,16 @@ public class StructuralUtils { } public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException { - Variable componentVariable = configuration.browse(graph, component); return componentVariable.getType(graph); - } + public static Resource getPossibleComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException { + Variable componentVariable = configuration.browsePossible(graph, component); + if(componentVariable == null) return null; + StructuralResource2 STR = StructuralResource2.getInstance(graph); + return componentVariable.getPossibleType(graph, STR.Component); + } } 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..4a40723ef 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 @@ -81,7 +81,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 @@ -456,9 +456,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)); + } } } } -- 2.43.2