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/21 18:55:23 UTC

svn commit: r234267 - in /myfaces: examples/trunk/simple/ examples/trunk/simple/css/ examples/trunk/simple/src/java/org/apache/myfaces/examples/tree/ tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/

Author: schof
Date: Sun Aug 21 09:55:19 2005
New Revision: 234267

URL: http://svn.apache.org/viewcvs?rev=234267&view=rev
Log:
Fixes MYFACES-432

Modified:
    myfaces/examples/trunk/simple/   (props changed)
    myfaces/examples/trunk/simple/css/basic.css
    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/TreeState.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/UITreeData.java

Propchange: myfaces/examples/trunk/simple/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Aug 21 09:55:19 2005
@@ -0,0 +1,2 @@
+commons-logging.properties
+log4j.properties

Modified: myfaces/examples/trunk/simple/css/basic.css
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/css/basic.css?rev=234267&r1=234266&r2=234267&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=234267&r1=234266&r2=234267&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 Sun Aug 21 09:55:19 2005
@@ -21,17 +21,24 @@
 import org.apache.myfaces.custom.tree2.TreeModel;
 import org.apache.myfaces.custom.tree2.TreeModelBase;
 
+import javax.faces.context.FacesContext;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.validator.ValidatorException;
+import javax.faces.event.ActionEvent;
+import java.io.Serializable;
+
 /**
  * Backer bean for use in example.  Basically makes a TreeNode available.
  *
  * @author Sean Schofield
  * @version $Revision$ $Date$
  */
-public class TreeBacker
+public class TreeBacker implements Serializable
 {
     private TreeModelBase _treeModel;
     private HtmlTree _tree;
-    
+
     public TreeNode getTreeData()
     {
         TreeNode treeData = new TreeNodeBase("foo-folder", "Inbox", false);
@@ -99,31 +106,77 @@
 
         return treeData;
     }
-    
+
     /**
-     * NOTE: This is just to show an alternative way of supplying tree data.  You can supply either a 
+     * 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;        
+        return _tree;
     }
-    
+
     public String expandAll()
     {
         _tree.expandAll();
         return null;
+    }
+
+    private String _nodePath;
+
+    public void setNodePath(String nodePath)
+    {
+        _nodePath = nodePath;
+    }
+
+    public String getNodePath()
+    {
+        return _nodePath;
+    }
+
+    public void checkPath(FacesContext context, UIComponent component, java.lang.Object value)
+    {
+        // make sure path is valid (leaves cannot be expanded or renderer will complain)
+        FacesMessage message = null;
+
+        String[] path = _tree.getPathInformation(value.toString());
+
+        for (int i = 0; i < path.length; i++)
+        {
+            String nodeId = path[i];
+            try
+            {
+                _tree.setNodeId(nodeId);
+            }
+            catch (Exception e)
+            {
+                throw new ValidatorException(message, e);
+            }
+
+            if (_tree.getNode().isLeaf())
+            {
+                message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                                           "Invalid node path (cannot expand a leaf): " + nodeId,
+                                           "Invalid node path (cannot expand a leaf): " + nodeId);
+                throw new ValidatorException(message);
+            }
+        }
+    }
+
+    public void expandPath(ActionEvent event)
+    {
+        _tree.expandPath(_tree.getPathInformation(_nodePath));
     }
 }

Modified: myfaces/examples/trunk/simple/tree2ExpandAll.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/tree2ExpandAll.jsp?rev=234267&r1=234266&r2=234267&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/tree2ExpandAll.jsp (original)
+++ myfaces/examples/trunk/simple/tree2ExpandAll.jsp Sun Aug 21 09:55:19 2005
@@ -34,7 +34,7 @@
 
     <h:commandLink value="Expand All" action="#{treeBacker.expandAll}"/>
     <br/><br/>
-    
+
     <t:tree2 id="serverTree" value="#{treeBacker.expandedTreeData}" var="node" varNodeToggler="t" clientSideToggle="false" binding="#{treeBacker.tree}">
         <f:facet name="person">
             <h:panelGroup>
@@ -75,6 +75,22 @@
             </h:panelGroup>
         </f:facet>
     </t:tree2>
+
+    <br/>
+
+    <h:form>
+
+        <h:panelGrid columns="1">
+            <h:message for=":serverTree" showSummary="false" styleClass="error"/>
+            <h:message for="nodePath" styleClass="error"/>
+            <h:panelGroup>
+                <h:outputText value="Enter Node Path To Expand (ex. 0:0:1) "/>
+                <h:inputText id="nodePath" value="#{treeBacker.nodePath}" validator="#{treeBacker.checkPath}"/>
+                <h:commandButton value="Expand" actionListener="#{treeBacker.expandPath}"/>
+            </h:panelGroup>
+        </h:panelGrid>
+
+    </h:form>
 
 </f:view>
 

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeState.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeState.java?rev=234267&r1=234266&r2=234267&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeState.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeState.java Sun Aug 21 09:55:19 2005
@@ -2,25 +2,41 @@
 
 import java.io.Serializable;
 
-public interface TreeState extends Serializable 
+public interface TreeState extends Serializable
 {
-	
+
     /**
      * 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);
-    
+
+    /**
+     * Expand the complete path specified.  If any node in the path is already expanded,
+     * that node should be left as it is.
+     *
+     * @param nodePath The path to be expanded.
+     */
+    public void expandPath(String[] nodePath);
+
     /**
-     * Getter for transient property.  
+     * Collapse the complete path specified.  If any node in the path is already collapsed,
+     * that node should be left as it is.
+     *
+     * @param nodePath The path to be collapsed.
+     */
+    public void collapsePath(String[] nodePath);
+
+    /**
+     * Getter for transient property.
      * @return boolean
      */
     public boolean isTransient();
@@ -28,7 +44,7 @@
     /**
      * Setter for transient property
      * @param trans boolean
-     */    
+     */
     public void setTransient(boolean trans);
 
 }

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java?rev=234267&r1=234266&r2=234267&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java Sun Aug 21 09:55:19 2005
@@ -2,19 +2,19 @@
 
 import java.util.HashSet;
 
