You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sc...@apache.org on 2005/08/04 05:03:35 UTC

svn commit: r227295 - in /myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2: HtmlTreeRenderer.java TreeNodeBase.java

Author: schof
Date: Wed Aug  3 20:03:32 2005
New Revision: 227295

URL: http://svn.apache.org/viewcvs?rev=227295&view=rev
Log:
Additional changes related to MYFACES-350

Modified:
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeNodeBase.java

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java?rev=227295&r1=227294&r2=227295&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java Wed Aug  3 20:03:32 2005
@@ -384,7 +384,7 @@
         UIComponent nodeImgFacet = null;
 
         int bitMask = NOTHING;
-        bitMask += (node.isLeaf() || node.getChildCount() == 0) ? NOTHING : CHILDREN;
+        bitMask += (node.isLeaf()) ? NOTHING : CHILDREN;
         bitMask += (tree.isNodeExpanded()) ? EXPANDED : NOTHING;
         bitMask += (tree.isLastChild(tree.getNodeId())) ? LAST : NOTHING;
         bitMask += (showLines) ? LINES : NOTHING;

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeNodeBase.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeNodeBase.java?rev=227295&r1=227294&r2=227295&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeNodeBase.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeNodeBase.java Wed Aug  3 20:03:32 2005
@@ -16,21 +16,23 @@
 
 package org.apache.myfaces.custom.tree2;
 
+
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Collections;
 
-public class TreeNodeBase implements TreeNode
+public class TreeNodeBase implements TreeNode, Comparable
 {
     private static final long serialVersionUID = 278589014441538822L;
     private ArrayList children = new ArrayList();
     private String type;
     private String description;
-    private boolean leaf;    
+    private boolean leaf;
     private String identifier;
 
     public TreeNodeBase()
     {}
-    
+
     public TreeNodeBase(String type, String description, boolean leaf)
     {
         this(type, description, null, leaf);
@@ -46,9 +48,9 @@
 
     public boolean isLeaf()
     {
-        return leaf;
+        return leaf || (getChildCount() == 0);
     }
-    
+
     public void setLeaf(boolean leaf)
     {
         this.leaf = leaf;
@@ -66,31 +68,53 @@
 
     public void setType(String type)
     {
-        this.type = type;           
-    }    
-    
+        this.type = type;
+    }
+
     public void setDescription(String description)
     {
         this.description = description;
     }
-    
+
     public String getDescription()
     {
         return description;
     }
-    
+
     public void setIdentifier(String identifier)
     {
         this.identifier = identifier;
     }
-    
+
     public String getIdentifier()
     {
         return identifier;
     }
-    
+
     public int getChildCount()
     {
         return getChildren().size();
+    }
+
+    public int compareTo(Object obj)
+    {
+        // branches come before leaves, after this criteria nodes are sorted alphabetically
+        TreeNode otherNode = (TreeNode)obj;
+
+        if (isLeaf() && !otherNode.isLeaf())
+        {
+            // leaves come after branches
+            return 1;
+        }
+        else if (!isLeaf() && otherNode.isLeaf())
+        {
+            // branches come before leaves
+            return -1;
+        }
+        else
+        {
+            // both nodes are leaves or both node are branches, so compare the descriptions
+            return getDescription().compareTo(otherNode.getDescription());
+        }
     }
 }