Class: TreeControl

Constructor

TreeControl

new TreeControl(toolbox, config)

An extension of the TreeControl object in closure that provides a way to view a hierarchical set of data. Similar to Closure's goog.ui.tree.TreeControl

Parameter

toolbox

Blockly.Toolbox

The parent toolbox for this tree.

config

Blockly.tree.BaseNode.Config

The configuration for the tree.

Value must not be null.

Extends
Blockly.tree.BaseNode

Properties

config_

protected

unknown

The configuration for the tree.

Inherited from
Blockly.tree.BaseNode#config_

content

package

unknown

Text content of the node label.

Inherited from
Blockly.tree.BaseNode#content

expanded_

protected

unknown

Whether the tree node is expanded.

Inherited from
Blockly.tree.BaseNode#expanded_

expandedIconClass

package

unknown

Inherited from
Blockly.tree.BaseNode#expandedIconClass

getChildAt

protected

This is re-defined here to indicate to the Closure Compiler the correct child return type.

Parameter

index

0-based index.

Inherited from
Blockly.tree.BaseNode#getChildAt
Returns

The child at the given index; null if none.

iconClass

package

unknown

Inherited from
Blockly.tree.BaseNode#iconClass

rightToLeft_

protected

unknown

Whether the component is rendered right-to-left.

Inherited from
Blockly.Component#rightToLeft_

selected_

protected

unknown

Whether the tree item is selected.

Inherited from
Blockly.tree.BaseNode#selected_

tree

protected

unknown

Inherited from
Blockly.tree.BaseNode#tree

Methods

add

package

add(child)

Appends a node as a child to the current node.

Parameter

child

The child to add.

Inherited from
Blockly.tree.BaseNode#add

addChild

package

addChild(child, opt_render)

Adds the specified component as the last child of this component. See Blockly.Component#addChildAt for detailed semantics.

Parameter

child

The new child component.

opt_render

Optional

If true, the child component will be rendered into the parent.

Inherited from
Blockly.Component#addChild
See also
Blockly.Component#addChildAt

contains

protected

contains(node) returns boolean

Returns true if the node is a descendant of this node.

Parameter

node

The node to check.

Inherited from
Blockly.tree.BaseNode#contains
Returns

True if the node is a descendant of this node, false otherwise.

createNode

package

createNode(opt_content) returns Blockly.tree.TreeNode

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

Parameter

opt_content

Optional

string

The content of the node label.

Returns

non-null Blockly.tree.TreeNode The new item.

dispose

package

dispose()

Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal.

Inherited from
Blockly.Component#dispose

doNodeCollapsed

protected

doNodeCollapsed()

Used to notify a node that we have collapsed it. Can be overridden by subclasses, see Blockly.tree.TreeNode.

Inherited from
Blockly.tree.BaseNode#doNodeCollapsed

doNodeExpanded

protected

doNodeExpanded()

Used to notify a node of that we have expanded it. Can be overridden by subclasses, see Blockly.tree.TreeNode.

Inherited from
Blockly.tree.BaseNode#doNodeExpanded

forEachChild

protected

forEachChild(f, opt_obj)

Calls the given function on each of this component's children in order. If 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.

Parameter

f

The function to call for every child component; should take 2 arguments (the child and its index).

opt_obj

Optional

Used as the 'this' object in f when called.

Inherited from
Blockly.Component#forEachChild

getBackgroundPosition

protected

getBackgroundPosition() returns string

Gets a string containing the x and y position of the node's background.

Inherited from
Blockly.tree.BaseNode#getBackgroundPosition
Returns

The background position style value.

getCalculatedIconClass

protected

getCalculatedIconClass() returns string

Returns the source for the icon.

Inherited from
Blockly.tree.TreeControl#getCalculatedIconClass
Returns

Src for the icon.

getChild

protected

getChild(id) returns Blockly.Component

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

Parameter

id

Child component ID.

Inherited from
Blockly.Component#getChild
Returns

The child with the given ID; null if none.

getChildCount

protected

getChildCount() returns number

Returns the number of children of this component.

