-package org.simantics.modeling.adapters;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.simantics.browsing.ui.model.children.ChildRule;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.scl.runtime.SCLContext;\r
-import org.simantics.scl.runtime.function.Function1;\r
-\r
-public class SCLChildRule implements ChildRule {\r
-\r
- private Resource rule;\r
- \r
- public SCLChildRule(ReadGraph graph, Resource rule) {\r
- this.rule = rule;\r
- }\r
- \r
- @Override\r
- public boolean isCompatible(Class<?> contentType) {\r
- return contentType.equals(Resource.class) || contentType.equals(Variable.class);\r
- }\r
-\r
- @Override\r
- public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {\r
- \r
- ModelingResources MOD = ModelingResources.getInstance(graph);\r
- \r
- Variable ruleVariable = Variables.getVariable(graph, rule);\r
-\r
- Function1<Object,List<?>> getChildren = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLChildRule_getChildren);\r
- if(getChildren == null) return Collections.emptyList();\r
-\r
- SCLContext sclContext = SCLContext.getCurrent();\r
- Object oldGraph = sclContext.get("graph");\r
- try {\r
- sclContext.put("graph", graph);\r
- Object value = getChildren.apply(parent);\r
- return (Collection<?>)value;\r
- } catch (Throwable t) {\r
- throw new DatabaseException(t);\r
- } finally {\r
- sclContext.put("graph", oldGraph);\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {\r
- return null;\r
- }\r
-\r
-}\r
+package org.simantics.modeling.adapters;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.simantics.browsing.ui.model.children.ChildRule;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+
+public class SCLChildRule implements ChildRule {
+
+ private Resource rule;
+
+ public SCLChildRule(ReadGraph graph, Resource rule) {
+ this.rule = rule;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return contentType.equals(Resource.class) || contentType.equals(Variable.class);
+ }
+
+ @Override
+ public Collection<Resource> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
+ Resource parentResource;
+
+ if (parent instanceof Variable) {
+ parentResource = ((Variable)parent).getRepresents(graph);
+ } else {
+ parentResource = (Resource)parent;
+ }
+
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+
+ Variable ruleVariable = Variables.getVariable(graph, rule);
+
+ Function1<Resource,List<Resource>> getChildren = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLChildRule_getChildren);
+ if(getChildren == null) return Collections.emptyList();
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ sclContext.put("graph", graph);
+ return getChildren.apply(parentResource);
+ } catch (Throwable t) {
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
+ @Override
+ public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {
+ return null;
+ }
+
+}