ref #7086 Add property and label to character details view
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / FeatureNodeContainerTree.java
index 55bf93082f58db1c48704d7f93d10dec583481da..c337da240874145b48b0f44445a47ff28d4c69de 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * 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.
 */
@@ -37,25 +37,32 @@ public class FeatureNodeContainerTree {
 
                @Override
                public int compare(DescriptionElementBase o1, DescriptionElementBase o2) {
-                       return DescriptionHelper.getLabel(o1).compareTo(DescriptionHelper.getLabel(o2));
+                   if (o1.equals(o2)){
+                       return 0;
+                   }
+                       int result = DescriptionHelper.getLabel(o1).compareTo(DescriptionHelper.getLabel(o2));
+                       if (result == 0){
+                           return o1.getUuid().compareTo(o2.getUuid());
+                       }
+                       return result;
                }
        };
-       
+
        private Set<FeatureNodeContainer> featureNodeContainers = new HashSet<FeatureNodeContainer>();
-       
+
        private FeatureNodeContainer root;
        private DescriptionBase description;
        private FeatureTree featureTree;
-       
+
        public FeatureNodeContainerTree(DescriptionBase description, FeatureTree featureTree){
                this.description = description;
                this.featureTree = featureTree;
-               
+
                root = new FeatureNodeContainer(this);
-               
+
                buildTree();
        }
-       
+
        /**
         * Traverses the given {@link FeatureNode} and computes a FeatureNodeContainer branch if the
         * given {@link TaxonDescription} has elements for the given feature node or any of its children
@@ -63,16 +70,16 @@ public class FeatureNodeContainerTree {
         */
        public void buildTree(){
                List<FeatureNode> children = featureTree.getRootChildren();
-               
+
 //             if(description.getElements().isEmpty()){
 //                     return;
 //             }
-               
+
                for(FeatureNode featureNode : children){
                        root.findLeaves(featureNode);
                }
        }
-       
+
        /**
         * <p>getFeatureNodeContainerForDescriptionElement</p>
         *
@@ -81,7 +88,7 @@ public class FeatureNodeContainerTree {
         */
        public FeatureNodeContainer getFeatureNodeContainerForDescriptionElement (DescriptionElementBase descriptionElement) {
                List<FeatureNodeContainer> leafs = root.getLeafs();
-               
+
                for(FeatureNodeContainer container : leafs){
                        if(container.getDescriptionElements().contains(descriptionElement)){
                                return container;
@@ -89,40 +96,40 @@ public class FeatureNodeContainerTree {
                }
                return null;
        }
-       
+
        /**
         * Returns all elements contained in the given {@link DescriptionBase description} that have the given {@link Feature feature}.
-        * 
+        *
         * @param description
         * @param feature
         * @return a list of description elements with the given feature alphabetically sorted by {@link DescriptionHelper#getLabel(Object)}
         */
        public List<DescriptionElementBase> getDescriptionsElementsForFeature(Feature feature) {
                List<DescriptionElementBase> featureElements = new ArrayList<DescriptionElementBase>();
-               
+
                Set<DescriptionElementBase> elements = description.getElements();
-               
+
                if (elements != null) {
                        for (DescriptionElementBase element : elements) {
-                               Feature elementFeature = (Feature) HibernateProxyHelper.deproxy(element.getFeature());
-                               
+                               Feature elementFeature = HibernateProxyHelper.deproxy(element.getFeature());
+
                                if (feature.equals(elementFeature)) {
                                        featureElements.add(element);
                                }
                        }
                }
-               
+
                if(featureElements.size() != 0){
                        Collections.sort(featureElements, comparator);
                }
-               
+
                return featureElements;
        }
-       
-       
-       public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {          
+
+
+       public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {
                List<FeatureNodeContainer> leafs = root.getLeafs();
-               
+
                for(FeatureNodeContainer container : leafs){
                        if(container.getFeature().equals(feature)){
                                return container;
@@ -130,10 +137,10 @@ public class FeatureNodeContainerTree {
                }
                return null;
        }
-       
+
        public FeatureNodeContainer getFeatureNodeContainer(FeatureNode featureNode){
                List<FeatureNodeContainer> leafs = root.getLeafs();
-               
+
                for(FeatureNodeContainer container : leafs){
                        if(container.getFeatureNode().equals(featureNode)){
                                return container;
@@ -141,18 +148,18 @@ public class FeatureNodeContainerTree {
                }
                return null;
        }
-       
+
        public void addContainer(FeatureNodeContainer container){
                featureNodeContainers.add(container);
        }
 
        /**
-        * 
+        *
         */
        public void removeContainer(FeatureNodeContainer container) {
                featureNodeContainers.remove(container);
        }
-       
+
        public FeatureNodeContainer getRoot() {
                return root;
        }
@@ -164,5 +171,5 @@ public class FeatureNodeContainerTree {
        public FeatureTree getFeatureTree() {
                return featureTree;
        }
-       
+
 }