]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/query/QueryProxyChildVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / query / QueryProxyChildVariable.java
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/query/QueryProxyChildVariable.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/query/QueryProxyChildVariable.java
new file mode 100644 (file)
index 0000000..6c62c4e
--- /dev/null
@@ -0,0 +1,46 @@
+package org.simantics.modeling.query;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.ProxyChildVariable;\r
+import org.simantics.db.layer0.variable.Variable;\r
+\r
+public class QueryProxyChildVariable extends ProxyChildVariable {\r
+\r
+    public QueryProxyChildVariable(Variable base, Variable parent, Variable other, String name) {\r
+        super(base, parent, other, name);\r
+    }\r
+\r
+    @Override\r
+    public Variable create(Variable base, Variable parent, Variable other, String name) {\r
+        return new QueryProxyChildVariable(base, parent, other, name);\r
+    }\r
+    \r
+    public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
+        \r
+       if(CONTEXT_END.equals(name)) {\r
+               if(other instanceof ProxyChildVariable) {\r
+                       // The context is also a proxy - let it do the job\r
+                return super.getPossibleChild(graph, name);\r
+               } else {\r
+               return new QueryRootVariable(this, base.getRepresents(graph));\r
+               }\r
+       }\r
+        \r
+        return super.getPossibleChild(graph, name);\r
+        \r
+    }\r
+    \r
+    public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {\r
+\r
+        Collection<Variable> result = super.getChildren(graph);\r
+        if(!(base instanceof ProxyChildVariable)) {\r
+               result.add(new QueryRootVariable(this, base.getRepresents(graph)));\r
+        }\r
+        return result;\r
+        \r
+    }       \r
+    \r
+}
\ No newline at end of file