X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fadapters%2FSCLChildRule.java;h=1ea88caf4377bb7cb66b31e8b55b8eeafec32ac9;hb=33b30297f751e06e9abac260d31313e2f833fedc;hp=8ca1b9ae8b5a676a8916a1b8b4ce95ac0bde9ca7;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLChildRule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLChildRule.java index 8ca1b9ae8..1ea88caf4 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLChildRule.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLChildRule.java @@ -1,59 +1,65 @@ -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 getChildren(ReadGraph graph, Object parent) throws DatabaseException { - - ModelingResources MOD = ModelingResources.getInstance(graph); - - Variable ruleVariable = Variables.getVariable(graph, rule); - - Function1> 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); - Object value = getChildren.apply(parent); - return (Collection)value; - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - - } - - @Override - public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { - return null; - } - -} +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 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> 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; + } + +}