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 22:29:00 UTC

svn commit: r227470 - in /myfaces: examples/trunk/simple/ examples/trunk/simple/WEB-INF/ examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/ tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/

Author: schof
Date: Thu Aug  4 13:28:49 2005
New Revision: 227470

URL: http://svn.apache.org/viewcvs?rev=227470&view=rev
Log:
Fixes MYFACES-353 and MYFACES-390 (provides an expandAll method for TreeModelBase.)

Added:
    myfaces/examples/trunk/simple/tree2ExpandAll.jsp
Modified:
    myfaces/examples/trunk/simple/WEB-INF/examples-config.xml
    myfaces/examples/trunk/simple/home.jsp
    myfaces/examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/TreeBacker.java
    myfaces/examples/trunk/simple/tree2.jsp
    myfaces/examples/trunk/simple/tree2HideRoot.jsp
    myfaces/examples/trunk/simple/tree2NiceWrap.jsp
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java
    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/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/WEB-INF/examples-config.xml?rev=227470&r1=227469&r2=227470&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/WEB-INF/examples-config.xml (original)
+++ myfaces/examples/trunk/simple/WEB-INF/examples-config.xml Thu Aug  4 13:28:49 2005
@@ -113,12 +113,40 @@
     </managed-bean>
 
     <!-- Managed Beans for tree2.jsp -->
-
+    <!-- 
+    NOTE: There are several copies of the same bean so that each example can share the yet maintainin its own 
+    copy of the expanded state (which is handled by the model.)  Otherwise the expanded state of one example 
+    is reflected in another example (which is correct but confusing to the user.)
+    -->
     <managed-bean>
         <managed-bean-name>treeBacker</managed-bean-name>
         <managed-bean-class>org.apache.myfaces.examples.tree.TreeBacker</managed-bean-class>
-        <managed-bean-scope>request</managed-bean-scope>
+        <managed-bean-scope>session</managed-bean-scope>
+    </managed-bean>
+
+    <managed-bean>
+        <managed-bean-name>treeBacker2</managed-bean-name>
+        <managed-bean-class>org.apache.myfaces.examples.tree.TreeBacker</managed-bean-class>
+        <managed-bean-scope>session</managed-bean-scope>
     </managed-bean>
+    
+    <managed-bean>
+        <managed-bean-name>treeBacker3</managed-bean-name>
+        <managed-bean-class>org.apache.myfaces.examples.tree.TreeBacker</managed-bean-class>
+        <managed-bean-scope>session</managed-bean-scope>
+    </managed-bean>    
+    
+    <managed-bean>
+        <managed-bean-name>treeBacker4</managed-bean-name>
+        <managed-bean-class>org.apache.myfaces.examples.tree.TreeBacker</managed-bean-class>
+        <managed-bean-scope>session</managed-bean-scope>
+    </managed-bean>    
+    
+    <managed-bean>
+        <managed-bean-name>treeBacker5</managed-bean-name>
+        <managed-bean-class>org.apache.myfaces.examples.tree.TreeBacker</managed-bean-class>
+        <managed-bean-scope>session</managed-bean-scope>
+    </managed-bean>    
 
     <!-- Managed Beans for forceId.jsp -->
 

Modified: myfaces/examples/trunk/simple/home.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/home.jsp?rev=227470&r1=227469&r2=227470&view=diff
==============================================================================
Binary files - no diff available.

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=227470&r1=227469&r2=227470&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 Thu Aug  4 13:28:49 2005
@@ -17,6 +17,8 @@
 
 import org.apache.myfaces.custom.tree2.TreeNode;
 import org.apache.myfaces.custom.tree2.TreeNodeBase;
+import org.apache.myfaces.custom.tree2.TreeModel;
+import org.apache.myfaces.custom.tree2.TreeModelBase;
 
 /**
  * Backer bean for use in example.  Basically makes a TreeNode available.
@@ -26,8 +28,15 @@
  */
 public class TreeBacker
 {
-    public TreeNode getTreeData()
+    private TreeModelBase _treeModel;
+    
+    public TreeModel 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)
@@ -90,7 +99,17 @@
         personNode.getChildren().add(folderNode);
 
         treeData.getChildren().add(personNode);
