Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface TreeDecorator

The TreeDecorator allows adapting the look and the style of the tree items within a widget. Changes are reflected in the form of decoration data. This decoration data is a map storing {@link TreeDecoration.Data} for affected tree nodes (using the unique node id as key). It is important to notice that there is no common contribution point for TreeDecorators. Instead, each TreeDecoratorService is supposed to declare its own contribution provider for TreeDecorators.

Example usage

A simple tree decorator that changes the background color of each tree node to red.

@injectable()
export class MyTreeDecorator implements TreeDecorator {
    id = 'myTreeDecorator';

    protected readonly emitter = new Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>();

    get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> {
        return this.emitter.event;
    }

    decorations(tree: Tree): MaybePromise<Map<string, TreeDecoration.Data>> {
        const result = new Map();

        if (tree.root === undefined) {
            return result;
        }
        for (const treeNode of new DepthFirstTreeIterator(tree.root)) {
            result.set(treeNode.id,<TreeDecoration.Data>{backgroundColor:'red'})
        }
        return result;
    }
}

Hierarchy

  • TreeDecorator

Implemented by

Index

Properties

Readonly id

id: string

The unique identifier of the decorator. Ought to be unique in the application.

Readonly onDidChangeDecorations

onDidChangeDecorations: Event<(tree: Tree) => Map<string, TreeDecoration.Data>>

Fired when this decorator has calculated all the decoration data for the tree nodes.

Methods

decorations

  • Computes the current decoration data for the given tree. Might return a promise if the computation is handled asynchronously.

    Parameters

    • tree: Tree

      the tree to decorate.

    Returns MaybePromise<Map<string, TreeDecoration.Data>>

    (a promise of) a map containing the current {@linkTreeDecoration.Data} for each node. Keys are the unique identifier of the tree nodes.