import * as vscode from "vscode" ; import { TreeItemCollapsibleState } from "vscode" ; import { Settings } from "../../Settings" ; import { mavenExplorerProvider } from "../mavenExplorerProvider" ; import { HintNode } from "./HintNode" ; import { ITreeItem } from "./ITreeItem" ; import { MavenProject } from "./MavenProject" ; const CONTEXT_VALUE = "maven:workspaceFolder" ; export class WorkspaceFolder implements ITreeItem { private _workspaceFolder : vscode . WorkspaceFolder ; constructor ( workspaceFolder ) { this . _workspaceFolder = workspaceFolder ; } public getContextValue ( ) { return CONTEXT_VALUE ; } public async getChildren ( ) { const allProjects = await mavenExplorerProvider . loadProjects ( this . _workspaceFolder ) ; if ( allProjects . length === 0 ) { return [ new HintNode ( "No Maven project found." ) ] ; } switch ( Settings . viewType ( ) ) { case "hierarchical" : return this . sortByName ( allProjects . filter ( m => ! m . parent ) ) ; case "flat" : return this . sortByName ( allProjects ) ; default : return [ ] ; } } public getTreeItem ( ) { return new vscode . TreeItem ( this . _workspaceFolder . name , TreeItemCollapsibleState . Expanded ) ; } private sortByName ( arr ) { return arr . sort ( ( a , b ) => { return a . name > b . name ? 1 : a . name < b . name ? - 1 : 0 ; } ) ; } }