1 package org.simantics.modeling.adapters;
3 import java.util.Collection;
4 import java.util.Collections;
7 import org.simantics.browsing.ui.model.children.ChildRule;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.db.layer0.variable.Variables;
13 import org.simantics.modeling.ModelingResources;
14 import org.simantics.scl.runtime.SCLContext;
15 import org.simantics.scl.runtime.function.Function1;
17 public class SCLChildRule implements ChildRule {
19 private Resource rule;
21 public SCLChildRule(ReadGraph graph, Resource rule) {
26 public boolean isCompatible(Class<?> contentType) {
27 return contentType.equals(Resource.class) || contentType.equals(Variable.class);
31 public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
33 ModelingResources MOD = ModelingResources.getInstance(graph);
35 Variable ruleVariable = Variables.getVariable(graph, rule);
37 Function1<Object,List<?>> getChildren = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLChildRule_getChildren);
38 if(getChildren == null) return Collections.emptyList();
40 SCLContext sclContext = SCLContext.getCurrent();
41 Object oldGraph = sclContext.get("graph");
43 sclContext.put("graph", graph);
44 Object value = getChildren.apply(parent);
45 return (Collection<?>)value;
46 } catch (Throwable t) {
47 throw new DatabaseException(t);
49 sclContext.put("graph", oldGraph);
55 public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {