X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Frequests%2FNode.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Frequests%2FNode.java;h=bdc3a97ddb2dbd3638e28e7207935cbbe7e50054;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java new file mode 100644 index 000000000..bdc3a97dd --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/requests/Node.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * 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 { + + public static final Comparator CASE_INSENSITIVE_COMPARATOR = new Comparator() { + @Override + public int compare(Node o1, Node o2) { + return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getName(), o2.getName()); + } + }; + + private final Node parent; + private final List children = new ArrayList(); + + /** + * May be null if there is no diagram for this node. + */ + private final Resource diagram; + private final ResourceArray definingResource; // i.e. Composite + private final String name; + +// private String[] partOfGroups = {}; + + private PageDesc pageDesc; + private String RVI; + + /** + * @param parent + * @param name + * @param diagram may be null 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 getParent() { + return parent; + } + + /** + * @return null 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 getChildren() { + return Collections.unmodifiableCollection(children); + } + +// public void setPartOfGroups(Collection groups) { +// this.partOfGroups = groups.toArray(new String[groups.size()]); +// } +// +// public String[] getPartOfGroups() { +// return partOfGroups; +// } + + 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