+        
+        _treeModel = new TreeModelBase(treeData);
 
-        return treeData;
+        return _treeModel;
+    }
+    
+    public TreeModel getExpandedTreeData()
+    {
+        TreeModelBase expandedModel = (TreeModelBase)getTreeData();
+        expandedModel.setExpandAll(true);
+        
+        return expandedModel;
     }
 }

Modified: myfaces/examples/trunk/simple/tree2.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/tree2.jsp?rev=227470&r1=227469&r2=227470&view=diff
==============================================================================
Binary files - no diff available.

Added: myfaces/examples/trunk/simple/tree2ExpandAll.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/tree2ExpandAll.jsp?rev=227470&view=auto
==============================================================================
--- myfaces/examples/trunk/simple/tree2ExpandAll.jsp (added)
+++ myfaces/examples/trunk/simple/tree2ExpandAll.jsp Thu Aug  4 13:28:49 2005
@@ -0,0 +1,83 @@
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
+
+<!--
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//-->
+<html>
+
+<%@include file="inc/head.inc" %>
+
+<body>
+
+<f:view>
+
+    <span style="font-family:verdana">
+        <b>Tree2 w/expand all</b><br/>
+    </span>
+    <br/>
+    
+    <x:tree2 id="serverTree" value="#{treeBacker5.expandedTreeData}" var="node" varNodeToggler="t" clientSideToggle="false">
+        <f:facet name="person">
+            <h:panelGroup>
+                <h:commandLink immediate="true" action="#{t.toggleExpanded}">
+                    <x:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
+                    <x:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
+                </h:commandLink>
+                <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
+            </h:panelGroup>
+        </f:facet>
+        <f:facet name="foo-folder">
+            <h:panelGroup>
+                <h:commandLink immediate="true" action="#{t.toggleExpanded}">
+                    <x:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
+                    <x:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
+                </h:commandLink>
+                <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
+                <h:outputText value=" (#{node.childCount})" styleClass="childCount" rendered="#{!empty node.children}"/>
+            </h:panelGroup>
+        </f:facet>
+        <f:facet name="bar-folder">
+            <h:panelGroup>
+                <h:commandLink immediate="true" action="#{t.toggleExpanded}">
+                    <x:graphicImage value="/images/blue-folder-open.gif" rendered="#{t.nodeExpanded}" border="0"/>
+                    <x:graphicImage value="/images/blue-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
+                </h:commandLink>
+                <h:outputText value="#{node.description}" styleClass="nodeFolder"/>
+                <h:outputText value=" (#{node.childCount})" styleClass="childCount" rendered="#{!empty node.children}"/>
+            </h:panelGroup>
+        </f:facet>
+        <f:facet name="document">
+            <h:panelGroup>
+                <h:commandLink immediate="true" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}" actionListener="#{t.setNodeSelected}">
+                    <x:graphicImage value="/images/document.png" border="0"/>
+                    <h:outputText value="#{node.description}"/>
+                    <f:param name="docNum" value="#{node.identifier}"/>
+                </h:commandLink>
+            </h:panelGroup>
+        </f:facet>
+    </x:tree2>
+
+</f:view>
+
+<%@include file="inc/page_footer.jsp" %>
+
+</body>
+
+</html>
+

Modified: myfaces/examples/trunk/simple/tree2HideRoot.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/tree2HideRoot.jsp?rev=227470&r1=227469&r2=227470&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/tree2HideRoot.jsp (original)
+++ myfaces/examples/trunk/simple/tree2HideRoot.jsp Thu Aug  4 13:28:49 2005
@@ -32,7 +32,7 @@
     </span>
     <br/>
 
-    <x:tree2 id="clientTree" value="#{treeBacker.treeData}" var="node" varNodeToggler="t" showRootNode="false">
+    <x:tree2 id="clientTree" value="#{treeBacker3.treeData}" var="node" varNodeToggler="t" showRootNode="false">
         <f:facet name="person">
             <h:panelGroup>
                 <f:facet name="expand">

Modified: myfaces/examples/trunk/simple/tree2NiceWrap.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/tree2NiceWrap.jsp?rev=227470&r1=227469&r2=227470&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/tree2NiceWrap.jsp (original)
+++ myfaces/examples/trunk/simple/tree2NiceWrap.jsp Thu Aug  4 13:28:49 2005
@@ -33,9 +33,9 @@
     <br/>
 
     <h:panelGrid width="200">
