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