Inherited from
Blockly.Component#getChildCount
Returns

The number of children.

getChildren

package

getChildren() returns Array of non-null Blockly.tree.BaseNode

Returns the children of this node.

Inherited from
Blockly.tree.BaseNode#getChildren
Returns

The children.

getChildrenElement

protected

getChildrenElement() returns Element

Inherited from
Blockly.tree.BaseNode#getChildrenElement
Returns

The div containing the children.

getContentElement

protected

getContentElement() returns Element

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.

Inherited from
Blockly.Component#getContentElement
Returns

Element to contain child elements (null if none).

getDepth

protected

getDepth() returns number

Return node depth.

Inherited from
Blockly.tree.TreeControl#getDepth
Returns

The non-negative depth of this node (the root is zero).

getIconDom

protected

getIconDom() returns Element

Inherited from
Blockly.tree.BaseNode#getIconDom
Returns

The HTML for the icon.

getIconElement

protected

getIconElement() returns Element

Inherited from
Blockly.tree.TreeControl#getIconElement
Returns

The icon element.

getId

package

getId() returns string

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

Inherited from
Blockly.Component#getId
Returns

Unique component ID.

getLabelDom

protected

getLabelDom() returns Element

Inherited from
Blockly.tree.BaseNode#getLabelDom
Returns

The HTML element for the label.

getLabelElement

protected

getLabelElement() returns Element

Inherited from
Blockly.tree.BaseNode#getLabelElement
Returns

The label element.

getLastShownDescendant

protected

getLastShownDescendant() returns Blockly.tree.BaseNode

Inherited from
Blockly.tree.BaseNode#getLastShownDescendant
Returns

The last shown descendant.

getNextShownNode

protected

getNextShownNode() returns Blockly.tree.BaseNode

Inherited from
Blockly.tree.BaseNode#getNextShownNode
Returns

The next node to show or null if there isn't a next node to show.

getNextSibling

protected

getNextSibling() returns Blockly.tree.BaseNode

Inherited from
Blockly.tree.BaseNode#getNextSibling
Returns

The next sibling of this node.

getParent

protected

getParent() returns Blockly.tree.BaseNode

Returns the node's parent, if any.

Inherited from
Blockly.tree.BaseNode#getParent
Returns

The parent node.

getPreviousShownNode

protected

getPreviousShownNode() returns Blockly.tree.BaseNode

Inherited from
Blockly.tree.BaseNode#getPreviousShownNode
Returns

The previous node to show.

getPreviousSibling

protected

getPreviousSibling() returns Blockly.tree.BaseNode

Inherited from
Blockly.tree.BaseNode#getPreviousSibling
Returns

The previous sibling of this node.

getRowClassName

protected

getRowClassName() returns string

Adds the selected class name to the default row class name if node is selected.

Inherited from
Blockly.tree.TreeControl#getRowClassName
Returns

The class name for the row.

getRowDom

protected

getRowDom() returns Element

Creates row with icon and label dom.

Inherited from
Blockly.tree.BaseNode#getRowDom
Returns

The HTML element for the row.

getRowElement

package

getRowElement() returns Element

Inherited from
Blockly.tree.BaseNode#getRowElement
Returns

The row is the div that is used to draw the node without the children.

getSelectedItem

package

getSelectedItem() returns Blockly.tree.BaseNode

Returns the selected item.

Returns

Blockly.tree.BaseNode The currently selected item.

getToolbox

package

getToolbox() returns Blockly.Toolbox

Returns the associated toolbox.

Returns

Blockly.Toolbox The toolbox.

getTree

protected

getTree() returns Blockly.tree.TreeControl

Returns the tree.

Inherited from
Blockly.tree.TreeControl#getTree
Returns

tree

hasChildren

protected

hasChildren() returns boolean

Returns true if the component has children.

Inherited from
Blockly.Component#hasChildren
Returns

True if the component has children.

initAccessibility

protected

initAccessibility()

Add roles and states.

Inherited from
Blockly.tree.TreeControl#initAccessibility

isInDocument

protected

isInDocument() returns boolean

Determines whether the component has been added to the document.

