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 2006/02/18 17:22:11 UTC

svn commit: r378737 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2: HtmlTree.java TreeState.java TreeStateBase.java UITreeData.java

Author: schof
Date: Sat Feb 18 08:22:09 2006
New Revision: 378737

URL: http://svn.apache.org/viewcvs?rev=378737&view=rev
Log:
Move selected state to the TreeState (fixes MYFACES-717)

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/HtmlTree.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeState.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeStateBase.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/UITreeData.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/HtmlTree.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/HtmlTree.java?rev=378737&r1=378736&r2=378737&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/HtmlTree.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/HtmlTree.java Sat Feb 18 08:22:09 2006
@@ -19,7 +19,6 @@
 import javax.faces.component.html.HtmlCommandLink;
 import javax.faces.context.FacesContext;
 import javax.faces.el.MethodBinding;
-import javax.faces.event.ActionEvent;
 import java.util.Map;
 
 /**
@@ -33,11 +32,9 @@
 {
     public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlTree2";
     private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.HtmlTree2";
-//	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 String _selectedNodeId;
+    //private String _selectedNodeId;
 
     /**
      * Constructor
@@ -52,11 +49,10 @@
     // see superclass for documentation
     public Object saveState(FacesContext context)
     {
-        Object values[] = new Object[3];
+        Object values[] = new Object[2];
         values[0] = super.saveState(context);
-//      values[1] = _expandedNodes;
         values[1] = _varNodeToggler;
-        values[2] = _selectedNodeId;
+        //values[2] = _selectedNodeId;
 
         return ((Object) (values));
     }
@@ -66,9 +62,8 @@
     {
         Object values[] = (Object[])state;
         super.restoreState(context, values[0]);
-//      _expandedNodes = (HashSet)values[1];
         setVarNodeToggler((String)values[1]);
-        _selectedNodeId = (String)values[2];
+        //_selectedNodeId = (String)values[2];
     }
 
     // see superclass for documentation
@@ -83,37 +78,6 @@
         }
     }
 
-//    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
      * mode.  It allows the nagivation controls (if any) to be clickable as well as any commandLinks the user has set up in
@@ -136,50 +100,24 @@
         _expandControl.setAction(actionBinding);
     }
 
-//    public void toggleExpanded()
+//    /**
+//     * Implements the {@link javax.faces.event.ActionListener} interface.  Basically, this
+//     * method is used to listen for node selection events (when a user has clicked on a
+//     * leaf node.)
+//     *
+//     * @param event ActionEvent
+//     */
+//    public void setNodeSelected(ActionEvent event)
 //    {
-//        String nodeId = getNodeId();
-//
-//        if (_expandedNodes.contains(nodeId))
-//        {
-//            _expandedNodes.remove(nodeId);
-//        }
-//        else
-//        {
-//            _expandedNodes.add(nodeId);
-//        }
-//
-//        return null;
+//        _selectedNodeId = getNodeId();
 //    }
-
-    /*
-     * Indicates whether or not the current {@link TreeNode} is expanded.
-     * @return boolean
-     */
-//    public boolean isNodeExpanded()
+//
+//    /**
+//     * Indicates whether or not the current {@link TreeNode} is selected.
+//     * @return boolean
+//     */
+//    public boolean isNodeSelected()
 //    {
-//        return (_expandedNodes.contains(getNodeId()) && getNode().getChildCount() > 0);
+//        return (getNodeId() != null) ? getNodeId().equals(_selectedNodeId) : false;
 //    }
-
-
-    /**
-     * Implements the {@link javax.faces.event.ActionListener} interface.  Basically, this
-     * method is used to listen for node selection events (when a user has clicked on a
-     * leaf node.)
-     *
-     * @param event ActionEvent
-     */
-    public void setNodeSelected(ActionEvent event)
-    {
-        _selectedNodeId = getNodeId();
-    }
-
-    /**
-     * Indicates whether or not the current {@link TreeNode} is selected.
-     * @return boolean
-     */
-    public boolean isNodeSelected()
-    {
-        return (getNodeId() != null) ? getNodeId().equals(_selectedNodeId) : false;
-    }
 }

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeState.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeState.java?rev=378737&r1=378736&r2=378737&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeState.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeState.java Sat Feb 18 08:22:09 2006
@@ -62,4 +62,16 @@
      */
     public void setTransient(boolean trans);
 
