import * as vscode from 'vscode' ; import { INode } from './INode' ; import { Constants } from '../common/constants' ; import { Global } from '../common/global' ; import { IConnection } from '../common/IConnection' ; import { ConnectionNode } from './connectionNode' ; export class PostgreSQLTreeDataProvider implements vscode . TreeDataProvider < INode > { public _onDidChangeTreeData : vscode . EventEmitter < INode > = new vscode . EventEmitter < INode > ( ) ; public readonly onDidChangeTreeData : vscode . Event < INode > = this . _onDidChangeTreeData . event ; private static _instance : PostgreSQLTreeDataProvider = null ; constructor ( public context ) { this . refresh ( ) ; } public static getInstance ( context ? ) { if ( context && ! this . _instance ) { this . _instance = new PostgreSQLTreeDataProvider ( context ) ; context . subscriptions . push ( vscode . window . registerTreeDataProvider ( "postgres" , this . _instance ) ) ; } return this . _instance ; } public refresh ( element ? ) { this . _onDidChangeTreeData . fire ( element ) ; } public getTreeItem ( element ) { return element . getTreeItem ( ) ; } public getChildren ( element ? ) { if ( ! element ) { return this . getConnectionNodes ( ) ; } return element . getChildren ( ) ; } private async getConnectionNodes ( ) { const connections = this . context . globalState . get < { [ key ] : IConnection ; } > ( Constants . GlobalStateKey ) ; const ConnectionNodes = [ ] ; if ( connections ) { for ( const id of Object . keys ( connections ) ) { let connection = Object . assign ( { } , connections [ id ] ) ; if ( connection . hasPassword || ! connection . hasOwnProperty ( 'hasPassword' ) ) { connection . password = await Global . context . secrets . get ( id ) ; } ConnectionNodes . push ( new ConnectionNode ( id , connection ) ) ; } } return ConnectionNodes ; } }