Constructor

BaseNode

new BaseNode(content, config)

An abstract base class for a node in the tree. Similar to goog.ui.tree.BaseNode

Parameter

content

string

The content of the node label treated as plain-text and will be HTML escaped.

config

Blockly.tree.BaseNode.Config

The configuration for the tree.

Value must not be null.

Extends
Blockly.Component

Properties

allNodes

protected   static

Object

Map of nodes in existence. Needed to route events to the appropriate nodes. Nodes are added to the map at #enterDocument time and removed at #exitDocument time.

getChildAt

protected

This is re-defined here to indicate to the closure compiler the correct child return type.

Parameter

index

number

0-based index.

Returns

Blockly.tree.BaseNode The child at the given index; null if none.

tree

protected

Blockly.tree.TreeControl

Methods

add

package

add(child)

Appends a node as a child to the current node.

Parameter

child

Blockly.tree.BaseNode

The child to 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

addChildAt

protected

addChildAt(child, index, opt_render)

The method assumes that the child doesn't have parent node yet.

Parameter

child

The new child component.

index

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

Optional

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

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

contains

protected

contains(node) returns boolean

Returns true if the node is a descendant of this node

Parameter

node

Blockly.tree.BaseNode

The node to check.

Returns

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

createDom

protected

createDom()

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

Inherited from
Blockly.tree.BaseNode#createDom

dispose

protected

dispose()

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

Inherited from
Blockly.Component#dispose

disposeInternal

protected

disposeInternal()

Disposes of the component. Calls exitDocument, which is expected to remove event handlers and clean up the component. Propagates the call to the component's children, if any. Removes the component's DOM from the document.

Inherited from
Blockly.tree.BaseNode#disposeInternal

doNodeCollapsed

protected

doNodeCollapsed()

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

doNodeExpanded

protected

doNodeExpanded()

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

enterDocument

protected

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.

Inherited from
Blockly.tree.BaseNode#enterDocument

exitDocument

protected

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.

Inherited from
Blockly.tree.BaseNode#exitDocument

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

Returns

string The background position style value.

getCalculatedIconClass

protected

getCalculatedIconClass()

Gets the calculated icon class.

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.

Returns

non-null Array of non-null Blockly.tree.BaseNode The children.

getChildrenElement

protected

getChildrenElement() returns Element

Returns

Element The div containing the children.

getConfig

protected

getConfig() returns Blockly.tree.BaseNode.Config

Returns

non-null Blockly.tree.BaseNode.Config The configuration for the tree.

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

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

getElement

package

getElement() returns Element

Gets the component's element.

Inherited from
Blockly.tree.BaseNode#getElement
Returns

The element for the tree node.

getExpanded

protected

getExpanded() returns boolean

Returns

boolean Whether the node is expanded.

getExpandedIconClass

protected

getExpandedIconClass() returns string

Gets the icon class for when the node is expanded.

Returns

string The class.

getFirstChild

protected

getFirstChild() returns Blockly.tree.BaseNode

Returns

Blockly.tree.BaseNode The first child of this node.

getIconClass

protected

getIconClass() returns string

Gets the icon class for the node.

Returns

string s The icon source.

getIconDom

protected

getIconDom() returns Element

Returns

non-null Element The HTML for the icon.

getIconElement

protected

getIconElement() returns Element

Returns

Element 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

Returns

non-null Element The HTML element for the label.

getLabelElement

protected

getLabelElement() returns Element

Returns

Element The label element.

getLastChild

protected

getLastChild() returns Blockly.tree.BaseNode

Returns

Blockly.tree.BaseNode The last child of this node.

getLastShownDescendant

protected

getLastShownDescendant() returns Blockly.tree.BaseNode

Returns

Blockly.tree.BaseNode The last shown descendant.

getNextShownNode

protected

getNextShownNode() returns Blockly.tree.BaseNode

Returns

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

getNextSibling

protected

getNextSibling() returns Blockly.tree.BaseNode

Returns

Blockly.tree.BaseNode The next sibling of this node.

getParent

protected

getParent() returns Blockly.Component

Returns the component's parent, if any.

Inherited from
Blockly.Component#getParent
Returns

The parent component.

