* if true, add "last" attribute to the LI element
* @return command to render the node
*/
private RenderCommand toRenderCommand(final TreeNode node, final boolean isLast)
{
return new RenderCommand()
{
public void render(MarkupWriter writer, RenderQueue queue)
{
// Inform the component's container about what value is being rendered
// (this may be necessary to generate the correct label for the node).
Tree.this.node = node;
value = node.getValue();
boolean isLeaf = node.isLeaf();
writer.element("li");
if (isLast)
{
writer.attributes("class", "last");
}
if (isLeaf)
{
writer.getElement().attribute("class", "leaf-node");
}
Element e = writer.element("span", "class", "tree-icon");
if (!isLeaf && !node.getHasChildren())
{
e.addClassName("empty-node");
}
boolean hasChildren = !isLeaf && node.getHasChildren();
boolean expanded = hasChildren && expansionModel.isExpanded(node);
writer.attributes("data-node-id", node.getId());
if (expanded)
{
// Inform the client side, so it doesn't try to fetch it a second time.
e.addClassName("tree-expanded");
}
writer.end(); // span.tree-icon
// From here on in, we're pushing things onto the queue. Remember that
// execution order is reversed from order commands are pushed.
queue.push(RENDER_CLOSE_TAG); // li
if (expanded)
{
queue.push(new RenderNodes(node.getChildren()));
}
queue.push(RENDER_CLOSE_TAG);
final RenderCommand startHeartbeat = new RenderCommand() {
@Override
public void render(MarkupWriter writer, RenderQueue queue) {
heartbeat.begin();
}
};
final RenderCommand endHeartbeat = new RenderCommand() {
@Override
public void render(MarkupWriter writer, RenderQueue queue) {
heartbeat.end();
}