Class: BaseNode

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.

config_

protected

non-null Blockly.tree.BaseNode.Config

The configuration for the tree.

content

package

string

Text content of the node label.

expanded_

protected

boolean

Whether the tree node is expanded.

expandedIconClass

package

string

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.

iconClass

package

string

rightToLeft_

protected

unknown

Whether the component is rendered right-to-left.

Inherited from
Blockly.Component#rightToLeft_

selected_

protected

boolean

Whether the tree item is selected.

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

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.

Inherited from
Blockly.tree.BaseNode#createDom

dispose

package

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 overridden by subclasses, see Blockly.tree.TreeNode.

doNodeExpanded

protected

doNodeExpanded()

Used to notify a node of that we have expanded it. Can be overridden 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

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

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.

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 HTMLElement

Gets the component's element.

Inherited from
Blockly.tree.BaseNode#getElement
Returns

The element for the tree node.

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.

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.tree.BaseNode

Returns the node's parent, if any.

Returns

nullable Blockly.tree.BaseNode The parent node.

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

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

Returns

string The class name for the row.

getRowDom

protected

getRowDom() returns Element

Creates row with icon and label dom.

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.

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.

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.

isSelected

protected

isSelected() returns boolean

Returns

boolean Whether the node is selected.

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.

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.

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.

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.

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

boolean

The new selection state.

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.