]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/SheetVariableSpaceManipulator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / adapter / SheetVariableSpaceManipulator.java
1 package org.simantics.spreadsheet.graph.adapter;\r
2 \r
3 import org.simantics.databoard.Bindings;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.WriteGraph;\r
6 import org.simantics.db.exception.DatabaseException;\r
7 import org.simantics.db.layer0.variable.Variable;\r
8 import org.simantics.db.layer0.variable.VariableSpaceManipulator;\r
9 import org.simantics.layer0.Layer0;\r
10 \r
11 public class SheetVariableSpaceManipulator implements VariableSpaceManipulator {\r
12     \r
13     private Variable variable;\r
14     public SheetVariableSpaceManipulator(Variable variable) {\r
15         this.variable = variable;\r
16     }\r
17 \r
18     @Override\r
19     public void apply(WriteGraph graph, Modification modification) throws DatabaseException {\r
20         \r
21         Layer0 L0 = Layer0.getInstance(graph);\r
22         for(String name : modification.removedChildren) {\r
23             Variable child = variable.getChild(graph, name);\r
24             Resource represents = child.getRepresents(graph);\r
25             graph.deny(represents, L0.PartOf);\r
26         }\r
27         \r
28         for(ChildCreationData data : modification.newChildren) {\r
29             Resource container = variable.getRepresents(graph);\r
30             Resource cell = graph.newResource();\r
31             Resource type = graph.getResource(data.type);\r
32             graph.claim(cell, L0.InstanceOf, null, type);\r
33             graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, data.name, Bindings.STRING);\r
34             for(PropertyCreationData p : data.properties) {\r
35                 Resource property = graph.getResource(p.name);\r
36                 graph.claimLiteral(cell, property, p.value.getValue());\r
37             }\r
38             graph.claim(cell, L0.PartOf, container);\r
39             \r
40         }\r
41     }\r
42 \r
43 }\r