constructor()

in src/views/dependencyExplorer.ts [41:132]


    constructor(public readonly context: ExtensionContext) {
        this._dataProvider = new DependencyDataProvider(context);
        this._dependencyViewer = window.createTreeView("javaProjectExplorer", { treeDataProvider: this._dataProvider, showCollapseAll: true });

        // register reveal events
        context.subscriptions.push(
            window.onDidChangeActiveTextEditor((textEditor: TextEditor | undefined) => {
                if (this._dependencyViewer.visible && textEditor?.document) {
                    const uri: Uri = textEditor.document.uri;
                    this.reveal(uri);
                }
            }),
            this._dependencyViewer.onDidChangeVisibility((e: TreeViewVisibilityChangeEvent) => {
                if (e.visible) {
                    sendInfo("", { projectManagerVisible: 1 });
                    if (window.activeTextEditor) {
                        this.reveal(window.activeTextEditor.document.uri);
                    }
                }
            }),
            this._dataProvider.onDidChangeTreeData(() => {
                if (this._dependencyViewer.visible && window.activeTextEditor) {
                    this.reveal(window.activeTextEditor.document.uri);
                }
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_IN_PROJECT_EXPLORER, async (uri: Uri) => {
                await commands.executeCommand(Commands.JAVA_PROJECT_EXPLORER_FOCUS);
                let fsPath: string = uri.fsPath;
                const fileName: string = path.basename(fsPath);
                if (/(.*\.gradle)|(.*\.gradle\.kts)|(pom\.xml)$/.test(fileName)) {
                    fsPath = path.dirname(fsPath);
                }
                uri = Uri.file(fsPath);
                if ((await fse.stat(fsPath)).isFile()) {
                    await commands.executeCommand(Commands.VSCODE_OPEN, uri, { preserveFocus: true });
                }

                this.reveal(uri, false /*force to reveal even the sync setting is turned off*/);
            }),
        );

        // register telemetry events
        context.subscriptions.push(
            this._dependencyViewer.onDidChangeSelection((_e: TreeViewSelectionChangeEvent<ExplorerNode>) => {
                EventCounter.increase("didChangeSelection");
            }),
            this._dependencyViewer.onDidCollapseElement((_e: TreeViewExpansionEvent<ExplorerNode>) => {
                EventCounter.increase("didCollapseElement");
            }),
            this._dependencyViewer.onDidExpandElement((_e: TreeViewExpansionEvent<ExplorerNode>) => {
                EventCounter.increase("didExpandElement");
            }),
        );

        // register keybinding commands
        context.subscriptions.push(
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_CLASS, async (node?: DataNode) => {
                newJavaClass(node);
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_PACKAGE, async (node?: DataNode) => {
                let cmdNode = getCmdNode(this._dependencyViewer.selection, node);
                if (!cmdNode) {
                    cmdNode = await this.promptForProjectNode();
                }
                newPackage(cmdNode);
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: DataNode) => {
                const cmdNode = getCmdNode(this._dependencyViewer.selection, node);
                if (cmdNode?.uri) {
                    commands.executeCommand("revealFileInOS", Uri.parse(cmdNode.uri));
                }
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node?: DataNode) => {
                const cmdNode = getCmdNode(this._dependencyViewer.selection, node);
                if (cmdNode?.uri) {
                    commands.executeCommand("copyFilePath", Uri.parse(cmdNode.uri));
                }
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node?: DataNode) => {
                const cmdNode = getCmdNode(this._dependencyViewer.selection, node);
                if (cmdNode?.uri) {
                    commands.executeCommand("copyRelativeFilePath", Uri.parse(cmdNode.uri));
                }
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_RENAME_FILE, (node?: DataNode) => {
                renameFile(getCmdNode(this._dependencyViewer.selection, node));
            }),
            instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_MOVE_FILE_TO_TRASH, (node?: DataNode) => {
                deleteFiles(getCmdNode(this._dependencyViewer.selection, node));
            }),
        );
    }