Fix flow tree display
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 31 Jul 2009 10:36:04 +0000 (10:36 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 31 Jul 2009 10:36:04 +0000 (10:36 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2847 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlowDescriptor.java

index 0d88c96fde2fddd28c2c1d1e04829765b7c64bb4..e41c8c84c82dff333498f97adfb685d02ed24694 100644 (file)
@@ -172,14 +172,21 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean,
                                                .getAttributes().get(key).getValue() != null);
        }
 
+       @Override
        public String toString() {
-               return new StringBuffer("Flow ").append(name).toString();
+               return new StringBuffer("Execution flow ").append(name).toString();
        }
 
+       @Override
        public boolean equals(Object obj) {
                return ((ExecutionFlow) obj).getName().equals(name);
        }
 
+       @Override
+       public int hashCode() {
+               return name.hashCode();
+       }
+
        public String getPath() {
                return path;
        }
index 1ff50e0db9c0f1c7caf8d54f0993ba7458197798..2d2d28babbddb5cd8f84ad1d8b361299a275504f 100644 (file)
@@ -218,9 +218,17 @@ public class DefaultExecutionFlowDescriptorConverter implements
                        Comparator<ExecutionFlowDescriptor> {
                public int compare(ExecutionFlowDescriptor o1,
                                ExecutionFlowDescriptor o2) {
+                       // TODO: write unit tests for this
                        if (StringUtils.hasText(o1.getPath())
                                        && StringUtils.hasText(o2.getPath())) {
-                               return o1.getPath().compareTo(o2.getPath());
+                               if (o1.getPath().equals(o2.getPath()))
+                                       return o1.getName().compareTo(o2.getName());
+                               else if (o1.getPath().startsWith(o2.getPath()))
+                                       return -1;
+                               else if (o2.getPath().startsWith(o1.getPath()))
+                                       return 1;
+                               else
+                                       return o1.getPath().compareTo(o2.getPath());
                        } else if (!StringUtils.hasText(o1.getPath())
                                        && StringUtils.hasText(o2.getPath())) {
                                return 1;
index f63703c88e45f27c760083ad441dc5a49bad2f55..89f0eac94b0dfb7b7bbc0532cd3f87a6743a3e6d 100644 (file)
@@ -59,4 +59,16 @@ public class ExecutionFlowDescriptor {
                this.description = description;
        }
 
+       @Override
+       public boolean equals(Object obj) {
+               if (obj instanceof ExecutionFlowDescriptor)
+                       return name.equals(((ExecutionFlowDescriptor) obj).getName());
+               return false;
+       }
+
+       @Override
+       public int hashCode() {
+               return name.hashCode();
+       }
+
 }