]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java
Merge "Default property editing restores assertions"
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / requests / Node.java
index bdc3a97ddb2dbd3638e28e7207935cbbe7e50054..4a43e0840a907cecc3bfd0bfbc847113775e8161 100644 (file)
-/*******************************************************************************\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.modeling.requests;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.utils.page.PageDesc;\r
-import org.simantics.utils.strings.AlphanumComparator;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class Node implements Comparable<Node> {\r
-\r
-    public static final Comparator<Node> CASE_INSENSITIVE_COMPARATOR = new Comparator<Node>() {\r
-        @Override\r
-        public int compare(Node o1, Node o2) {\r
-            return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName());\r
-        }\r
-    };\r
-\r
-    private final Node       parent;\r
-    private final List<Node> children = new ArrayList<Node>();\r
-\r
-    /**\r
-     * May be <code>null</code> if there is no diagram for this node.\r
-     */\r
-    private final Resource         diagram;\r
-    private final ResourceArray    definingResource; // i.e. Composite\r
-    private final String           name;\r
-\r
-//    private String[]         partOfGroups = {};\r
-\r
-    private PageDesc         pageDesc;\r
-    private String           RVI;\r
-\r
-    /**\r
-     * @param parent\r
-     * @param name\r
-     * @param diagram may be <code>null</code> if there is no diagram for this node\r
-     * @param definingResources\r
-     */\r
-    public Node(Node parent, String name, Resource diagram, Resource... definingResources) {\r
-        if (definingResources.length == 0)\r
-            throw new IllegalArgumentException("must provide at least one defining resource");\r
-        this.parent = parent;\r
-        this.name = name;\r
-        this.diagram = diagram;\r
-        this.definingResource = new ResourceArray(definingResources);\r
-\r
-        if (parent != null)\r
-            parent.addChild(this);\r
-    }\r
-\r
-    public Node getParent() {\r
-        return parent;\r
-    }\r
-\r
-    /**\r
-     * @return <code>null</code> if there is no diagram for this node\r
-     */\r
-    public Resource getDiagramResource() {\r
-        return diagram;\r
-    }\r
-\r
-    public ResourceArray getDefiningResources() {\r
-        return definingResource;\r
-    }\r
-\r
-    public String getName() {\r
-        return name;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return (parent != null ? parent : "") + "/" + name + definingResource;\r
-    }\r
-\r
-    public void addChild(Node child) {\r
-        children.add(child);\r
-    }\r
-\r
-    public void removeChild(Node child) {\r
-        children.remove(child);\r
-    }\r
-\r
-    public Collection<Node> getChildren() {\r
-        return Collections.unmodifiableCollection(children);\r
-    }\r
-\r
-//    public void setPartOfGroups(Collection<String> groups) {\r
-//        this.partOfGroups = groups.toArray(new String[groups.size()]);\r
-//    }\r
-//\r
-//    public String[] getPartOfGroups() {\r
-//        return partOfGroups;\r
-//    }\r
-\r
-    public void setPageDesc(PageDesc pageDesc) {\r
-        this.pageDesc = pageDesc;\r
-    }\r
-    \r
-    public void setRVI(String RVI) {\r
-       this.RVI = RVI;\r
-    }\r
-    \r
-    public String getRVI() {\r
-       return RVI;\r
-    }\r
-\r
-    public PageDesc getPageDesc() {\r
-        return pageDesc;\r
-    }\r
-\r
-    @Override\r
-    public int compareTo(Node o) {\r
-        int ret = name.compareTo(o.name);\r
-        return ret;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + ((diagram == null) ? 0 : diagram.hashCode());\r
-        result = prime * result + ((parent == null) ? 0 : parent.hashCode());\r
-        result = prime * result + ((definingResource == null) ? 0 : definingResource.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        Node other = (Node) obj;\r
-        if (diagram == null) {\r
-            if (other.diagram != null)\r
-                return false;\r
-        } else if (!diagram.equals(other.diagram))\r
-            return false;\r
-        if (parent == null) {\r
-            if (other.parent != null)\r
-                return false;\r
-        } else if (!parent.equals(other.parent))\r
-            return false;\r
-        if (definingResource == null) {\r
-            if (other.definingResource != null)\r
-                return false;\r
-        } else if (!definingResource.equals(other.definingResource))\r
-            return false;\r
-        return true;\r
-    }\r
-\r
+/*******************************************************************************
+ * 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.modeling.requests;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.simantics.db.Resource;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.utils.page.PageDesc;
+import org.simantics.utils.strings.AlphanumComparator;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class Node implements Comparable<Node> {
+
+    public static final Comparator<Node> CASE_INSENSITIVE_COMPARATOR =
+            (o1, o2) -> AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName());
+
+    private final Node       parent;
+    private final List<Node> children = new ArrayList<Node>();
+    private final List<Node> unmodifiableChildren = Collections.unmodifiableList(children);
+
+    /**
+     * May be <code>null</code> if there is no diagram for this node.
+     */
+    private final Resource         diagram;
+    private final ResourceArray    definingResource; // i.e. Composite
+    private final String           name;
+
+    private PageDesc         pageDesc;
+    private String           rvi;
+
+    /**
+     * @param parent
+     * @param name
+     * @param diagram may be <code>null</code> if there is no diagram for this node
+     * @param definingResources
+     */
+    public Node(Node parent, String name, Resource diagram, Resource... definingResources) {
+        if (definingResources.length == 0)
+            throw new IllegalArgumentException("must provide at least one defining resource");
+        this.parent = parent;
+        this.name = name;
+        this.diagram = diagram;
+        this.definingResource = new ResourceArray(definingResources);
+
+        if (parent != null)
+            parent.addChild(this);
+    }
+
+    public Node cloneWithoutChildren(Node parent) {
+        Node clone = new Node(parent, name, diagram, definingResource.resources);
+        clone.setRVI(rvi);
+        clone.setPageDesc(pageDesc);
+        return clone;
+    }
+
+    public Node getParent() {
+        return parent;
+    }
+
+    /**
+     * @return <code>null</code> if there is no diagram for this node
+     */
+    public Resource getDiagramResource() {
+        return diagram;
+    }
+
+    public ResourceArray getDefiningResources() {
+        return definingResource;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String toString() {
+        return (parent != null ? parent : "") + "/" + name + definingResource;
+    }
+
+    public void addChild(Node child) {
+        children.add(child);
+    }
+
+    public void removeChild(Node child) {
+        children.remove(child);
+    }
+
+    public Collection<Node> getChildren() {
+        return unmodifiableChildren;
+    }
+
+    public void setPageDesc(PageDesc pageDesc) {
+        this.pageDesc = pageDesc;
+    }
+    
+    public void setRVI(String rvi) {
+       this.rvi = rvi;
+    }
+    
+    public String getRVI() {
+       return rvi;
+    }
+
+    public PageDesc getPageDesc() {
+        return pageDesc;
+    }
+
+    @Override
+    public int compareTo(Node o) {
+        int ret = name.compareTo(o.name);
+        return ret;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((diagram == null) ? 0 : diagram.hashCode());
+        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+        result = prime * result + ((definingResource == null) ? 0 : definingResource.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Node other = (Node) obj;
+        if (diagram == null) {
+            if (other.diagram != null)
+                return false;
+        } else if (!diagram.equals(other.diagram))
+            return false;
+        if (parent == null) {
+            if (other.parent != null)
+                return false;
+        } else if (!parent.equals(other.parent))
+            return false;
+        if (definingResource == null) {
+            if (other.definingResource != null)
+                return false;
+        } else if (!definingResource.equals(other.definingResource))
+            return false;
+        return true;
+    }
+
 }
\ No newline at end of file