myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "sean schofield (JIRA)" <...@myfaces.apache.org>
Subject [jira] Closed: (MYFACES-717) No way to make selection from code in Tree2
Date Sat, 18 Feb 2006 16:24:25 GMT
     [ http://issues.apache.org/jira/browse/MYFACES-717?page=all ]
     
sean schofield closed MYFACES-717:
----------------------------------

    Fix Version: Nightly
     Resolution: Fixed

You are now able to programatically change the selected state by providing your own TreeModel
and TreeState (instead of just giving the tree your node hierarchy and using the default implementations.

> No way to make selection from code in Tree2
> -------------------------------------------
>
>          Key: MYFACES-717
>          URL: http://issues.apache.org/jira/browse/MYFACES-717
>      Project: MyFaces
>         Type: Bug
>   Components: Tomahawk
>     Reporter: Jon Travis
>     Assignee: sean schofield
>      Fix For: Nightly

>
> There is no way to tell Tree2 what to select without the
> user doing the actual selection themselves.  I tried a
> bunch of different things (including broadcasting an
> event, etc.), but nothing worked without changing some
> code.
> This patch basically moves the concept of the 'selected node'
> into the TreeState.  It seems like a good fit, given that
> expansions are stored in the same manner.
> Without this patch, I can't tell the tree what to select
> from the code.
> It may make more sense to push this down ito the UITreeData
> instead of HtmlTree -- I'll leave that one up to Sean.
> -- Jon
> Index: tomahawk/src/java/org/apache/myfaces/custom/tree2/TreeState.java
> ===================================================================
> --- tomahawk/src/java/org/apache/myfaces/custom/tree2/TreeState.java    (revision 292567)
> +++ tomahawk/src/java/org/apache/myfaces/custom/tree2/TreeState.java    (working copy)
> @@ -4,7 +4,10 @@
> public interface TreeState extends Serializable
> {
> +    public boolean isNodeSelected(String nodeId);
> +    public void setNodeSelected(String nodeId);
> +
>      /**
>       * Indicates whether or not the specified {@link TreeNode} is expanded.
>       *
> Index: tomahawk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java
> ===================================================================
> --- tomahawk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java     (revision 292567)
> +++ tomahawk/src/java/org/apache/myfaces/custom/tree2/HtmlTree.java     (working copy)
> @@ -41,7 +41,6 @@
>      private UICommand _expandControl;
>      private String _varNodeToggler;
> //    private HashSet _expandedNodes = new HashSet();
> -    private String _selectedNodeId;
>      /**
>       * Constructor
> @@ -56,11 +55,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;
>          return ((Object) (values));
>      }
> @@ -72,7 +70,6 @@
>          super.restoreState(context, values[0]);
> //        _expandedNodes = (HashSet)values[1];
>          setVarNodeToggler((String)values[1]);
> -        _selectedNodeId = (String)values[2];
>      }
>      // see superclass for documentation
> @@ -179,7 +176,7 @@
>       */
>      public void setNodeSelected(ActionEvent event)
>      {
> -        _selectedNodeId = getNodeId();
> +        getDataModel().getTreeState().setNodeSelected(getNodeId());
>      }
>      /**
> @@ -188,6 +185,11 @@
>       */
>      public boolean isNodeSelected()
>      {
> -        return (getNodeId() != null) ? getNodeId().equals(_selectedNodeId) : false;
> +        String nodeId = getNodeId();
> +
> +        if (nodeId == null)
> +            return false;
> +
> +        return getDataModel().getTreeState().isNodeSelected(nodeId);
>      }
> }
> Index: tomahawk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java
> ===================================================================
> --- tomahawk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java      (revision
292567)
> +++ tomahawk/src/java/org/apache/myfaces/custom/tree2/TreeStateBase.java      (working
copy)
> @@ -8,7 +8,21 @@
>      private static final long serialVersionUID = -6767283932185878071L;
>      private HashSet _expandedNodes = new HashSet();
>      private boolean _transient = false;
> +    private String  _selectedNode = null;
> +    public boolean isNodeSelected(String nodeId)
> +    {
> +        if (_selectedNode == null)
> +            return nodeId == null;
> +
> +        return _selectedNode.equals(nodeId);
> +    }
> +
> +    public void setNodeSelected(String nodeId)
> +    {
> +        _selectedNode = nodeId;
> +    }
> +
>      // see interface
>      public boolean isNodeExpanded(String nodeId)
>      {

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message