-        <x:tree2 id="wrapTree" value="#{treeBacker.treeData}" var="node" varNodeToggler="t" clientSideToggle="false">
+        <x:tree2 id="wrapTree" value="#{treeBacker4.treeData}" var="node" varNodeToggler="t" clientSideToggle="false">
             <f:facet name="person">
-                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
+                <h:panelGrid id="a" columns="2" cellpadding="0" cellspacing="0">
                     <h:commandLink immediate="true" action="#{t.toggleExpanded}">
                         <x:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
                         <x:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
@@ -44,7 +44,7 @@
                 </h:panelGrid>
             </f:facet>
             <f:facet name="foo-folder">
-                <h:panelGrid columns="2" cellpadding="2" cellspacing="0">
+                <h:panelGrid id="b" columns="2" cellpadding="2" cellspacing="0">
                     <h:commandLink immediate="true" action="#{t.toggleExpanded}">
                         <x:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0"/>
                         <x:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>
@@ -56,7 +56,7 @@
                 </h:panelGrid>
             </f:facet>
             <f:facet name="bar-folder">
-                <h:panelGrid columns="2" cellpadding="2" cellspacing="0">
+                <h:panelGrid id="c" columns="2" cellpadding="2" cellspacing="0">
                     <h:commandLink immediate="true" action="#{t.toggleExpanded}">
                         <x:graphicImage value="/images/blue-folder-open.gif" rendered="#{t.nodeExpanded}" border="0"/>
                         <x:graphicImage value="/images/blue-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0"/>

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java?rev=227470&r1=227469&r2=227470&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java Thu Aug  4 13:28:49 2005
@@ -40,7 +40,7 @@
     private static final String NODE_STATE_KEY = "org.apache.myfaces.tree.NODE_STATE_KEY";
     private UICommand _expandControl;
     private String _varNodeToggler;
