--- /dev/null
+/*******************************************************************************\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
+}
\ No newline at end of file