--- /dev/null
+package org.simantics.modeling.ui.viewpoint;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.simantics.browsing.ui.model.children.ChildRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+\r
+public class VariableChildRule implements ChildRule {\r
+\r
+ @Override\r
+ public boolean isCompatible(Class<?> contentType) {\r
+ return contentType.equals(Variable.class);\r
+ }\r
+\r
+ @Override\r
+ public Collection<?> getChildren(ReadGraph graph, Object parent)\r
+ throws DatabaseException {\r
+ Collection<Variable> children = ((Variable)parent).getChildren(graph);\r
+ return VariableChildren.filterByClassification(graph, children, StructuralResource2.URIs.Component);\r
+ }\r
+\r
+ @Override\r
+ public Collection<?> getParents(ReadGraph graph, Object child)\r
+ throws DatabaseException {\r
+ Variable parent = ((Variable)child).getParent(graph);\r
+ if(parent == null)\r
+ return Collections.emptyList();\r
+ else\r
+ return Collections.singleton(parent);\r
+ }\r
+\r
+\r
+}\r