mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as vscode from 'vscode';
|
|
import * as constants from '../common/constants';
|
|
|
|
import { BaseProjectTreeItem, MessageTreeItem, SpacerTreeItem } from '../models/tree/baseTreeItem';
|
|
import { ProjectRootTreeItem } from '../models/tree/projectTreeItem';
|
|
import { Project } from '../models/project';
|
|
|
|
/**
|
|
* Tree view for database projects
|
|
*/
|
|
export class SqlDatabaseProjectTreeViewProvider implements vscode.TreeDataProvider<BaseProjectTreeItem> {
|
|
private _onDidChangeTreeData: vscode.EventEmitter<BaseProjectTreeItem | undefined> = new vscode.EventEmitter<BaseProjectTreeItem | undefined>();
|
|
readonly onDidChangeTreeData: vscode.Event<BaseProjectTreeItem | undefined> = this._onDidChangeTreeData.event;
|
|
|
|
private roots: BaseProjectTreeItem[] = [];
|
|
|
|
constructor() {
|
|
this.initialize();
|
|
}
|
|
|
|
private initialize() {
|
|
this.roots = [new MessageTreeItem(constants.noOpenProjectMessage)];
|
|
}
|
|
|
|
public getTreeItem(element: BaseProjectTreeItem): vscode.TreeItem {
|
|
return element.treeItem;
|
|
}
|
|
|
|
public getChildren(element?: BaseProjectTreeItem): BaseProjectTreeItem[] {
|
|
if (element === undefined) {
|
|
return this.roots;
|
|
}
|
|
|
|
return element.children;
|
|
}
|
|
|
|
/**
|
|
* Constructs a new set of root nodes from a list of Projects
|
|
* @param projects List of Projects
|
|
*/
|
|
public load(projects: Project[]) {
|
|
let newRoots: BaseProjectTreeItem[] = [];
|
|
|
|
for (const proj of projects) {
|
|
newRoots.push(new ProjectRootTreeItem(proj));
|
|
newRoots.push(SpacerTreeItem);
|
|
}
|
|
|
|
if (newRoots[newRoots.length - 1] === SpacerTreeItem) {
|
|
newRoots.pop(); // get rid of the trailing SpacerTreeItem
|
|
}
|
|
|
|
this.roots = newRoots;
|
|
this._onDidChangeTreeData.fire();
|
|
}
|
|
}
|