Merge branch 'develop' of ssh://dev.e-taxonomy.eu/var/git/taxeditor into develop
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / FeatureNodeContainer.java
index 900665e9e54e599c08c09e78cc862039c3863490..6a5316169bf69b911df49d55f84a375fcf721727 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -17,8 +16,8 @@ import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
-import eu.etaxonomy.cdm.model.description.FeatureNode;
-import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.term.FeatureNode;
+import eu.etaxonomy.cdm.model.term.FeatureTree;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 
 /**
@@ -35,62 +34,62 @@ import eu.etaxonomy.cdm.model.description.TaxonDescription;
  * @version 1.0
  */
 public class FeatureNodeContainer{
-       
-       
-       
+
+
+
        private FeatureNodeContainer parent;
-       
 
 
-       private FeatureNode featureNode;
+
+       private FeatureNode<Feature> featureNode;
        private List<FeatureNodeContainer> children = new ArrayList<FeatureNodeContainer>();
        private List<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
 
        private FeatureNodeContainerTree containerTree;
 
-       
+
        /**
         * @param description
         */
        protected FeatureNodeContainer(FeatureNodeContainerTree containerTree) {
-               this.containerTree = containerTree; 
+               this.containerTree = containerTree;
                this.containerTree.addContainer(this);
        }
-       
-       
+
+
        /**
-        * Recursively traverse a branch of a feature tree and check if there are 
-        * 
+        * Recursively traverse a branch of a feature tree and check if there are
+        *
         * @param featureNode
-        * @param description 
+        * @param description
         * @return
         */
-       protected void findLeaves(FeatureNode featureNode) {
+       protected void findLeaves(FeatureNode<Feature> featureNode) {
                if(featureNode.isLeaf()){
                        buildLeaf(featureNode);
                }else{
-                       for(FeatureNode childNode : featureNode.getChildren()){
+                       for(FeatureNode<Feature> childNode : featureNode.getChildNodes()){
                                findLeaves(childNode);
                        }
                }
        }
-       
+
        /**
-        * 
+        *
         * @param featureNode
         * @param description
         * @return
         */
-       private void buildLeaf(FeatureNode featureNode){
-               if(featureNode.getFeature() == null){
+       private void buildLeaf(FeatureNode<Feature> featureNode){
+               if(featureNode.getTerm() == null){
                        throw new IllegalArgumentException("The given feature node does not have a feature.");
                }
-               
-               Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
-               
+
+               Feature feature = HibernateProxyHelper.deproxy(featureNode.getTerm());
+
                // get feature node container for the given feature
                FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
-               
+
                // get description elements for the given feature
                List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(feature);
                // no description elements, so we should also remove the feature node container
@@ -108,12 +107,12 @@ public class FeatureNodeContainer{
                                container.buildBranch();
                        }
                        // add description elements to the feature node container
-                       container.setDescriptionElements(elements);             
+                       container.setDescriptionElements(elements);
                }
        }
-       
+
        /**
-        * 
+        *
         */
        private void remove() {
                if(getParent() != null){
@@ -134,15 +133,15 @@ public class FeatureNodeContainer{
 
 
        /**
-        * Recursively 
-        * 
+        * Recursively
+        *
         * @param featureNodeMap
         * @return
         */
-       private void buildBranch(){     
+       private void buildBranch(){
                if(getParent() == null){
-                       FeatureNode parentFeatureNode = getFeatureNode().getParent();
-                       
+                       FeatureNode<Feature> parentFeatureNode = getFeatureNode().getParent();
+
                        if(parentFeatureNode.isRoot()){
                                containerTree.getRoot().addChild(this);
                        }else{
@@ -151,15 +150,15 @@ public class FeatureNodeContainer{
                                        parentContainer = new FeatureNodeContainer(containerTree);
                                        parentContainer.setFeatureNode(parentFeatureNode);
                                }
-                               
+
                                parentContainer.addChild(this);
-                               
+
                                parentContainer.buildBranch();
-                               
+
                        }
                }
        }
-       
+
        /**
         * <p>Getter for the field <code>children</code>.</p>
         *
@@ -182,7 +181,7 @@ public class FeatureNodeContainer{
                        throw new IllegalStateException("Container may not have a description element set when setting children.");
                }
        }
-       
+
        /**
         * Adds a child container to the list of this containers children
         *
@@ -201,11 +200,11 @@ public class FeatureNodeContainer{
        public void addDescriptionElement(DescriptionElementBase descriptionElement){
                descriptionElements.add(descriptionElement);
        }
-       
+
        public void removeDescriptionElement(DescriptionElementBase descriptionElement){
                descriptionElements.remove(descriptionElement);
        }
-       
+
        /**
         * If {@link #isLeaf()} is true, i.e. this container should have elements, returns the list of description elements.
         *
@@ -225,7 +224,7 @@ public class FeatureNodeContainer{
        public List<DescriptionElementBase> getDescriptionElementsForEntireBranch(){
                return getDescriptionElementsRecursively(new ArrayList<DescriptionElementBase>());
        }
-       
+
        private List<DescriptionElementBase> getDescriptionElementsRecursively(List<DescriptionElementBase> descriptionElements){
                if(isLeaf()){
                        descriptionElements.addAll(getDescriptionElements());
@@ -236,20 +235,20 @@ public class FeatureNodeContainer{
                }
                return descriptionElements;
        }
-       
+
        protected List<FeatureNodeContainer> getLeafs(){
                List<FeatureNodeContainer> leafs = new ArrayList<FeatureNodeContainer>();
-               
+
                if(isLeaf()){
                        leafs.add(this);
                }else{
                        for(FeatureNodeContainer container : getChildren()){
                                leafs.addAll(container.getLeafs());
-                       }                       
+                       }
                }
                return leafs;
        }
-       
+
        /**
         * Set the description element
         *
@@ -263,7 +262,7 @@ public class FeatureNodeContainer{
                        throw new IllegalStateException("Container may not contain child container when adding description elements.");
                }
        }
-       
+
        /**
         * If the container is a leaf, it will hold a description element and no child containers
         *
@@ -272,25 +271,25 @@ public class FeatureNodeContainer{
        public boolean isLeaf(){
                return ! descriptionElements.isEmpty() && children.isEmpty();
        }
-       
+
        /**
         * <p>Setter for the field <code>featureNode</code>.</p>
         *
-        * @param featureNode a {@link eu.etaxonomy.cdm.model.description.FeatureNode} object.
+        * @param featureNode a {@link eu.etaxonomy.cdm.model.term.FeatureNode} object.
         */
-       public void setFeatureNode(FeatureNode featureNode) {
+       public void setFeatureNode(FeatureNode<Feature> featureNode) {
                this.featureNode = featureNode;
        }
 
        /**
         * <p>Getter for the field <code>featureNode</code>.</p>
         *
-        * @return a {@link eu.etaxonomy.cdm.model.description.FeatureNode} object.
+        * @return a {@link eu.etaxonomy.cdm.model.term.FeatureNode} object.
         */
-       public FeatureNode getFeatureNode() {
+       public FeatureNode<Feature> getFeatureNode() {
                return featureNode;
        }
-       
+
        /**
         * <p>getFeature</p>
         *
@@ -298,7 +297,7 @@ public class FeatureNodeContainer{
         */
        public Feature getFeature(){
                if(featureNode != null){
-                       return featureNode.getFeature();
+                       return featureNode.getTerm();
                }
                return null;
        }
@@ -311,14 +310,14 @@ public class FeatureNodeContainer{
        public DescriptionBase getDescription(){
                return containerTree.getDescription();
        }
-       
+
        public FeatureNodeContainerTree getContainerTree(){
                return containerTree;
        }
 
 
        /**
-        * 
+        *
         */
        public void clear() {
                children.clear();