]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/SheetVariableSpaceManipulator.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/SheetVariableSpaceManipulator.java
new file mode 100644 (file)
index 0000000..66adc07
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.spreadsheet.graph.adapter;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.VariableSpaceManipulator;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class SheetVariableSpaceManipulator implements VariableSpaceManipulator {\r
+    \r
+    private Variable variable;\r
+    public SheetVariableSpaceManipulator(Variable variable) {\r
+        this.variable = variable;\r
+    }\r
+\r
+    @Override\r
+    public void apply(WriteGraph graph, Modification modification) throws DatabaseException {\r
+        \r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        for(String name : modification.removedChildren) {\r
+            Variable child = variable.getChild(graph, name);\r
+            Resource represents = child.getRepresents(graph);\r
+            graph.deny(represents, L0.PartOf);\r
+        }\r
+        \r
+        for(ChildCreationData data : modification.newChildren) {\r
+            Resource container = variable.getRepresents(graph);\r
+            Resource cell = graph.newResource();\r
+            Resource type = graph.getResource(data.type);\r
+            graph.claim(cell, L0.InstanceOf, null, type);\r
+            graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, data.name, Bindings.STRING);\r
+            for(PropertyCreationData p : data.properties) {\r
+                Resource property = graph.getResource(p.name);\r
+                graph.claimLiteral(cell, property, p.value.getValue());\r
+            }\r
+            graph.claim(cell, L0.PartOf, container);\r
+            \r
+        }\r
+    }\r
+\r
+}\r