]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java
Revert "Default property editing restores assertions"
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / requests / Node.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.modeling.requests;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Comparator;
18 import java.util.List;
19
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.ResourceArray;
22 import org.simantics.utils.page.PageDesc;
23 import org.simantics.utils.strings.AlphanumComparator;
24
25 /**
26  * @author Tuukka Lehtonen
27  */
28 public class Node implements Comparable<Node> {
29
30     public static final Comparator<Node> CASE_INSENSITIVE_COMPARATOR = new Comparator<Node>() {
31         @Override
32         public int compare(Node o1, Node o2) {
33             return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName());
34         }
35     };
36
37     private final Node       parent;
38     private final List<Node> children = new ArrayList<Node>();
39
40     /**
41      * May be <code>null</code> if there is no diagram for this node.
42      */
43     private final Resource         diagram;
44     private final ResourceArray    definingResource; // i.e. Composite
45     private final String           name;
46
47 //    private String[]         partOfGroups = {};
48
49     private PageDesc         pageDesc;
50     private String           RVI;
51
52     /**
53      * @param parent
54      * @param name
55      * @param diagram may be <code>null</code> if there is no diagram for this node
56      * @param definingResources
57      */
58     public Node(Node parent, String name, Resource diagram, Resource... definingResources) {
59         if (definingResources.length == 0)
60             throw new IllegalArgumentException("must provide at least one defining resource");
61         this.parent = parent;
62         this.name = name;
63         this.diagram = diagram;
64         this.definingResource = new ResourceArray(definingResources);
65
66         if (parent != null)
67             parent.addChild(this);
68     }
69
70     public Node getParent() {
71         return parent;
72     }
73
74     /**
75      * @return <code>null</code> if there is no diagram for this node
76      */
77     public Resource getDiagramResource() {
78         return diagram;
79     }
80
81     public ResourceArray getDefiningResources() {
82         return definingResource;
83     }
84
85     public String getName() {
86         return name;
87     }
88
89     @Override
90     public String toString() {
91         return (parent != null ? parent : "") + "/" + name + definingResource;
92     }
93
94     public void addChild(Node child) {
95         children.add(child);
96     }
97
98     public void removeChild(Node child) {
99         children.remove(child);
100     }
101
102     public Collection<Node> getChildren() {
103         return Collections.unmodifiableCollection(children);
104     }
105
106 //    public void setPartOfGroups(Collection<String> groups) {
107 //        this.partOfGroups = groups.toArray(new String[groups.size()]);
108 //    }
109 //
110 //    public String[] getPartOfGroups() {
111 //        return partOfGroups;
112 //    }
113
114     public void setPageDesc(PageDesc pageDesc) {
115         this.pageDesc = pageDesc;
116     }
117     
118     public void setRVI(String RVI) {
119         this.RVI = RVI;
120     }
121     
122     public String getRVI() {
123         return RVI;
124     }
125
126     public PageDesc getPageDesc() {
127         return pageDesc;
128     }
129
130     @Override
131     public int compareTo(Node o) {
132         int ret = name.compareTo(o.name);
133         return ret;
134     }
135
136     @Override
137     public int hashCode() {
138         final int prime = 31;
139         int result = 1;
140         result = prime * result + ((diagram == null) ? 0 : diagram.hashCode());
141         result = prime * result + ((parent == null) ? 0 : parent.hashCode());
142         result = prime * result + ((definingResource == null) ? 0 : definingResource.hashCode());
143         return result;
144     }
145
146     @Override
147     public boolean equals(Object obj) {
148         if (this == obj)
149             return true;
150         if (obj == null)
151             return false;
152         if (getClass() != obj.getClass())
153             return false;
154         Node other = (Node) obj;
155         if (diagram == null) {
156             if (other.diagram != null)
157                 return false;
158         } else if (!diagram.equals(other.diagram))
159             return false;
160         if (parent == null) {
161             if (other.parent != null)
162                 return false;
163         } else if (!parent.equals(other.parent))
164             return false;
165         if (definingResource == null) {
166             if (other.definingResource != null)
167                 return false;
168         } else if (!definingResource.equals(other.definingResource))
169             return false;
170         return true;
171     }
172
173 }