]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/techtype/variable/Functions.java
beb92684693ba96a00f683712a5741c235ad8b8d
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / techtype / variable / Functions.java
1 package org.simantics.district.network.techtype.variable;
2
3 import org.simantics.databoard.binding.Binding;
4 import org.simantics.databoard.type.Datatype;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.WriteGraph;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.variable.ValueAccessor;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.district.network.techtype.TechTypeUtils;
12 import org.simantics.scl.reflection.annotations.SCLValue;
13 import org.simantics.structural.stubs.StructuralResource2;
14
15 public class Functions {
16         @SCLValue(type = "ValueAccessor")
17         public static final ValueAccessor techTypeCodeValueAccessor = new ValueAccessor() {
18
19                 @Override
20                 public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
21                         return org.simantics.db.layer0.function.All.standardValueAccessor.getValue(graph, context);
22                 }
23
24                 @Override
25                 public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException {
26                         return org.simantics.db.layer0.function.All.standardValueAccessor.getValue(graph, context, binding);
27                 }
28
29                 @Override
30                 public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException {
31                         org.simantics.db.layer0.function.All.standardValueAccessor.setValue(graph, context, value);
32                         
33                         updateComponentProperties(graph, context, value);
34                 }
35
36                 @Override
37                 public void setValue(WriteGraph graph, Variable context, Object value, Binding binding)
38                                 throws DatabaseException {
39                         org.simantics.db.layer0.function.All.standardValueAccessor.setValue(graph, context, value, binding);
40                         
41                         updateComponentProperties(graph, context, value);
42                 }
43
44                 @Override
45                 public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException {
46                         return org.simantics.db.layer0.function.All.standardValueAccessor.getDatatype(graph, context);
47                 }
48                 
49         };
50
51         protected static void updateComponentProperties(WriteGraph graph, Variable context, Object value) throws DatabaseException {
52                 Variable component = context.getParent(graph);
53                 Resource type = component.getPossibleType(graph, StructuralResource2.getInstance(graph).Component);
54                 if (type == null)
55                         return;
56                 
57                 TechTypeUtils.updateComponent(graph, component.getRepresents(graph));
58         }
59 }