/******************************************************************************** * Copyright (C) 2017 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { Emitter, Event, WaitUntilEvent } from '@gedit/utils'; import { Disposable, DisposableCollection } from '@gedit/utils'; import { CancellationToken } from '@gedit/utils'; import { Mutable } from '@gedit/utils'; export declare const Tree: unique symbol; /** * The tree - an abstract data type. */ export interface Tree = T & CompositeTreeNode> extends Disposable { /** * A root node of this tree. * Undefined if there is no root node. * Setting a root node refreshes the tree. */ root: T | undefined; /** * Emit when the tree is changed. */ readonly onChanged: Event; /** * Emit when the children of the given node are refreshed. */ readonly onNodeRefreshed: Event & WaitUntilEvent>; /** * Emits when the busy state of the given node is changed. */ readonly onDidChangeBusy: Event; /** * Return a node for the given identifier or undefined if such does not exist. */ getNode(id: string | undefined): T | undefined; /** * Return a valid node in this tree matching to the given; otherwise undefined. */ validateNode(node: T | undefined): T | undefined; /** * Refresh children of the root node. * * Return a valid refreshed composite root or `undefined` if such does not exist. */ refresh(): Promise | undefined>; /** * Refresh children of a node for the give node id if it is valid. * * Return a valid refreshed composite node or `undefined` if such does not exist. */ refresh(parent: Readonly): Promise | undefined>; /** * Marks the give node as busy after a specified number of milliseconds. * A token source of the given token should be canceled to unmark. */ markAsBusy(node: Readonly, ms: number, token: CancellationToken): Promise; size: number; } /** * The tree node. */ export interface TreeNode { /** * An unique id of this node. */ readonly id: string; /** * A human-readable name of this tree node. * */ readonly name?: string; /** * A css string for this tree node icon. * * @deprecated use `LabelProvider.getIcon` instead or move this property to your tree node type */ readonly icon?: string; /** * A human-readable description of this tree node. * * @deprecated use `LabelProvider.getLongName` instead or move this property to your tree node type */ readonly description?: string; /** * Test whether this node should be rendered. * If undefined then node will be rendered. */ readonly visible?: boolean; /** * A parent node of this tree node. * Undefined if this node is root. */ readonly parent: CompositeTreeNode | undefined; /** * A previous sibling of this tree node. */ readonly previousSibling?: TreeNode; /** * A next sibling of this tree node. */ readonly nextSibling?: TreeNode; /** * Whether this node is busy. Greater than 0 then busy; otherwise not. */ readonly busy?: number; } export declare namespace TreeNode { function is(node: Object | undefined): node is TreeNode; function equals(left: TreeNode | undefined, right: TreeNode | undefined): boolean; function isVisible(node: TreeNode | undefined): boolean; } /** * The composite tree node. */ export interface CompositeTreeNode extends TreeNode { /** * Child nodes of this tree node. */ children: ReadonlyArray; } export declare namespace CompositeTreeNode { function is(node: Object | undefined): node is CompositeTreeNode; function getFirstChild(parent: CompositeTreeNode): TreeNode | undefined; function getLastChild(parent: CompositeTreeNode): TreeNode | undefined; function isAncestor(parent: CompositeTreeNode, child: TreeNode | undefined): boolean; function indexOf(parent: CompositeTreeNode, node: TreeNode | undefined): number; function addChildren(parent: CompositeTreeNode, children: TreeNode[]): CompositeTreeNode; function addChild(parent: CompositeTreeNode, child: TreeNode): CompositeTreeNode; function removeChild(parent: CompositeTreeNode, child: TreeNode): void; function setParent(child: TreeNode, index: number, parent: CompositeTreeNode): void; } /** * A default implementation of the tree. */ export declare class TreeImpl = T & CompositeTreeNode> implements Tree { protected readonly onChangedEmitter: Emitter; protected readonly onNodeRefreshedEmitter: Emitter; readonly toDispose: DisposableCollection; protected readonly onDidChangeBusyEmitter: Emitter; readonly onDidChangeBusy: Event; protected nodes: { [id: string]: Mutable | undefined; }; constructor(); protected _root: T | undefined; get root(): T | C | undefined; set root(root: T | C | undefined); get onChanged(): Event; get onNodeRefreshed(): Event; dispose(): void; getNode(id: string | undefined): T | undefined; validateNode(node: T | undefined): T | undefined; refresh(raw?: C): Promise; markAsBusy(raw: T, ms: number, token: CancellationToken): Promise; protected fireChanged(): void; protected fireNodeRefreshed(parent: C): Promise; protected resolveChildren(parent: C): Promise; protected setChildren(parent: C, children: T[]): Promise; protected removeNode(node: T | undefined): void; protected getRootNode(node: T): T; protected addNode(node: T | undefined): void; protected doMarkAsBusy(node: Mutable, ms: number, token: CancellationToken): Promise; protected doSetBusy(node: Mutable, busy: boolean): void; get size(): number; } //# sourceMappingURL=tree.d.ts.map