views:

74

answers:

1

Hi,

I'm using the Google Closure Library and goog.ui.tree in particular to build a tree structure GUI component. It works pretty well out of the box, but I'd like to add a few extra controls to each of the leaves (goog.ui.Checkboxes in particular).

The problem is that Component.addChild has been overridden in BaseNode so that each added child is treated as a child tree node as opposed to a child component. In effect plenty of errors are thrown if you try to add anything else than an actual tree node as a child, as these children are traversed and BaseNode-specific functions are called on them.

I must admit I'm quite a Closure newb, but I reckon there must be some workaround for this, right? Essentially all I want to do is have a bunch of checkboxes appear next to each leaf in my tree.

Thanks, Andreas

A: 

In addition to the more general comment I left on your question, I found the following property on goog.ui.tree.BaseNode that may work for simple needs:

/**
 * Html that can appear after the label (so not inside the anchor).
 * @type {string}
 * @private
 */
goog.ui.tree.BaseNode.prototype.afterLabelHtml_ = '';

This can be set using:

/**
 * Sets the html that appears after the label. This is useful if you want to
 * put extra UI on the row of the label but not inside the anchor tag.
 * @param {string} html The html.
 */
goog.ui.tree.BaseNode.prototype.setAfterLabelHtml = function(html)
Adam Alexander
Thanks Adam, this is really useful, it slipped me! I'm just curious if I'd be able to take full advantage of the Checkbox class just by inserting html. What I tried doing before was overriding the createDom() method of TreeNode to insert some html divs and then using these divs' ids to identify elements to pass to the render() method of the Checkboxes. The problem then was that, because the tree is not expanded by default, the html was not rendered, and therefore could not be used in render() (the divs simply do not exist until you expand the parent and reveal the leaves).
Andreas Jansson