if(params.containsKey(clientId) && params.containsKey(rowKeyParam) && params.containsKey(actionParam)) {
String rowKey = params.get(rowKeyParam);
String event = params.get(actionParam);
TreeNode root = (TreeNode) tree.getValue();
TreeNode currentNode = treeExplorer.findTreeNode(rowKey, new TreeModel(root));
switch(TreeNodeEvent.valueOf(event)) {
case SELECT:
tree.queueEvent(new NodeSelectEvent(tree, currentNode));
break;
case EXPAND:
currentNode.setExpanded(true);
tree.queueEvent(new NodeExpandEvent(tree, currentNode));
break;
case COLLAPSE:
currentNode.setExpanded(false);
tree.queueEvent(new NodeCollapseEvent(tree, currentNode));
break;
}
}
//Selection
if(params.containsKey(selectionParam)) {
String selectedNodesValue = params.get(selectionParam);
boolean isSingle = tree.getSelectionMode().equalsIgnoreCase("single");
if(selectedNodesValue.equals("")) {
if(isSingle)
tree.setSelection(null);
else
tree.setSelection(new TreeNode[0]);
}
else {
String[] selectedRowKeys = selectedNodesValue.split(",");
TreeModel model = new TreeModel((TreeNode) tree.getValue());
if(isSingle) {
TreeNode selectedNode = treeExplorer.findTreeNode(selectedRowKeys[0], model);
tree.setSelection(selectedNode);
} else {
TreeNode[] selectedNodes = new TreeNode[selectedRowKeys.length];
for(int i = 0 ; i < selectedRowKeys.length; i++) {
selectedNodes[i] = treeExplorer.findTreeNode(selectedRowKeys[i], model);
model.setRowIndex(-1); //reset
}
tree.setSelection(selectedNodes);
}
}