Class: TreeModelAdapter

core.TreeModelAdapter

Class representing an adapter for treating a core.ListModel with a role for the depth level as a tree with collapsible nodes.

This adapter extends the original list items with a new role for the status of the tree node. The status is an object with these properties:

  • collapsed: Whether the node is currently collapsed.
  • verticals: A list of booleans telling for each depth level up to this node if there are vertical lines going past this node. This information can be used for rendering branch lines.

A tree model may be used anywhere a list model is expected.

Dynamic Content

The list model can be populated dynamically when uncollapsing a node by defining the dynamicContentProvider function. This function takes a tree node index and is expected to return a Promise for a list of node items (async functions return a Promise automatically).

TreeModelAdapter {
    model: listModel
    dynamicContentProvider: async (idx) =>
    {
        const item = at(idx);
        const nodes = [];
        for (let i = 0; i < 10; ++i)
        {
            nodes.push({
                name: "Item #" + (i + 1),
                level: item.level + 1,
                nodeType: "folder"
            });
        }
        return nodes;
    }
}

The thus newly created node items are removed from the model automatically when collapsing an ancestor node.

new core.TreeModelAdapter ()

Properties:
Name Type Description
levelRole string

(default: "level") The name of the role holding the depth level of a tree node.

dynamicContentProvider function

(default: null) If this function is defined, it will be used to fill the model with content dynamically when uncollapsing a node.

statusRole string

(default: "nodeStatus") The name of the role to be used for the status of a tree node.

model core.ListModel

(default: null) The list model to work on.

Extends

Methods

setCollapsed (n, value)

Sets the collapsion state of a tree node.

Name Type Description
n number

The tree index of the node.

value bool

Whether the node shall be collapsed.

toListIndex (n)number

Converts a tree index to a list index of the underlying list model.

Name Type Description
n number

The tree index.

Returns:
Type Description
number
  • The list index.

toTreeIndex (n)number

Converts a list index of the underlying list model to a tree index. If the list item is currently not visible in the tree due to a collapsed ancestor, -1 will be returned instead.

Name Type Description
n number

The list index.

Returns:
Type Description
number
  • The tree index, or -1 if the list item is not visible in the tree.