]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableSpaceManipulator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableSpaceManipulator.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableSpaceManipulator.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableSpaceManipulator.java
new file mode 100644 (file)
index 0000000..6346510
--- /dev/null
@@ -0,0 +1,124 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.layer0.variable;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * Obtained with Variable.adapt\r
+ */\r
+public interface VariableSpaceManipulator {\r
+\r
+    public class PropertyCreationData {\r
+       public String name;\r
+       public Variant value;\r
+        public PropertyCreationData(String name, Variant value) {\r
+            this.name = name;\r
+            this.value = value;\r
+        }\r
+        \r
+               public static PropertyCreationData build(String name, Object value) {\r
+                       return new PropertyCreationData(name, Variant.ofInstance(value));\r
+               }\r
+        \r
+    }\r
+       \r
+    public class ChildCreationData {\r
+       public String type;\r
+       public String name;\r
+        public PropertyCreationData[] properties;\r
+        public ChildCreationData(String name, String type, PropertyCreationData[] properties) {\r
+            this.name = name;\r
+            this.type = type;\r
+            this.properties = properties;\r
+        }\r
+        \r
+               public static ChildCreationData build(String name, String type, PropertyCreationData ... properties) {\r
+                       return new ChildCreationData(name, type, properties);\r
+               }\r
+        \r
+    }\r
+\r
+    public class Modification {\r
+\r
+               public String[] removedProperties;\r
+               public String[] removedChildren;\r
+               public PropertyCreationData[] newProperties;\r
+               public ChildCreationData[] newChildren;\r
+               \r
+               public Modification(String[] removedProperties, String[] removedChildren, PropertyCreationData[] newProperties, ChildCreationData[] newChildren) {\r
+                       this.removedProperties = removedProperties;\r
+                       this.removedChildren = removedChildren;\r
+                       this.newProperties = newProperties;\r
+                       this.newChildren = newChildren;\r
+               }\r
+               \r
+               public static Modification build(Collection<String> removedProperties, Collection<String> removedChildren, Collection<PropertyCreationData> newProperties, Collection<ChildCreationData> newChildren) {\r
+                       return new Modification(\r
+                                       removedProperties.toArray(new String[removedProperties.size()]),\r
+                                       removedChildren.toArray(new String[removedChildren.size()]),\r
+                                       newProperties.toArray(new PropertyCreationData[newProperties.size()]),\r
+                                       newChildren.toArray(new ChildCreationData[newChildren.size()]));\r
+               }\r
+\r
+               public static Modification buildChildren(Collection<String> removedChildren, Collection<ChildCreationData> newChildren) {\r
+                       return new Modification(\r
+                                       new String[0], removedChildren.toArray(new String[removedChildren.size()]),\r
+                                       new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));\r
+               }\r
+               \r
+               public static Modification addChildren(Collection<ChildCreationData> newChildren) {\r
+                       return new Modification(\r
+                                       new String[0], new String[0],\r
+                                       new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));\r
+               }\r
+\r
+               public static Modification addChild(ChildCreationData child) {\r
+                       return addChildren(Collections.singletonList(child));\r
+               }\r
+\r
+               public static Modification removeChildren(Collection<String> removedChildren) {\r
+                       return new Modification(\r
+                                       new String[0], removedChildren.toArray(new String[removedChildren.size()]),\r
+                                       new PropertyCreationData[0], new ChildCreationData[0]);\r
+               }\r
+\r
+               public static Modification removeChild(String child) {\r
+                       return removeChildren(Collections.singletonList(child));\r
+               }\r
+               \r
+               public static Modification addProperties(Collection<PropertyCreationData> newProperties) {\r
+                       return new Modification(\r
+                                       new String[0], new String[0],\r
+                                       newProperties.toArray(new PropertyCreationData[newProperties.size()]), new ChildCreationData[0]);\r
+               }\r
+               \r
+               public static Modification addProperty(PropertyCreationData property) {\r
+                       return addProperties(Collections.singletonList(property));\r
+               }\r
+               \r
+       }\r
+       \r
+    void apply(WriteGraph graph, Modification modification) throws DatabaseException;\r
+       \r
+//     Variable createChild(WriteGraph graph, String name, Object content) throws DatabaseException;\r
+//     Variable createProperty(WriteGraph graph, String name) throws DatabaseException;\r
+//     Variable createVariable(WriteGraph graph, String rvi) throws DatabaseException;\r
+//     \r
+//     Variable removeChild(WriteGraph graph, String name) throws DatabaseException;\r
+       \r
+}\r