1 package org.simantics.spreadsheet.graph.adapter;
\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
11 public class SheetVariableSpaceManipulator implements VariableSpaceManipulator {
\r
13 private Variable variable;
\r
14 public SheetVariableSpaceManipulator(Variable variable) {
\r
15 this.variable = variable;
\r
19 public void apply(WriteGraph graph, Modification modification) throws DatabaseException {
\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
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
38 graph.claim(cell, L0.PartOf, container);
\r