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