]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ResourceToPossibleVariable.java
Initial support for concurrency in databoard, bindings and serializers
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / ResourceToPossibleVariable.java
1 package org.simantics.db.layer0.request;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.request.ResourceRead;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.variable.StandardGraphChildVariable;
8 import org.simantics.db.layer0.variable.Variable;
9 import org.simantics.layer0.Layer0;
10
11 public class ResourceToPossibleVariable extends ResourceRead<Variable> {
12
13         public ResourceToPossibleVariable(Resource resource) {
14                 super(resource);
15         }
16         
17         @Override
18         public Variable perform(ReadGraph graph) throws DatabaseException {
19                 
20                 Layer0 L0 = Layer0.getInstance(graph);
21                 Resource parent = graph.getPossibleObject(resource, L0.PartOf);
22                 if(parent == null) {
23                         if(graph.getRootLibrary().equals(resource)) return new StandardGraphChildVariable(null, null, graph.getRootLibrary());
24                         else return null;
25                 }
26                 Variable parentVariable = graph.syncRequest(new ResourceToPossibleVariable(parent));
27                 if(parentVariable == null) return null;
28                 return parentVariable.browsePossible(graph, resource);
29                 
30         }
31
32 }