+    /**
+     * Sets the id of the currently selected node
+     * @param nodeId The id of the currently selected node
+     */
+    public void setSelected(String nodeId);
+
+    /**
+     * Indicates whether or not the specified node is selected.
+     * @param nodeId String
+     * @return boolean
+     */
+    public boolean isSelected(String nodeId);
 }

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeStateBase.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeStateBase.java?rev=378737&r1=378736&r2=378737&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeStateBase.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/TreeStateBase.java Sat Feb 18 08:22:09 2006
@@ -23,6 +23,7 @@
     private static final long serialVersionUID = -6767283932185878071L;
     private HashSet _expandedNodes = new HashSet();
     private boolean _transient = false;
+    private String _selected;
 
     // see interface
     public boolean isNodeExpanded(String nodeId)
@@ -73,5 +74,15 @@
             String nodeId = nodePath[i];
             _expandedNodes.remove(nodeId);
         }
+    }
+
+    public void setSelected(String nodeId)
+    {
+        _selected = nodeId;
+    }
+
+    public boolean isSelected(String nodeId)
+    {
+        return nodeId.equals(_selected);
     }
 }

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/UITreeData.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/UITreeData.java?rev=378737&r1=378736&r2=378737&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/UITreeData.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/UITreeData.java Sat Feb 18 08:22:09 2006
@@ -30,6 +30,7 @@
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
 import javax.faces.event.FacesEvent;
 import javax.faces.event.FacesListener;
 import javax.faces.event.PhaseId;
@@ -106,7 +107,7 @@
 
     public void encodeEnd(FacesContext context) throws IOException {
         super.encodeEnd(context);
-        
+
         // prepare to save the tree state -- fix for MYFACES-618
         // should be done in saveState() but Sun RI does not call saveState() and restoreState()
         // with javax.faces.STATE_SAVING_METHOD = server
@@ -118,7 +119,7 @@
         }
         // save the state with the component, unless it should explicitly not saved eg. session-scoped model and state
         _restoredState = (state.isTransient()) ? null : state;
-        
+
     }
 
     public void queueEvent(FacesEvent event)
@@ -491,29 +492,6 @@
     }
 
     /**
-     * Process the child nodes of the supplied parent {@link TreeNode}.  This method is protected so that
-     * it can be overriden by a subclass that may want to control how child nodes are processed.
-     *
-     * @param context       FacesContext
-     * @param parentNode    The parent node whose children are to be processed
-     * @param processAction An <code>int</code> representing the type of action to process
-     */
-    /*
-    protected void processChildNodes(FacesContext context, TreeNode parentNode, int processAction)
-    {
-        int kidId = 0;
-        String currId = getNodeId();
-
-        List children = parentNode.getChildren();
-
-        for (int i = 0; i < children.size(); i++)
-        {
-            processNodes(context, processAction, currId, kidId++);
-        }
-    }
-    */
-
-    /**
      * To support using input components for the nodes (e.g., input fields, checkboxes, and selection
      * lists) while still only using one set of components for all nodes, the state held by the components
      * for the current node must be saved for a new node is selected.
@@ -775,5 +753,26 @@
     public boolean isNodeExpanded()
     {
         return getDataModel().getTreeState().isNodeExpanded(getNodeId());
+    }
+
+    /**
+     * Implements the {@link javax.faces.event.ActionListener} interface.  Basically, this
+     * method is used to listen for node selection events (when a user has clicked on a
+     * leaf node.)
+     *
+     * @param event ActionEvent
+     */
+    public void setNodeSelected(ActionEvent event)
+    {
+        getDataModel().getTreeState().setSelected(getNodeId());
+    }
+
+    /**
+     * Indicates whether or not the current {@link TreeNode} is selected.
+     * @return boolean
+     */
+    public boolean isNodeSelected()
+    {
+        return (getNodeId() != null) ? getDataModel().getTreeState().isSelected(getNodeId()) : false;
     }
 }