Introduce path in TreeParent so that equals makes more sense
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Aug 2012 14:33:54 +0000 (14:33 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Aug 2012 14:33:54 +0000 (14:33 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5525 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/TreeParent.java

index 26bdbe615135a0bd9a6b0a76ad6280623c07de84..09f8b2b2beb3c43cc7be0f8f3b49c264fa8da418 100644 (file)
@@ -25,6 +25,12 @@ public class TreeParent {
 
        private List<Object> children;
 
+       /**
+        * Unique id within the context of a tree display. If set, equals() and
+        * hashCode() methods will be based on it
+        */
+       private String path = null;
+
        /** False until at least one child has been added, then true until cleared */
        private boolean loaded = false;
 
@@ -105,6 +111,10 @@ public class TreeParent {
 
        public void setParent(TreeParent parent) {
                this.parent = parent;
+               if (parent != null && parent.path != null)
+                       this.path = parent.path + '/' + name;
+               else
+                       this.path = '/' + name;
        }
 
        public TreeParent getParent() {
@@ -121,12 +131,18 @@ public class TreeParent {
 
        @Override
        public int hashCode() {
-               return name.hashCode();
+               if (path != null)
+                       return path.hashCode();
+               else
+                       return name.hashCode();
        }
 
        @Override
        public boolean equals(Object obj) {
-               return name.equals(obj.toString());
+               if (path != null && obj instanceof TreeParent)
+                       return path.equals(((TreeParent) obj).path);
+               else
+                       return name.equals(obj.toString());
        }
 
 }