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