-public class TreeStateBase implements TreeState 
+public class TreeStateBase implements TreeState
 {
-	
+
     private static final long serialVersionUID = -6767283932185878071L;
     private HashSet _expandedNodes = new HashSet();
     private boolean _transient = false;
-	
+
     // see interface
     public boolean isNodeExpanded(String nodeId)
     {
         return (_expandedNodes.contains(nodeId) /*&& !getNode().isLeaf()*/);
     }
-    
+
     // see interface
     public void toggleExpanded(String nodeId)
     {
@@ -29,61 +29,34 @@
     }
 
     // see interface
-    public boolean isTransient() 
+    public boolean isTransient()
     {
         return _transient;
     }
-    
+
     // see interface
-    public void setTransient(boolean trans) 
+    public void setTransient(boolean trans)
     {
         _transient = trans;
     }
-    
-    
-    /**
-     * 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)
+
+    // see interface
+    public void expandPath(String[] nodePath)
     {
-        if (expandAll)
+        for (int i=0; i < nodePath.length; i++)
         {
-            TreeNode originalNode = currentNode;
-
-            //List rootChildren = root.getChildren();
-            int kidId = 0;
-
-            //for (int i = 0; i < rootChildren.size(); i++)
-            //{
-                expandEverything(null, kidId++);
-            //}
-    
-            currentNode = originalNode;
+            String nodeId = nodePath[i];
+            _expandedNodes.add(nodeId);
         }
     }
-    */
-    
-    /**
-     * 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++)
+
+    // see interface
+    public void collapsePath(String[] nodePath)
+    {
+        for (int i=0; i < nodePath.length; i++)
         {
-            expandEverything(nodeId, kount);
+            String nodeId = nodePath[i];
+            _expandedNodes.remove(nodeId);
         }
     }
-    */
-
 }

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=234267&r1=234266&r2=234267&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 Sun Aug 21 09:55:19 2005
@@ -63,7 +63,7 @@
     private String _var;
     private String _nodeId;
     private Map _saved = new HashMap();
-    
+
     private TreeState _restoredState = null;
 
     /**
@@ -87,16 +87,16 @@
         Object values[] = new Object[3];
         values[0] = super.saveState(context);
         values[1] = _var;
-        
+
         TreeState t = getDataModel().getTreeState();
         if ( t == null)
         {
             // the model supplier has forgotten to return a valid state manager, but we need one
-            t = new TreeStateBase(); 
+            t = new TreeStateBase();
         }
-        
-        // save the state with the component, unless it should explicitly not saved eg. session-scoped model and state            
-        values[2] = (t.isTransient()) ? null : t; 
+
+        // save the state with the component, unless it should explicitly not saved eg. session-scoped model and state
+        values[2] = (t.isTransient()) ? null : t;
         return ((Object) (values));
     }
 
@@ -211,12 +211,12 @@
          * do want to keep the saved state so that we can render the node with
          * the invalid value.
          */
-    	   	
+
         if (!keepSaved(context))
         {
             _saved = new HashMap();
         }
-        
+
         // FIX for MYFACES-404
         // do not use the cached model the render phase
         _model = null;
@@ -401,7 +401,7 @@
 
         if (_restoredState != null)
             _model.setTreeState(_restoredState); // set the restored state (if there is one) on the model
-        
+
         return _model;
     }
 
@@ -417,7 +417,25 @@
         expandEverything(null, kidId++);
         setNodeId(currentNodeId);
     }
-    
+
+    /**
+     * Expands all of the nodes in the specfied path.
+     * @param nodePath The path to expand.
+     */
+    public void expandPath(String[] nodePath)
+    {
+        getDataModel().getTreeState().expandPath(nodePath);
+    }
+
+    /**
+     * Expands all of the nodes in the specfied path.
+     * @param nodePath The path to expand.
+     */
+    public void collapsePath(String[] nodePath)
+    {
+        getDataModel().getTreeState().collapsePath(nodePath);
+    }
+
     /**
      * Private helper method that recursviely expands all of the nodes.
      *
@@ -426,11 +444,11 @@
      */
     private void expandEverything(String parentId, int childCount)
     {
-        String nodeId = (parentId != null) ? parentId + TreeModel.SEPARATOR + childCount : "0";    
+        String nodeId = (parentId != null) ? parentId + TreeModel.SEPARATOR + childCount : "0";
         setNodeId(nodeId);
 
         TreeNode node = getDataModel().getNode();
-        
+
         if (!node.isLeaf() && !isNodeExpanded())
         {
             getDataModel().getTreeState().toggleExpanded(nodeId);
@@ -442,7 +460,7 @@
             expandEverything(nodeId, kount);
         }
     }
-    
+
 
     private void processNodes(FacesContext context, int processAction, String parentId, int childLevel)
     {
@@ -748,12 +766,12 @@
 
     /**
      * Toggle the expanded state of the current node.
-     */    
+     */
     public void toggleExpanded()
     {
         getDataModel().getTreeState().toggleExpanded(getNodeId());
     }
-    
+
     /**
      * Indicates whether or not the current {@link TreeNode} is expanded.
      * @return boolean
@@ -762,5 +780,5 @@
     {
         return getDataModel().getTreeState().isNodeExpanded(getNodeId());
     }
-    
+
 }