The goog.ui.tree.TreeControl Class

goog.ui.tree.TreeControl
> goog.ui.tree.BaseNode
> goog.ui.Component
> goog.events.EventTarget
> goog.Disposable

goog.ui.tree.TreeControl(html, opt_config, opt_domHelper)

This creates a TreeControl object. A tree control provides a way to view a hierarchical set of data.

html {string}
The HTML content of the node label.
opt_config {Object=}
The configuration for the tree. See goog.ui.tree.TreeControl.DefaultConfig. If not specified, a default config will be used.
opt_domHelper {goog.dom.DomHelper=}
Optional DOM helper.

.add(child, opt_before)

Inherited from goog.ui.tree.BaseNode .

Adds a node as a child to the current node.

child {goog.ui.tree.BaseNode}
The child to add.
opt_before {goog.ui.tree.BaseNode=}
If specified, the new child is added as a child before this one. If not specified, it's appended to the end.
returns {goog.ui.tree.BaseNode}
The added child.

.addChild(child, opt_render)

Inherited from goog.ui.Component .

Adds the specified component as the last child of this component. See {@link goog.ui.Component#addChildAt} for detailed semantics.

child {goog.ui.Component}
The new child component.
opt_render {boolean=}
If true, the child component will be rendered into the parent.
@see
goog.ui.Component#addChildAt

.addChildAt(child, index, opt_render)

Inherited from goog.ui.tree.BaseNode .

The method assumes that the child doesn't have parent node yet. The {@code opt_render} argument is not used. If the parent node is expanded, the child node's state will be the same as the parent's. Otherwise the child's DOM tree won't be created.

child {goog.ui.Component}
The new child component.
index {number}
0-based index at which the new child component is to be added; must be between 0 and the current child count (inclusive).
opt_render {boolean=}
If true, the child component will be rendered into the parent.
returns {void}
Nada.
@see
goog.ui.Component#addChild

.addEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. Supported for legacy but use goog.events.listen(src, type, handler) instead.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.canDecorate(element)

Inherited from goog.ui.Component .

Determines if a given element can be decorated by this type of component. This method should be overridden by inheriting objects.

element {Element}
Element to decorate.
returns {boolean}
True if the element can be decorated, false otherwise.

.clearTypeAhead()

Clear the typeahead buffer.

.collapse()

Inherited from goog.ui.tree.BaseNode .

Collapses the node.

.collapseAll()

Inherited from goog.ui.tree.BaseNode .

Collapses the children and the node.

.collapseChildren()

Inherited from goog.ui.tree.BaseNode .

Collapses the children of the node.

.contains(node)

Inherited from goog.ui.tree.BaseNode .

Returns true if the node is a descendant of this node

node {goog.ui.tree.BaseNode}
The node to check.
returns {boolean}
True if the node is a descendant of this node, false otherwise.

.createDom()

Inherited from goog.ui.tree.BaseNode .

Creates the initial DOM representation for the component. The default implementation is to set this.element_ = div.

.createNode(html)

Creates a new tree node using the same config as the root.

html {string}
The html content of the node label.
returns {goog.ui.tree.TreeNode}
The new item.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.decorate(element)

Inherited from goog.ui.Component .

Decorates the element for the UI component.

element {Element}
Element to decorate.

.defaultConfig

A default configuration for the tree.

.dispatchEvent(e)

Inherited from goog.events.EventTarget .

Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.

e {string|Object|goog.events.Event}
Event object.
returns {boolean}
If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.enterDocument()

Called when the component's element is known to be in the document. Anything using document.getElementById etc. should be done at this stage. If the component contains child components, this call is propagated to its children.

.exitDocument()

Called by dispose to clean up the elements and listeners created by a component, or by a parent component/application who has removed the component from the document but wants to reuse it later. If the component contains child components, this call is propagated to its children. It should be possible for the component to be rendered again once this method has been called.

.expand()

Inherited from goog.ui.tree.BaseNode .

Expands the node.

.expandAll()

Inherited from goog.ui.tree.BaseNode .

Expands the children and the node.

.expandChildren()

Inherited from goog.ui.tree.BaseNode .

Expands the children of the node.

.forEachChild(f, opt_obj)

Inherited from goog.ui.Component .

Calls the given function on each of this component's children in order. If {@code opt_obj} is provided, it will be used as the 'this' object in the function when called. The function should take two arguments: the child component and its 0-based index. The return value is ignored.

f {Function}
The function to call for every child component; should take 2 arguments (the child and its index).
opt_obj {Object=}
Used as the 'this' object in f when called.

.getAfterLabelElement()

Inherited from goog.ui.tree.BaseNode .

returns {Element}
The element after the label.

.getAfterLabelHtml()

Inherited from goog.ui.tree.BaseNode .

Returns 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.

returns {string}
The html.

.getChild(id)

Inherited from goog.ui.Component .

Returns the child with the given ID, or null if no such child exists.

id {string}
Child component ID.
returns {goog.ui.Component?}
The child with the given ID; null if none.

.getChildAt

Inherited from goog.ui.tree.BaseNode .

index {number}
0-based index.
returns {goog.ui.tree.BaseNode}
The child at the given index; null if none.

.getChildCount()

Inherited from goog.ui.Component .

Returns the number of children of this component.

returns {number}
The number of children.

.getChildIds()

Inherited from goog.ui.Component .

Returns an array containing the IDs of the children of this component, or an empty array if the component has no children.

returns {Array.<string>}
Child component IDs.

.getChildren()

Inherited from goog.ui.tree.BaseNode .

Returns the children of this node.

returns {!Array.<!goog.ui.tree.BaseNode>}
The children.

.getConfig()

Inherited from goog.ui.tree.BaseNode .

returns {Object}
The configuration for the tree.

.getContentElement()

Inherited from goog.ui.Component .

Returns the DOM element into which child components are to be rendered, or null if the component itself hasn't been rendered yet. This default implementation returns the component's root element. Subclasses with complex DOM structures must override this method.

returns {Element}
Element to contain child elements (null if none).

.getDepth()

Returns the depth of the node in the tree. Should not be overridden.

returns {number}
The non-negative depth of this node (the root is zero).

.getDomHelper()

Inherited from goog.ui.Component .

Returns the dom helper that is being used on this component.

returns {!goog.dom.DomHelper}
The dom helper used on this component.

.getElement()

Inherited from goog.ui.tree.BaseNode .

Gets the component's element.

returns {Element}
The element for the tree node.

.getElementByClass(className)

Inherited from goog.ui.Component .

Returns the first element in this component's DOM with the provided className.

className {string}
The name of the class to look for.
returns {Element}
The first item with the class name provided.

.getElementByFragment(idFragment)

Inherited from goog.ui.Component .

Helper function for returning an element in the document with a unique id generated using makeId().

idFragment {string}
The partial id.
returns {Element}
The element with the unique id, or null if it cannot be found.

.getElementsByClass(className)

Inherited from goog.ui.Component .

Returns an array of all the elements in this component's DOM with the provided className.

className {string}
The name of the class to look for.
returns {!goog.array.ArrayLike}
The items found with the class name provided.

.getExpanded()

returns {boolean}
Whether the node is expanded.

.getExpandedIconClass()

Inherited from goog.ui.tree.BaseNode .

Gets the icon class for when the node is expanded.

returns {string}
The class.

.getFirstChild()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The first child of this node.

.getFragmentFromId(id)

Inherited from goog.ui.Component .

Helper function for returning the fragment portion of an id generated using makeId().

id {string}
Id generated with makeId().
returns {string}
Fragment.

.getHtml()

Inherited from goog.ui.tree.BaseNode .

Returns the html of the label.

returns {string}
The html string of the label.

.getIconClass()

Inherited from goog.ui.tree.BaseNode .

Gets the icon class for the node.

returns {string}
s The icon source.

.getId()

Inherited from goog.ui.Component .

Gets the unique ID for the instance of this component. If the instance doesn't already have an ID, generates one on the fly.

returns {string}
Unique component ID.

.getLabelElement()

Inherited from goog.ui.tree.BaseNode .

returns {Element}
The label element.

.getLastChild()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The last child of this node.

.getLastShownDescendant()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The last shown descendant.

.getLineStyle()

Inherited from goog.ui.tree.BaseNode .

returns {string}
The line style.

.getLineStyle2()

Inherited from goog.ui.tree.BaseNode .

returns {string}
The line style.

.getModel()

Inherited from goog.ui.Component .

Returns the model associated with the UI component.

returns {*}
The model.

.getNextShownNode()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The next node to show or null if there isn't a next node to show.

.getNextSibling()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The next sibling of this node.

.getParent()

Inherited from goog.ui.Component .

Returns the component's parent, if any.

returns {goog.ui.Component?}
The parent component.

.getParentEventTarget()

Inherited from goog.events.EventTarget .

Returns the parent of this event target to use for bubbling.

returns {goog.events.EventTarget}
The parent EventTarget or null if there is no parent.

.getPreviousShownNode()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The previous node to show.

.getPreviousSibling()

Inherited from goog.ui.tree.BaseNode .

returns {goog.ui.tree.BaseNode}
The previous sibling of this node.

.getRowElement()

Inherited from goog.ui.tree.BaseNode .

returns {Element}
The row is the div that is used to draw the node without the children.

.getSelectedItem()

Returns the selected item.

returns {goog.ui.tree.BaseNode}
The currently selected item.

.getShowExpandIcons()

returns {boolean}
Whether to show expand icons.

.getShowLines()

returns {boolean}
Whether to show lines.

.getShowRootLines()

returns {boolean}
Whether to show root lines.

.getShowRootNode()

returns {boolean}
Whether to show the root node.

.getText()

Inherited from goog.ui.tree.BaseNode .

Returns the text of the label. If the text was originally set as HTML, the return value is unspecified.

returns {string}
The plain text of the label.

.getToolTip()

Inherited from goog.ui.tree.BaseNode .

Returns the text of the tooltip.

returns {?string}
The tooltip text.

.getTree()

Returns the tree.

.handleKeyEvent(e)

Handles key down on the tree.

e {!goog.events.BrowserEvent}
The browser event.
returns {boolean}
The handled value.

.hasChildren()

Inherited from goog.ui.Component .

Returns true if the component has children.

returns {boolean}
True if the component has children.

.hasFocus()

returns {boolean}
Whether the tree has keyboard focus.

.indexOfChild(child)

Inherited from goog.ui.Component .

Returns the 0-based index of the given child component, or -1 if no such child is found.

child {goog.ui.Component?}
The child component.
returns {number}
0-based index of the child component; -1 if not found.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isInDocument()

Inherited from goog.ui.Component .

Determines whether the component has been added to the document.

returns {boolean}
TRUE if rendered. Otherwise, FALSE.

.isLastSibling()

Inherited from goog.ui.tree.BaseNode .

returns {boolean}
Whether the node is the last sibling.

.isRightToLeft()

Inherited from goog.ui.Component .

Returns true if the component is rendered right-to-left, false otherwise. The first time this function is invoked, the right-to-left rendering property is set if it has not been already.

returns {boolean}
Whether the control is rendered right-to-left.

.isSelected()

Inherited from goog.ui.tree.BaseNode .

returns {boolean}
Whether the node is selected.

.isUserCollapsible()

Inherited from goog.ui.tree.BaseNode .

returns {boolean}
Whether the node is collapsible by user actions.

.makeId(idFragment)

Inherited from goog.ui.Component .

Helper function for subclasses that gets a unique id for a given fragment, this can be used by components to generate unique string ids for DOM elements.

idFragment {string}
A partial id.
returns {string}
Unique element id.

.makeIds(object)

Inherited from goog.ui.Component .

Makes a collection of ids. This is a convenience method for makeId. The object's values are the id fragments and the new values are the generated ids. The key will remain the same.

object {Object}
The object that will be used to create the ids.
returns {Object}
An object of id keys to generated ids.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.removeChild(childNode, opt_unrender)

Inherited from goog.ui.tree.BaseNode .

Removes a child. The caller is responsible for disposing the node.

childNode {goog.ui.Component|string}
The child to remove. Must be a {@link goog.ui.tree.BaseNode}.
opt_unrender {boolean=}
Unused. The child will always be unrendered.
returns {goog.ui.tree.BaseNode}
The child that was removed.
@see
goog.ui.Component#removeChildAt

.removeChildAt(index, opt_unrender)

Inherited from goog.ui.Component .

Removes the child at the given index from this component, and returns it. Throws an error if the argument is out of bounds, or if the specified child isn't found in the parent. See {@link goog.ui.Component#removeChild} for detailed semantics.

index {number}
0-based index of the child to remove.
opt_unrender {boolean=}
If true, calls {@code exitDocument} on the removed child component, and detaches its DOM from the document.
returns {goog.ui.Component}
The removed component, if any.
@see
goog.ui.Component#removeChild

.removeChildren(opt_unrender)

Inherited from goog.ui.Component .

Removes every child component attached to this one and returns them.

opt_unrender {boolean=}
If true, calls {@link #exitDocument} on the removed child components, and detaches their DOM from the document.
returns {!Array.<goog.ui.Component>|undefined}
The removed components if any.
@see
goog.ui.Component#removeChild

.removeEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.removeNode(node)

Allows the caller to notify that the given node is being removed from the tree.

node {goog.ui.tree.BaseNode}
Node being removed.

.render(opt_parentElement)

Inherited from goog.ui.Component .

Renders the component. If a parent element is supplied, the component's element will be appended to it. If there is no optional parent element and the element doesn't have a parentNode then it will be appended to the document body. If this component has a parent component, and the parent component is not in the document already, then this will not call {@code enterDocument} on this component. Throws an Error if the component is already rendered.

opt_parentElement {Element=}
Optional parent element to render the component into.

.renderBefore(sibling)

Inherited from goog.ui.Component .

Renders the component before another element. The other element should be in the document already. Throws an Error if the component is already rendered.

sibling {Node}
Node to render the component before.

.reveal()

Expands the parent chain of this node so that it is visible.

.select()

Inherited from goog.ui.tree.BaseNode .

Selects the node.

.setAfterLabelHtml(html)

Inherited from goog.ui.tree.BaseNode .

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.

html {string}
The html.

.setExpanded(expanded)

Sets the node to be expanded.

expanded {boolean}
Whether to expand or close the node.

.setExpandedIconClass(s)

Inherited from goog.ui.tree.BaseNode .

Sets the icon class for when the node is expanded.

s {string}
The expanded icon class.

.setExpandedInternal(expanded)

Inherited from goog.ui.tree.BaseNode .

Sets the node to be expanded internally, without state change events.

expanded {boolean}
Whether to expand or close the node.

.setHtml(s)

Inherited from goog.ui.tree.BaseNode .

Sets the html of the label.

s {string}
The html string for the label.

.setIconClass(s)

Inherited from goog.ui.tree.BaseNode .

Sets the icon class for the node.

s {string}
The icon class.

.setId(id)

Inherited from goog.ui.Component .

Assigns an ID to this component instance. It is the caller's responsibility to guarantee that the ID is unique. If the component is a child of a parent component, then the parent component's child index is updated to reflect the new ID; this may throw an error if the parent already has a child with an ID that conflicts with the new ID.

id {string}
Unique component ID.

.setIsUserCollapsible(isCollapsible)

Inherited from goog.ui.tree.BaseNode .

Sets whether the node will allow the user to collapse it.

isCollapsible {boolean}
Whether to allow node collapse.

.setModel(obj)

Inherited from goog.ui.Component .

Sets the model associated with the UI component.

obj {*}
The model.

.setNode(node)

Allows the caller to notify that the given node has been added or just had been updated in the tree.

node {goog.ui.tree.BaseNode}
New node being added or existing node that just had been updated.

.setParent(parent)

Inherited from goog.ui.Component .

Sets the parent of this component to use for event bubbling. Throws an error if the component already has a parent or if an attempt is made to add a component to itself as a child. Callers must use {@code removeChild} or {@code removeChildAt} to remove components from their containers before calling this method.

parent {goog.ui.Component}
The parent component.
@see
goog.ui.Component#removeChild
@see
goog.ui.Component#removeChildAt

.setParentEventTarget(parent)

Inherited from goog.ui.Component .

Overrides {@link goog.events.EventTarget#setParentEventTarget} to throw an error if the parent component is set, and the argument is not the parent.

parent {goog.events.EventTarget?}
Parent EventTarget (null if none).

.setRightToLeft(rightToLeft)

Inherited from goog.ui.Component .

Set is right-to-left. This function should be used if the component needs to know the rendering direction during dom creation (i.e. before {@link #enterDocument} is called and is right-to-left is set).

rightToLeft {boolean}
Whether the component is rendered right-to-left.

.setSelectedItem(node)

Sets the selected item.

node {goog.ui.tree.BaseNode}
The item to select.

.setShowExpandIcons(b)

Sets whether to show expand icons.

b {boolean}
Whether to show expand icons.

.setShowLines(b)

Sets whether to show lines.

b {boolean}
Whether to show lines.

.setShowRootLines(b)

Sets whether to show root lines.

b {boolean}
Whether to show root lines.

.setShowRootNode(b)

Sets whether to show the root node.

b {boolean}
Whether to show the root node.

.setText(s)

Inherited from goog.ui.tree.BaseNode .

Sets the text of the label.

s {string}
The plain text of the label.

.setToolTip(s)

Inherited from goog.ui.tree.BaseNode .

Sets the text of the tooltip.

s {string}
The tooltip text to set.

.setTreeInternal(tree)

Inherited from goog.ui.tree.BaseNode .

Internal method that is used to set the tree control on the node.

tree {goog.ui.tree.TreeControl}
The tree control.

.toHtml(sb)

Inherited from goog.ui.tree.BaseNode .

Returns the html for the node.

sb {goog.string.StringBuffer}
A string buffer to append the HTML to.

.toggle()

Inherited from goog.ui.tree.BaseNode .

Toggles the expanded state of the node.

.updateExpandIcon()

Updates the expand icon of the node.

.updateRow()

Inherited from goog.ui.tree.BaseNode .

Updates the row styles.

.wasDecorated()

Inherited from goog.ui.Component .

returns {boolean}
Whether the component was decorated.