getPreviousShownNode

protected

getPreviousShownNode() returns Blockly.tree.BaseNode

Returns

Blockly.tree.BaseNode The previous node to show.

getPreviousSibling

protected

getPreviousSibling() returns Blockly.tree.BaseNode

Returns

Blockly.tree.BaseNode The previous sibling of this node.

getRowClassName

protected

getRowClassName() returns string

Returns

string The class name for the row.

getRowDom

protected

getRowDom() returns Element

Returns

non-null Element The HTML element for the row.

getRowElement

package

getRowElement() returns Element

Returns

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

getText

package

getText() returns string

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.

getTree

protected

getTree() returns Blockly.tree.TreeControl

Returns the tree.

Returns

nullable Blockly.tree.TreeControl 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.

indexOfChild

protected

indexOfChild(child) returns number

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

Parameter

child

The child component.

Value may be null.

Inherited from
Blockly.Component#indexOfChild
Returns

0-based index of the child component; -1 if not found.

initAccessibility

protected

initAccessibility()

Adds roles and states.

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

Returns

boolean Whether the node is the last sibling.

isRightToLeft

protected

isRightToLeft() returns boolean

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.

Inherited from
Blockly.Component#isRightToLeft
Returns

Whether the control is rendered right-to-left.

isSelected

protected

isSelected() returns boolean

Returns

boolean Whether the node is selected.

isUserCollapsible

protected

isUserCollapsible() returns boolean

Returns

boolean Whether the node is collapsible by user actions.

onClick_

protected

onClick_(e)

Handles a click event.

Parameter

e

Event

The browser event.

Value must not be null.

onKeyDown

protected

onKeyDown(e) returns boolean

Handles a key down event.

Parameter

e

Event

The browser event.

Value must not be null.

Returns

boolean The handled value.

onMouseDown

protected

onMouseDown(e)

Handles mouse down event.

Parameter

e

Event

The browser event.

Value must not be null.

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

renderBefore

protected

renderBefore(sibling)

Renders the component before another element. The other element should be in the document already.

Throws an Error if the component is already rendered.

Parameter

sibling

Node to render the component before.

Inherited from
Blockly.Component#renderBefore

select

protected

select()

Selects the node.

selectChild

package

selectChild() returns boolean

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

Returns

boolean True if the action has been handled, false otherwise.

selectFirst

protected

selectFirst()

Selects the first node.

selectNext

package

selectNext() returns boolean

Select the next node.

Returns

boolean True if the action has been handled, false otherwise.

selectParent

package

selectParent() returns boolean

Select the parent node or collapse the current node.

Returns

boolean True if the action has been handled, false otherwise.

selectPrevious

package

selectPrevious() returns boolean

Select the previous node.

Returns

boolean 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

boolean

Whether to expand or close the node.

setExpandedInternal

protected

setExpandedInternal(expanded)

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

Parameter

expanded

boolean

Whether to expand or close the node.

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

setRightToLeft

package

setRightToLeft(rightToLeft)

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 #enterDocument is called and is right-to-left is set).

Parameter

rightToLeft

Whether the component is rendered right-to-left.

Inherited from
Blockly.Component#setRightToLeft

setSelectedInternal

protected

setSelectedInternal(selected)

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

Parameter

selected

boolean

The new selection state.

setText

protected

setText(s)

Sets the text of the label.

Parameter

s

string

The plain text of the label.

setTreeInternal

protected

setTreeInternal(tree)

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

Parameter

tree

Blockly.tree.TreeControl

The tree control.

toDom

protected

toDom() returns Element

Creates HTML Element for the node.

Returns

non-null Element HTML element

toggle

protected

toggle()

Toggles the expanded state of the node.

updateExpandIcon

protected

updateExpandIcon()

Updates the expand icon of the node.

updateRow

protected

updateRow()

Updates the row styles.

Abstract type

Config

static

{indentWidth:number, cssRoot:string, cssHideRoot:string, cssTreeRow:string, cssItemLabel:string, cssTreeIcon:string, cssExpandedFolderIcon:string, cssCollapsedFolderIcon:string, cssFileIcon:string, cssSelectedRow:string}

The config type for the tree.