]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableSpaceManipulator.java
Merge commit 'ad8333027322fda6b9a8a524c7a7e15a54c52f38'
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableSpaceManipulator.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.layer0.variable;\r
13 \r
14 import java.util.Collection;\r
15 import java.util.Collections;\r
16 \r
17 import org.simantics.databoard.binding.mutable.Variant;\r
18 import org.simantics.db.WriteGraph;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 \r
21 /**\r
22  * Obtained with Variable.adapt\r
23  */\r
24 public interface VariableSpaceManipulator {\r
25 \r
26     public class PropertyCreationData {\r
27         public String name;\r
28         public Variant value;\r
29         public PropertyCreationData(String name, Variant value) {\r
30             this.name = name;\r
31             this.value = value;\r
32         }\r
33         \r
34                 public static PropertyCreationData build(String name, Object value) {\r
35                         return new PropertyCreationData(name, Variant.ofInstance(value));\r
36                 }\r
37         \r
38     }\r
39         \r
40     public class ChildCreationData {\r
41         public String type;\r
42         public String name;\r
43         public PropertyCreationData[] properties;\r
44         public ChildCreationData(String name, String type, PropertyCreationData[] properties) {\r
45             this.name = name;\r
46             this.type = type;\r
47             this.properties = properties;\r
48         }\r
49         \r
50                 public static ChildCreationData build(String name, String type, PropertyCreationData ... properties) {\r
51                         return new ChildCreationData(name, type, properties);\r
52                 }\r
53         \r
54     }\r
55 \r
56     public class Modification {\r
57 \r
58                 public String[] removedProperties;\r
59                 public String[] removedChildren;\r
60                 public PropertyCreationData[] newProperties;\r
61                 public ChildCreationData[] newChildren;\r
62                 \r
63                 public Modification(String[] removedProperties, String[] removedChildren, PropertyCreationData[] newProperties, ChildCreationData[] newChildren) {\r
64                         this.removedProperties = removedProperties;\r
65                         this.removedChildren = removedChildren;\r
66                         this.newProperties = newProperties;\r
67                         this.newChildren = newChildren;\r
68                 }\r
69                 \r
70                 public static Modification build(Collection<String> removedProperties, Collection<String> removedChildren, Collection<PropertyCreationData> newProperties, Collection<ChildCreationData> newChildren) {\r
71                         return new Modification(\r
72                                         removedProperties.toArray(new String[removedProperties.size()]),\r
73                                         removedChildren.toArray(new String[removedChildren.size()]),\r
74                                         newProperties.toArray(new PropertyCreationData[newProperties.size()]),\r
75                                         newChildren.toArray(new ChildCreationData[newChildren.size()]));\r
76                 }\r
77 \r
78                 public static Modification buildChildren(Collection<String> removedChildren, Collection<ChildCreationData> newChildren) {\r
79                         return new Modification(\r
80                                         new String[0], removedChildren.toArray(new String[removedChildren.size()]),\r
81                                         new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));\r
82                 }\r
83                 \r
84                 public static Modification addChildren(Collection<ChildCreationData> newChildren) {\r
85                         return new Modification(\r
86                                         new String[0], new String[0],\r
87                                         new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));\r
88                 }\r
89 \r
90                 public static Modification addChild(ChildCreationData child) {\r
91                         return addChildren(Collections.singletonList(child));\r
92                 }\r
93 \r
94                 public static Modification removeChildren(Collection<String> removedChildren) {\r
95                         return new Modification(\r
96                                         new String[0], removedChildren.toArray(new String[removedChildren.size()]),\r
97                                         new PropertyCreationData[0], new ChildCreationData[0]);\r
98                 }\r
99 \r
100                 public static Modification removeChild(String child) {\r
101                         return removeChildren(Collections.singletonList(child));\r
102                 }\r
103                 \r
104                 public static Modification addProperties(Collection<PropertyCreationData> newProperties) {\r
105                         return new Modification(\r
106                                         new String[0], new String[0],\r
107                                         newProperties.toArray(new PropertyCreationData[newProperties.size()]), new ChildCreationData[0]);\r
108                 }\r
109                 \r
110                 public static Modification addProperty(PropertyCreationData property) {\r
111                         return addProperties(Collections.singletonList(property));\r
112                 }\r
113                 \r
114         }\r
115         \r
116     void apply(WriteGraph graph, Modification modification) throws DatabaseException;\r
117         \r
118 //      Variable createChild(WriteGraph graph, String name, Object content) throws DatabaseException;\r
119 //      Variable createProperty(WriteGraph graph, String name) throws DatabaseException;\r
120 //      Variable createVariable(WriteGraph graph, String rvi) throws DatabaseException;\r
121 //      \r
122 //      Variable removeChild(WriteGraph graph, String name) throws DatabaseException;\r
123         \r
124 }\r