]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/query/QueryProxyChildVariable.java
Fixed ComponentTypeCommands.setUnit to support unit == null
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / query / QueryProxyChildVariable.java
1 package org.simantics.modeling.query;
2
3 import java.util.Collection;
4
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.variable.ProxyChildVariable;
8 import org.simantics.db.layer0.variable.Variable;
9
10 public class QueryProxyChildVariable extends ProxyChildVariable {
11
12     public QueryProxyChildVariable(Variable base, Variable parent, Variable other, String name) {
13         super(base, parent, other, name);
14     }
15
16     @Override
17     public Variable create(Variable base, Variable parent, Variable other, String name) {
18         return new QueryProxyChildVariable(base, parent, other, name);
19     }
20     
21     public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
22         
23         if(CONTEXT_END.equals(name)) {
24                 if(other instanceof ProxyChildVariable) {
25                         // The context is also a proxy - let it do the job
26                 return super.getPossibleChild(graph, name);
27                 } else {
28                 return new QueryRootVariable(this, base.getRepresents(graph));
29                 }
30         }
31         
32         return super.getPossibleChild(graph, name);
33         
34     }
35     
36     public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
37
38         Collection<Variable> result = super.getChildren(graph);
39         if(!(base instanceof ProxyChildVariable)) {
40                 result.add(new QueryRootVariable(this, base.getRepresents(graph)));
41         }
42         return result;
43         
44     }       
45     
46 }