Inherited from
Blockly.Component#isInDocument
Returns

TRUE if rendered. Otherwise, FALSE.

isLastSibling

protected

isLastSibling() returns boolean

Inherited from
Blockly.tree.BaseNode#isLastSibling
Returns

Whether the node is the last sibling.

isSelected

protected

isSelected() returns boolean

Inherited from
Blockly.tree.BaseNode#isSelected
Returns

Whether the node is selected.

onAfterSelected

package

onAfterSelected(fn)

Set the handler that's triggered after a node is selected.

Parameter

fn

function(Blockly.tree.BaseNode, Blockly.tree.BaseNode)

The handler

onBeforeSelected

package

onBeforeSelected(fn)

Set the handler that's triggered before a node is selected.

Parameter

fn

function(Blockly.tree.BaseNode)

The handler

onClick_

protected

onClick_(e)

Handles a click event.

Parameter

e

The browser event.

Value must not be null.

Inherited from
Blockly.tree.BaseNode#onClick_

onKeyDown

protected

onKeyDown(e) returns boolean

Handles a key down event.

Parameter

e

The browser event.

Value must not be null.

Inherited from
Blockly.tree.BaseNode#onKeyDown
Returns

The handled value.

render

package

render(opt_parentElement)

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 enterDocument on this component.

Throws an Error if the component is already rendered.

Parameter

opt_parentElement

Optional

Optional parent element to render the component into.

Inherited from
Blockly.Component#render

select

protected

select()

Selects the node.

Inherited from
Blockly.tree.BaseNode#select

selectChild

package

selectChild() returns boolean

Expand the current node if it's not already expanded, or select the child node.

Inherited from
Blockly.tree.BaseNode#selectChild
Returns

True if the action has been handled, false otherwise.

selectNext

package

selectNext() returns boolean

Select the next node.

Inherited from
Blockly.tree.BaseNode#selectNext
Returns

True if the action has been handled, false otherwise.

selectParent

package

selectParent() returns boolean

Select the parent node or collapse the current node.

Inherited from
Blockly.tree.BaseNode#selectParent
Returns

True if the action has been handled, false otherwise.

selectPrevious

package

selectPrevious() returns boolean

Select the previous node.

Inherited from
Blockly.tree.BaseNode#selectPrevious
Returns

True if the action has been handled, false otherwise.

setElementInternal

protected

setElementInternal(element)

Sets the component's root element to the given element. Considered protected and final.

This should generally only be called during createDom. Setting the element does not actually change which element is rendered, only the element that is associated with this UI component.

This should only be used by subclasses and its associated renderers.

Parameter

element

Root element for the component.

Inherited from
Blockly.Component#setElementInternal

setExpanded

package

setExpanded(expanded)

Sets the node to be expanded.

Parameter

expanded

Whether to expand or close the node.

Inherited from
Blockly.tree.TreeControl#setExpanded

setParent

protected

setParent(parent)

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.

Parameter

parent

The parent component.

Inherited from
Blockly.Component#setParent

setSelected

protected

setSelected(selected)

Called from the tree to instruct the node change its selection state.

Parameter

selected

The new selection state.

Inherited from
Blockly.tree.BaseNode#setSelected

setSelectedItem

package

setSelectedItem(node)

Sets the selected item.

Parameter

node

Blockly.tree.BaseNode

The item to select.

setTreeInternal

protected

setTreeInternal(tree)

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

Parameter

tree

The tree control.

Inherited from
Blockly.tree.BaseNode#setTreeInternal

toDom

protected

toDom() returns Element

Creates HTML Element for the node.

Inherited from
Blockly.tree.BaseNode#toDom
Returns

HTML element

toggle

protected

toggle()

Toggles the expanded state of the node.

Inherited from
Blockly.tree.BaseNode#toggle

updateExpandIcon

protected

updateExpandIcon()

Updates the expand icon of the node.

Inherited from
Blockly.tree.TreeControl#updateExpandIcon

updateRow

protected

updateRow()

Updates the row styles.

Inherited from
Blockly.tree.BaseNode#updateRow