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 [EMAIL PROTECTED] 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)
{