"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tree = void 0;
const ide_utils_1 = require("@opensumi/ide-utils");
const TreeNode_1 = require("./TreeNode");
class Tree {
    constructor() {
        this.onChangedEmitter = new ide_utils_1.Emitter();
        this.toDispose = new ide_utils_1.DisposableCollection();
        this.nodes = {};
    }
    dispose() {
        var _a;
        this.toDispose.dispose();
        (_a = this._root) === null || _a === void 0 ? void 0 : _a.dispose();
    }
    get root() {
        return this._root;
    }
    set root(root) {
        var _a;
        if (root === this._root) {
            return;
        }
        (_a = this._root) === null || _a === void 0 ? void 0 : _a.dispose();
        this._root = root;
    }
    fireChanged() {
        this.onChangedEmitter.fire(undefined);
    }
    sortComparator(a, b) {
        if (a.constructor === b.constructor) {
            return a.name > b.name ? 1 : a.name < b.name ? -1 : 0;
        }
        return TreeNode_1.CompositeTreeNode.is(a) ? -1 : TreeNode_1.CompositeTreeNode.is(b) ? 1 : 0;
    }
}
exports.Tree = Tree;
//# sourceMappingURL=Tree.js.map