1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.requests;
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;
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;
26 * @author Tuukka Lehtonen
28 public class Node implements Comparable<Node> {
30 public static final Comparator<Node> CASE_INSENSITIVE_COMPARATOR = new Comparator<Node>() {
32 public int compare(Node o1, Node o2) {
33 return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName());
37 private final Node parent;
38 private final List<Node> children = new ArrayList<Node>();
41 * May be <code>null</code> if there is no diagram for this node.
43 private final Resource diagram;
44 private final ResourceArray definingResource; // i.e. Composite
45 private final String name;
47 // private String[] partOfGroups = {};
49 private PageDesc pageDesc;
55 * @param diagram may be <code>null</code> if there is no diagram for this node
56 * @param definingResources
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");
63 this.diagram = diagram;
64 this.definingResource = new ResourceArray(definingResources);
67 parent.addChild(this);
70 public Node getParent() {
75 * @return <code>null</code> if there is no diagram for this node
77 public Resource getDiagramResource() {
81 public ResourceArray getDefiningResources() {
82 return definingResource;
85 public String getName() {
90 public String toString() {
91 return (parent != null ? parent : "") + "/" + name + definingResource;
94 public void addChild(Node child) {
98 public void removeChild(Node child) {
99 children.remove(child);
102 public Collection<Node> getChildren() {
103 return Collections.unmodifiableCollection(children);
106 // public void setPartOfGroups(Collection<String> groups) {
107 // this.partOfGroups = groups.toArray(new String[groups.size()]);
110 // public String[] getPartOfGroups() {
111 // return partOfGroups;
114 public void setPageDesc(PageDesc pageDesc) {
115 this.pageDesc = pageDesc;
118 public void setRVI(String RVI) {
122 public String getRVI() {
126 public PageDesc getPageDesc() {
131 public int compareTo(Node o) {
132 int ret = name.compareTo(o.name);
137 public int hashCode() {
138 final int prime = 31;
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());
147 public boolean equals(Object obj) {
152 if (getClass() != obj.getClass())
154 Node other = (Node) obj;
155 if (diagram == null) {
156 if (other.diagram != null)
158 } else if (!diagram.equals(other.diagram))
160 if (parent == null) {
161 if (other.parent != null)
163 } else if (!parent.equals(other.parent))
165 if (definingResource == null) {
166 if (other.definingResource != null)
168 } else if (!definingResource.equals(other.definingResource))