boolean hasChildren = !node.isLeaf() && node.getHasChildren();
boolean expanded = hasChildren && expansionModel.isExpanded(node);
String clientId = jss.allocateClientId(resources);
JSONObject spec = new JSONObject("clientId", clientId);
e.attribute("id", clientId);
spec.put("leaf", node.isLeaf());
if (hasChildren)
{
Link expandChildren = resources.createEventLink("expandChildren", node.getId());
Link markExpanded = resources.createEventLink("markExpanded", node.getId());
Link markCollapsed = resources.createEventLink("markCollapsed", node.getId());
spec.put("expandChildrenURL", expandChildren.toString())
.put("markExpandedURL", markExpanded.toString())
.put("markCollapsedURL", markCollapsed.toString());
if (expanded)
spec.put("expanded", true);
} else
{
if (selectionModel != null)
{
// May need to address this in the future; in other tree implementations I've constructed,
// folders are selectable, and selections even propagate up and down the tree.
Link selectLeaf = resources.createEventLink("select", node.getId());
spec.put("selectURL", selectLeaf.toString());
if (selectionModel.isSelected(node))
{
spec.put("selected", true);
}
}
}
jss.addInitializerCall("treeNode", spec);