-    private HashSet _expandedNodes = new HashSet();
+//    private HashSet _expandedNodes = new HashSet();
     private String _selectedNodeId;
 
     /**
@@ -56,11 +56,11 @@
     // see superclass for documentation
     public Object saveState(FacesContext context)
     {
-        Object values[] = new Object[4];
+        Object values[] = new Object[3];
         values[0] = super.saveState(context);
-        values[1] = _expandedNodes;
-        values[2] = _varNodeToggler;
-        values[3] = _selectedNodeId;
+//        values[1] = _expandedNodes;
+        values[1] = _varNodeToggler;
+        values[2] = _selectedNodeId;
 
         return ((Object) (values));
     }
@@ -70,9 +70,9 @@
     {
         Object values[] = (Object[])state;
         super.restoreState(context, values[0]);
-        _expandedNodes = (HashSet)values[1];
-        setVarNodeToggler((String)values[2]);
-        _selectedNodeId = (String)values[3];
+//        _expandedNodes = (HashSet)values[1];
+        setVarNodeToggler((String)values[1]);
+        _selectedNodeId = (String)values[2];
     }
 
     // see superclass for documentation
@@ -87,36 +87,36 @@
         }
     }
 
-    public void processDecodes(FacesContext context)
-    {
-        super.processDecodes(context);
-
-        // store the expand/collapse state information in the session (long story)
-        Map sessionMap = context.getExternalContext().getSessionMap();
-        sessionMap.put(NODE_STATE_KEY + ":" + getId(), _expandedNodes);
-    }
-
-    public void encodeBegin(FacesContext context)
-            throws IOException
-    {
-        /**
-         * The expand/collapse state of the nodes is stored in the session in order to ensure that this information
-         * is preserved across requests where the same tree is reused in a tile (server-side include.)  When using
-         * the server-side toggle method without this step, the tree would not remember the expand/collapse state.
-         * Since we didn't think it was appropriate to burden the end user with this information as part of a backing
-         * bean, it just being stored in the session during encode and retrieved during decode.
-         */
-        // restore the expand/collapse state information from the session
-        Map sessionMap = context.getExternalContext().getSessionMap();
-        HashSet nodeState = (HashSet)sessionMap.get(NODE_STATE_KEY + ":" + getId());
-
-        if (nodeState != null)
-        {
-            _expandedNodes = nodeState;
-        }
-
-        super.encodeBegin(context);
-    }
+//    public void processDecodes(FacesContext context)
+//    {
+//        super.processDecodes(context);
+//
+//        // store the expand/collapse state information in the session (long story)
+//        Map sessionMap = context.getExternalContext().getSessionMap();
+//        sessionMap.put(NODE_STATE_KEY + ":" + getId(), _expandedNodes);
+//    }
+
+//    public void encodeBegin(FacesContext context)
+//            throws IOException
+//    {
+//        /**
+//         * The expand/collapse state of the nodes is stored in the session in order to ensure that this information
+//         * is preserved across requests where the same tree is reused in a tile (server-side include.)  When using
+//         * the server-side toggle method without this step, the tree would not remember the expand/collapse state.
+//         * Since we didn't think it was appropriate to burden the end user with this information as part of a backing
+//         * bean, it just being stored in the session during encode and retrieved during decode.
+//         */
+//        // restore the expand/collapse state information from the session
+//        Map sessionMap = context.getExternalContext().getSessionMap();
+//        HashSet nodeState = (HashSet)sessionMap.get(NODE_STATE_KEY + ":" + getId());
+//
+//        if (nodeState != null)
+//        {
+//            _expandedNodes = nodeState;
+//        }
+//
+//        super.encodeBegin(context);
+//    }
 
     /**
      * Gets the expand/collapse control that can be used to handle expand/collapse nodes.  This is only used in server-side
@@ -140,30 +140,30 @@
         _expandControl.setAction(actionBinding);
     }
 
-    public String toggleExpanded()
-    {
-        String nodeId = getNodeId();
-
-        if (_expandedNodes.contains(nodeId))
-        {
-            _expandedNodes.remove(nodeId);
-        }
-        else
-        {
-            _expandedNodes.add(nodeId);
-        }
-
-        return null;
-    }
+//    public void toggleExpanded()
+//    {
+//        String nodeId = getNodeId();
+//
+//        if (_expandedNodes.contains(nodeId))
+//        {
+//            _expandedNodes.remove(nodeId);
+//        }
+//        else
+//        {
+//            _expandedNodes.add(nodeId);
+//        }
+//
+//        return null;
+//    }
 
     /**
      * Indicates whether or not the current {@link TreeNode} is expanded.
      * @return boolean
      */
