addParameterEncoder(DnDParametersEncoder.getInstance());
}
protected String getToggleScript(FacesContext context, UITreeNode treeNode, String to) {
UITree tree = treeNode.getUITree();
if ("handle".equals(to) && tree.isToggleOnClick() ||
"mainRow".equals(to) && !tree.isToggleOnClick())
return "";
String id = treeNode.getClientId(context);
StringBuilder script = new StringBuilder();
script.append("var c = Tree.Item.findComponent(this); if (!c) return; c.");
boolean expanded = tree.isExpanded();
if (expanded) {
script.append("fireCollapsionEvent();");
} else {
script.append("fireExpansionEvent();");
}
if (UITree.SWITCH_AJAX.equals(tree.getSwitchType())) {
UITreeNode nodeFacet = tree.getNodeFacet();
JSFunction function = AjaxRendererUtils.buildAjaxFunction(nodeFacet,
context);
Map<String, Object> eventOptions = AjaxRendererUtils.buildEventOptions(context,
nodeFacet);
Map<Object, Object> parameters = (Map<Object, Object>) eventOptions.get("parameters");
parameters.remove(id);
parameters.put(id + NODE_EXPANDED_INPUT_SUFFIX, String.valueOf(!expanded));
parameters.put(id + AJAX_EXPANDED_SUFFIX, Boolean.TRUE);
function.addParameter(eventOptions);
StringBuffer buffer = new StringBuffer();
buffer.append(script);
buffer.append(";");
function.appendScript(buffer);
buffer.append(";");
return buffer.toString();
} else if (UITree.SWITCH_SERVER.equals(tree.getSwitchType())) {
String paramName = id + NODE_EXPANDED_INPUT_SUFFIX;
StringBuffer result = new StringBuffer();
result.append(script);
result.append(";");