protected Decorator createDecorator() {
return new Decorator() {
public String render(Object object, Context context) {
TreeNode treeNode = (TreeNode) object;
HtmlStringBuffer buffer = new HtmlStringBuffer();
renderIcon(buffer, treeNode);
renderCheckbox(buffer, treeNode);
buffer.elementStart("span");
if (treeNode.isSelected()) {
buffer.appendAttribute("class", "selected");
} else {
buffer.appendAttribute("class", "unselected");
}
if (isJavascriptEnabled()) {
((CheckboxJavascriptRenderer) javascriptHandler.getJavascriptRenderer()).renderSelect(
buffer);
}
buffer.closeTag();
renderValue(buffer, treeNode);
buffer.elementEnd("span");
return buffer.toString();
}
/**
* Render the node's value.
*
* @param buffer string buffer containing the markup
* @param treeNode treeNode to render
*/
protected void renderValue(HtmlStringBuffer buffer,
TreeNode treeNode) {
if (isJavascriptEnabled()) {
//create a href to interact with the checkbox on browser
buffer.elementStart("a");
Map hrefParameters =
Collections.singletonMap(SELECT_TREE_NODE_PARAM,
treeNode.getId());
buffer.appendAttribute("href", getHref(hrefParameters));
((CheckboxJavascriptRenderer) javascriptHandler.getJavascriptRenderer()).renderValue(
buffer);
buffer.closeTag();
if (treeNode.getValue() != null) {
buffer.append(treeNode.getValue());
}
buffer.elementEnd("a");
buffer.append("\n");
} else {
//just print normal value
if (treeNode.getValue() != null) {
buffer.append(treeNode.getValue());
}
buffer.append("\n");
}
}
};
}