-    public boolean isNodeExpanded()
-    {
-        return (_expandedNodes.contains(getNodeId()) && getNode().getChildCount() > 0);
-    }
+//    public boolean isNodeExpanded()
+//    {
+//        return (_expandedNodes.contains(getNodeId()) && getNode().getChildCount() > 0);
+//    }
 
     protected void processChildNodes(FacesContext context, TreeNode parentNode, int processAction)
     {

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=227470&r1=227469&r2=227470&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 Thu Aug  4 13:28:49 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.myfaces.custom.tree2;
 
+import java.io.Serializable;
+
 /**
  * Model class for the tree component.  It provides random access to nodes in a tree
  * made up of instances of the {@link TreeNode} class.
@@ -22,7 +24,7 @@
  * @author Sean Schofield
  * @version $Revision$ $Date$
  */
-public interface TreeModel
+public interface TreeModel extends Serializable
 {
     /**
      * Gets the current {@link TreeNode} or <code>null</code> if no node ID is selected.
@@ -56,4 +58,17 @@
      */
     public boolean isLastChild(String nodeId);
 
+    /**
+     * Indicates whether or not the specified {@link TreeNode} is expanded.
+     * 
+     * @param nodeId The id of the node in question.
+     * @return If the node is expanded.
+     */
+    public boolean isNodeExpanded(String nodeId);
+    
+    /**
+     * Toggle the expanded state of the specified {@link TreeNode}.
+     * @param nodeId The id of the node whose expanded state should be toggled.
+     */
+    public void toggleExpanded(String nodeId);
 }

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=227470&r1=227469&r2=227470&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 Thu Aug  4 13:28:49 2005
@@ -15,10 +15,15 @@
  */
 package org.apache.myfaces.custom.tree2;
 
-import javax.faces.component.NamingContainer;
 
+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;
+import java.util.HashSet;
+import java.util.List;
 
 /**
  * Model class for the tree component.  It provides random access to nodes in a tree
@@ -30,8 +35,10 @@
  */
 public class TreeModelBase implements TreeModel
 {
+    private static final Log log = LogFactory.getLog(TreeModelBase.class);    
     private final static String SEPARATOR = String.valueOf(NamingContainer.SEPARATOR_CHAR);
 
+    private HashSet _expandedNodes = new HashSet();
     private TreeNode root;
     private TreeNode currentNode;
 
@@ -149,5 +156,65 @@
         }
 
         return node;
+    }
+    
+    // see interface
+    public boolean isNodeExpanded(String nodeId)
+    {
+        return (_expandedNodes.contains(nodeId) && !getNode().isLeaf());
+    }
+    
+    // see interface
+    public void toggleExpanded(String nodeId)
+    {
+        if (_expandedNodes.contains(nodeId))
+        {
+            _expandedNodes.remove(nodeId);
+        }
+        else
+        {
+            _expandedNodes.add(nodeId);
+        }
+    }
+
+    /**
+     * If set to true, all nodes will be expanded by default.  NOTE: A value of false is ignored.
+     * @param expandAll boolean
+     */
+    public void setExpandAll(boolean expandAll)
+    {
+        if (expandAll)
+        {
+            TreeNode originalNode = currentNode;
+
+            //List rootChildren = root.getChildren();
+            int kidId = 0;
+
+            //for (int i = 0; i < rootChildren.size(); i++)
+            //{
+                expandEverything(null, kidId++);
+            //}
+    
+            currentNode = originalNode;
+        }
+    }
+    
+    /**
+     * 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 + SEPARATOR + childCount : "0";    
+        setNodeId(nodeId);
+        
+        _expandedNodes.add(nodeId);
+        
+        List children = getNode().getChildren();
+        for (int kount=0; kount < children.size(); kount++)
+        {
+            expandEverything(nodeId, kount);
+        }
     }
 }

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=227470&r1=227469&r2=227470&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 Thu Aug  4 13:28:49 2005
@@ -59,7 +59,7 @@
     private static final int PROCESS_UPDATES = 3;
 
     private TreeModel _model;
-    private TreeNode _value;
+    private Object _value;
     private String _var;
     private String _nodeId;
     private Map _saved = new HashMap();
@@ -84,7 +84,8 @@
     {
         Object values[] = new Object[3];
         values[0] = super.saveState(context);
-        values[1] = _value;
+        //values[1] = _value;
+        values[1] = _model;
         values[2] = _var;
         return ((Object) (values));
     }
@@ -96,7 +97,8 @@
         Object values[] = (Object[]) state;
         super.restoreState(context, values[0]);
 
-        _value = (TreeNode)values[1];
+        //_value = values[1];
+        _model = (TreeModel)values[1];
         _var = (String)values[2];
     }
 
@@ -212,7 +214,7 @@
      *
      * @param value The new value
      */
-    public void setValue(TreeNode value)
+    public void setValue(Object value)
     {
         _model = null;
         _value = value;
@@ -373,13 +375,10 @@
             {
                 _model = (TreeModel) value;
             }
-            else if (value instanceof TreeNode)
+            else 
             {
-                _model = new TreeModelBase((TreeNode) value);
-            }
-            else
-            {
-                throw new IllegalArgumentException("Value must implement TreeModel interface or be an instance of TreeNode");
+                throw new IllegalArgumentException("Value must now implement TreeModel interface.  " +
+                    "If you were using an instance of TreeNode use TreeModelBase now instead.");
             }
         }
 
@@ -687,4 +686,22 @@
 
         return false;
     }
+
+    /**
+     * Toggle the expanded state of the current node.
+     */    
+    public void toggleExpanded()
+    {
+        getDataModel().toggleExpanded(getNodeId());
+    }
+    
+    /**
+     * Indicates whether or not the current {@link TreeNode} is expanded.
+     * @return boolean
+     */
+    public boolean isNodeExpanded()
+    {
+        return getDataModel().isNodeExpanded(getNodeId());
+    }
+    
 }