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