]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/scl/VariableStructuralContext.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / scl / VariableStructuralContext.java
1 package org.simantics.structural2.scl;\r
2 \r
3 import java.util.List;\r
4 \r
5 import org.simantics.databoard.Bindings;\r
6 import org.simantics.databoard.adapter.AdaptException;\r
7 import org.simantics.databoard.binding.Binding;\r
8 import org.simantics.db.ReadGraph;\r
9 import org.simantics.db.Resource;\r
10 import org.simantics.db.exception.DatabaseException;\r
11 import org.simantics.db.layer0.variable.Variable;\r
12 import org.simantics.layer0.Layer0;\r
13 import org.simantics.structural.stubs.StructuralResource2;\r
14 import org.simantics.structural2.scl.StructuralComponent;\r
15 \r
16 public class VariableStructuralContext extends StructuralComponent<Variable> {\r
17 \r
18         final public Variable variable;\r
19         \r
20         public VariableStructuralContext(ReadGraph graph, Variable selfVariable) throws DatabaseException {\r
21                 this.variable = selfVariable.getParent(graph).getParent(graph);\r
22         }\r
23 \r
24         public VariableStructuralContext(Variable variable) throws DatabaseException {\r
25                 this.variable = variable;\r
26         }\r
27 \r
28         @Override\r
29         public Resource getType(ReadGraph g) throws DatabaseException {\r
30                 throw new UnsupportedOperationException();\r
31         }\r
32 \r
33         @Override\r
34         public Object getValue(ReadGraph g, Resource attribute, Binding binding) throws DatabaseException, AdaptException {\r
35                 \r
36                 Layer0 L0 = Layer0.getInstance(g);\r
37                 StructuralResource2 STR = StructuralResource2.getInstance(g);\r
38                 if(STR.input.equals(attribute)) {\r
39                         return variable.getPropertyValue(g, "input");\r
40                 }\r
41 \r
42                 String name = g.getRelatedValue(attribute, L0.HasName, Bindings.STRING);\r
43                 return variable.getPropertyValue(g, name);\r
44                 \r
45         }\r
46 \r
47         @Override\r
48         public boolean isParametrized(ReadGraph g) throws DatabaseException {\r
49                 throw new UnsupportedOperationException();\r
50         }\r
51 \r
52         @Override\r
53         public Variable getConnection(ReadGraph g, Resource connectionPoint) throws DatabaseException {\r
54                 throw new UnsupportedOperationException();\r
55         }\r
56 \r
57         @SuppressWarnings({ "unchecked", "rawtypes" })\r
58         @Override\r
59         public List getConnections(ReadGraph g, Resource connectionPoint) throws DatabaseException {\r
60                 throw new UnsupportedOperationException();\r
61         }\r
62 \r
63         @Override\r
64         public Resource getResource() {\r
65                 throw new UnsupportedOperationException();\r
66         }\r
67 \r
68     @Override\r
69     public StructuralComponent<Variable> getContext() {\r
70         throw new UnsupportedOperationException();\r
71     }\r
72 \r
73 }\r