X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FVariableSpaceManipulator.java;h=23c290025e97c98b78ae484499a346c7c6074153;hb=85c1daf4b3d4a48613e0c61c359cb8aac2157f01;hp=6346510c366f59193675e621d96dbd471eb46a66;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git 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 index 6346510c3..23c290025 100644 --- 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 @@ -1,124 +1,124 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.layer0.variable; - -import java.util.Collection; -import java.util.Collections; - -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; - -/** - * Obtained with Variable.adapt - */ -public interface VariableSpaceManipulator { - - public class PropertyCreationData { - public String name; - public Variant value; - public PropertyCreationData(String name, Variant value) { - this.name = name; - this.value = value; - } - - public static PropertyCreationData build(String name, Object value) { - return new PropertyCreationData(name, Variant.ofInstance(value)); - } - - } - - public class ChildCreationData { - public String type; - public String name; - public PropertyCreationData[] properties; - public ChildCreationData(String name, String type, PropertyCreationData[] properties) { - this.name = name; - this.type = type; - this.properties = properties; - } - - public static ChildCreationData build(String name, String type, PropertyCreationData ... properties) { - return new ChildCreationData(name, type, properties); - } - - } - - public class Modification { - - public String[] removedProperties; - public String[] removedChildren; - public PropertyCreationData[] newProperties; - public ChildCreationData[] newChildren; - - public Modification(String[] removedProperties, String[] removedChildren, PropertyCreationData[] newProperties, ChildCreationData[] newChildren) { - this.removedProperties = removedProperties; - this.removedChildren = removedChildren; - this.newProperties = newProperties; - this.newChildren = newChildren; - } - - public static Modification build(Collection removedProperties, Collection removedChildren, Collection newProperties, Collection newChildren) { - return new Modification( - removedProperties.toArray(new String[removedProperties.size()]), - removedChildren.toArray(new String[removedChildren.size()]), - newProperties.toArray(new PropertyCreationData[newProperties.size()]), - newChildren.toArray(new ChildCreationData[newChildren.size()])); - } - - public static Modification buildChildren(Collection removedChildren, Collection newChildren) { - return new Modification( - new String[0], removedChildren.toArray(new String[removedChildren.size()]), - new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()])); - } - - public static Modification addChildren(Collection newChildren) { - return new Modification( - new String[0], new String[0], - new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()])); - } - - public static Modification addChild(ChildCreationData child) { - return addChildren(Collections.singletonList(child)); - } - - public static Modification removeChildren(Collection removedChildren) { - return new Modification( - new String[0], removedChildren.toArray(new String[removedChildren.size()]), - new PropertyCreationData[0], new ChildCreationData[0]); - } - - public static Modification removeChild(String child) { - return removeChildren(Collections.singletonList(child)); - } - - public static Modification addProperties(Collection newProperties) { - return new Modification( - new String[0], new String[0], - newProperties.toArray(new PropertyCreationData[newProperties.size()]), new ChildCreationData[0]); - } - - public static Modification addProperty(PropertyCreationData property) { - return addProperties(Collections.singletonList(property)); - } - - } - - void apply(WriteGraph graph, Modification modification) throws DatabaseException; - -// Variable createChild(WriteGraph graph, String name, Object content) throws DatabaseException; -// Variable createProperty(WriteGraph graph, String name) throws DatabaseException; -// Variable createVariable(WriteGraph graph, String rvi) throws DatabaseException; -// -// Variable removeChild(WriteGraph graph, String name) throws DatabaseException; - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.layer0.variable; + +import java.util.Collection; +import java.util.Collections; + +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; + +/** + * Obtained with Variable.adapt + */ +public interface VariableSpaceManipulator { + + public class PropertyCreationData { + public String name; + public Variant value; + public PropertyCreationData(String name, Variant value) { + this.name = name; + this.value = value; + } + + public static PropertyCreationData build(String name, Object value) { + return new PropertyCreationData(name, Variant.ofInstance(value)); + } + + } + + public class ChildCreationData { + public String type; + public String name; + public PropertyCreationData[] properties; + public ChildCreationData(String name, String type, PropertyCreationData[] properties) { + this.name = name; + this.type = type; + this.properties = properties; + } + + public static ChildCreationData build(String name, String type, PropertyCreationData ... properties) { + return new ChildCreationData(name, type, properties); + } + + } + + public class Modification { + + public String[] removedProperties; + public String[] removedChildren; + public PropertyCreationData[] newProperties; + public ChildCreationData[] newChildren; + + public Modification(String[] removedProperties, String[] removedChildren, PropertyCreationData[] newProperties, ChildCreationData[] newChildren) { + this.removedProperties = removedProperties; + this.removedChildren = removedChildren; + this.newProperties = newProperties; + this.newChildren = newChildren; + } + + public static Modification build(Collection removedProperties, Collection removedChildren, Collection newProperties, Collection newChildren) { + return new Modification( + removedProperties.toArray(new String[removedProperties.size()]), + removedChildren.toArray(new String[removedChildren.size()]), + newProperties.toArray(new PropertyCreationData[newProperties.size()]), + newChildren.toArray(new ChildCreationData[newChildren.size()])); + } + + public static Modification buildChildren(Collection removedChildren, Collection newChildren) { + return new Modification( + new String[0], removedChildren.toArray(new String[removedChildren.size()]), + new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()])); + } + + public static Modification addChildren(Collection newChildren) { + return new Modification( + new String[0], new String[0], + new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()])); + } + + public static Modification addChild(ChildCreationData child) { + return addChildren(Collections.singletonList(child)); + } + + public static Modification removeChildren(Collection removedChildren) { + return new Modification( + new String[0], removedChildren.toArray(new String[removedChildren.size()]), + new PropertyCreationData[0], new ChildCreationData[0]); + } + + public static Modification removeChild(String child) { + return removeChildren(Collections.singletonList(child)); + } + + public static Modification addProperties(Collection newProperties) { + return new Modification( + new String[0], new String[0], + newProperties.toArray(new PropertyCreationData[newProperties.size()]), new ChildCreationData[0]); + } + + public static Modification addProperty(PropertyCreationData property) { + return addProperties(Collections.singletonList(property)); + } + + } + + void apply(WriteGraph graph, Modification modification) throws DatabaseException; + +// Variable createChild(WriteGraph graph, String name, Object content) throws DatabaseException; +// Variable createProperty(WriteGraph graph, String name) throws DatabaseException; +// Variable createVariable(WriteGraph graph, String rvi) throws DatabaseException; +// +// Variable removeChild(WriteGraph graph, String name) throws DatabaseException; + +}