myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r231342 - in /myfaces: examples/trunk/simple/ examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/ tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/
Date Wed, 10 Aug 2005 22:33:27 GMT
Author: schof
Date: Wed Aug 10 15:33:20 2005
New Revision: 231342

URL: http://svn.apache.org/viewcvs?rev=231342&view=rev
Log:
tentative fix for expandAll problem

Modified:
    myfaces/examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/TreeBacker.java
    myfaces/examples/trunk/simple/tree2ExpandAll.jsp
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModel.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/UITreeData.java

Modified: myfaces/examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/TreeBacker.java
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/TreeBacker.java?rev=231342&r1=231341&r2=231342&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/TreeBacker.java
(original)
+++ myfaces/examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/TreeBacker.java
Wed Aug 10 15:33:20 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.myfaces.examples.tree;
 
+import org.apache.myfaces.custom.tree2.HtmlTree;
 import org.apache.myfaces.custom.tree2.TreeNode;
 import org.apache.myfaces.custom.tree2.TreeNodeBase;
 import org.apache.myfaces.custom.tree2.TreeModel;
@@ -29,14 +30,10 @@
 public class TreeBacker
 {
     private TreeModelBase _treeModel;
+    private HtmlTree _tree;
     
     public TreeNode getTreeData()
     {
-//        if (_treeModel != null)
-//        {
-//            return _treeModel;
-//        }
-        
         TreeNode treeData = new TreeNodeBase("foo-folder", "Inbox", false);
 
         // construct a set of fake data (normally your data would come from a database)
@@ -99,14 +96,34 @@
         personNode.getChildren().add(folderNode);
 
         treeData.getChildren().add(personNode);
-        
-//        _treeModel = new TreeModelBase(treeData);
 
         return treeData;
     }
     
+    /**
+     * NOTE: This is just to show an alternative way of supplying tree data.  You can supply
either a 
+     * TreeModel or TreeNode.
+     * 
+     * @return TreeModel
+     */
     public TreeModel getExpandedTreeData()
     {
         return new TreeModelBase(getTreeData());
+    }
+    
+    public void setTree(HtmlTree tree)
+    {
+        _tree = tree;
+    }
+    
+    public HtmlTree getTree()
+    {
+        return _tree;        
+    }
+    
+    public String expandAll()
+    {
+        _tree.expandAll();
+        return null;
     }
 }

Modified: myfaces/examples/trunk/simple/tree2ExpandAll.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/tree2ExpandAll.jsp?rev=231342&r1=231341&r2=231342&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/tree2ExpandAll.jsp (original)
+++ myfaces/examples/trunk/simple/tree2ExpandAll.jsp Wed Aug 10 15:33:20 2005
@@ -31,8 +31,11 @@
         <b>Tree2 w/expand all</b><br/>
     </span>
     <br/>
+
+    <h:commandLink value="Expand All" action="#{treeBacker.expandAll}"/>
+    <br/><br/>
     
-    <t:tree2 id="serverTree" value="#{treeBacker.expandedTreeData}" var="node" varNodeToggler="t"
clientSideToggle="false">
+    <t:tree2 id="serverTree" value="#{treeBacker.expandedTreeData}" var="node" varNodeToggler="t"
clientSideToggle="false" binding="#{treeBacker.tree}">
         <f:facet name="person">
             <h:panelGroup>
                 <h:commandLink immediate="true" action="#{t.toggleExpanded}">

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModel.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModel.java?rev=231342&r1=231341&r2=231342&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModel.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModel.java Wed Aug
10 15:33:20 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.myfaces.custom.tree2;
 
+import javax.faces.component.NamingContainer;
 import java.io.Serializable;
 
 
@@ -27,6 +28,11 @@
  */
 public interface TreeModel extends Serializable
 {
+    /**
+     * Separator char to be used in node path generation.
+     */
+    public final static String SEPARATOR = String.valueOf(NamingContainer.SEPARATOR_CHAR);
+    
     /**
      * Gets the current {@link TreeNode} or <code>null</code> if no node ID is
selected.
      * @return The current node

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java?rev=231342&r1=231341&r2=231342&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java Wed
Aug 10 15:33:20 2005
@@ -19,7 +19,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.faces.component.NamingContainer;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
 /**
@@ -35,8 +34,6 @@
 
     private static final long serialVersionUID = 3969414475396945742L;
     private static final Log log = LogFactory.getLog(TreeModelBase.class);    
-    private final static String SEPARATOR = String.valueOf(NamingContainer.SEPARATOR_CHAR);
-
    
     private TreeNode root;
     private TreeNode currentNode;

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/UITreeData.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/UITreeData.java?rev=231342&r1=231341&r2=231342&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/UITreeData.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/UITreeData.java Wed Aug
10 15:33:20 2005
@@ -402,6 +402,45 @@
         return _model;
     }
 
+    /**
+     * Epands all nodes by default.
+     * @param expandAll boolean
+     */
+    public void expandAll()
+    {
+        String currentNodeId = _nodeId;
+
+        int kidId = 0;
+        expandEverything(null, kidId++);
+        setNodeId(currentNodeId);
+    }
+    
+    /**
+     * Private helper method that recursviely expands all of the nodes.
+     *
+     * @param parentId The id of the parent node (if applicable)
+     * @param childCount The child number of the node to expand (will be incremented as you
recurse.)
+     */
+    private void expandEverything(String parentId, int childCount)
+    {
+        String nodeId = (parentId != null) ? parentId + TreeModel.SEPARATOR + childCount
: "0";    
+        setNodeId(nodeId);
+
+        TreeNode node = getDataModel().getNode();
+        
+        if (!node.isLeaf() && !isNodeExpanded())
+        {
+            getDataModel().getTreeState().toggleExpanded(nodeId);
+        }
+
+        List children = getNode().getChildren();
+        for (int kount=0; kount < children.size(); kount++)
+        {
+            expandEverything(nodeId, kount);
+        }
+    }
+    
+
     private void processNodes(FacesContext context, int processAction, String parentId, int
childLevel)
     {
         UIComponent facet = null;



Mime
View raw message