Set<ResourceTreeNode> openNodes = new HashSet<ResourceTreeNode>();
public void changeExpandListener(org.richfaces.event.NodeExpandedEvent e) {
HtmlTree tree = (HtmlTree) e.getComponent();
TreeState state = (TreeState) tree.getComponentState();
//check if we're collapsing a parent of currently selected node.
//if we do, change the focus to the parent
if (state.getSelectedNode() != null) {
boolean closingParent = false;
TreeRowKey<?> key = (TreeRowKey<?>) tree.getRowKey();
ResourceTreeNode node = (ResourceTreeNode) tree.getRowData(key);
ResourceTreeNode selectedNode = (ResourceTreeNode) tree.getRowData(state.getSelectedNode());
ResourceTreeNode traverseCheckNode = selectedNode.getParent();
while (traverseCheckNode != null) {
if (node.equals(traverseCheckNode)) {
closingParent = true;
break;
}
traverseCheckNode = traverseCheckNode.getParent();
}
if (closingParent) {
if (redirectTo(node)) {
state.setSelected(key);
openNodes.remove(node);
//this is nasty hack. We need some kind of flag that would persist only for the remainder
//of this request to advertise that no more open/closed states should be made in this request.
//The tree is request scoped, so setting this flag will not persist to the next request.