mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 17:23:31 -05:00
More Layering (#9139)
* move handling generated files to the serilization classes * remove unneeded methods * add more folders to strictire compile, add more strict compile options * update ci * wip * add more layering and fix issues * add more strictness * remove unnecessary assertion * add missing checks * fix indentation * wip * remove jsdoc * fix layering * fix compile * fix compile errors * wip * wip * finish layering * fix css * more layering * rip * reworking results serializer * move some files around * move capabilities to platform wip * implement capabilities register provider * fix capabilities service * fix usage of the regist4ry * add contribution * wip * wip * wip * remove no longer good parts * fix strict-nulls * fix issues with startup * another try * fix startup * fix imports * fix tests * fix tests * fix more tests * fix tests * fix more tests * fix broken test * fix tabbing * fix naming * wip * finished layering * fix imports * fix valid layers * fix layers
This commit is contained in:
178
src/sql/workbench/services/objectExplorer/common/treeNode.ts
Normal file
178
src/sql/workbench/services/objectExplorer/common/treeNode.ts
Normal file
@@ -0,0 +1,178 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { NodeType, SqlThemeIcon } from 'sql/workbench/services/objectExplorer/common/nodeType';
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
import * as UUID from 'vs/base/common/uuid';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export enum TreeItemCollapsibleState {
|
||||
None = 0,
|
||||
Collapsed = 1,
|
||||
Expanded = 2
|
||||
}
|
||||
|
||||
export interface ObjectExplorerCallbacks {
|
||||
getChildren(treeNode: TreeNode): Thenable<TreeNode[]>;
|
||||
isExpanded(treeNode: TreeNode): Thenable<boolean>;
|
||||
setNodeExpandedState(TreeNode: TreeNode, expandedState: TreeItemCollapsibleState): Thenable<void>;
|
||||
setNodeSelected(TreeNode: TreeNode, selected: boolean, clearOtherSelections?: boolean): Thenable<void>;
|
||||
}
|
||||
|
||||
export class TreeNode {
|
||||
/**
|
||||
* Informs who provides the children to a node, used by data explorer tree view api
|
||||
*/
|
||||
public childProvider: string;
|
||||
/**
|
||||
* Holds the connection profile for nodes, used by data explorer tree view api
|
||||
*/
|
||||
public payload: any;
|
||||
/**
|
||||
* id for TreeNode
|
||||
*/
|
||||
public id: string;
|
||||
|
||||
/**
|
||||
* string defining the type of the node - for example Server, Database, Folder, Table
|
||||
*/
|
||||
public nodeTypeId: string;
|
||||
|
||||
/**
|
||||
* Label to display to the user, describing this node
|
||||
*/
|
||||
public label: string;
|
||||
|
||||
/**
|
||||
* Is this a leaf node (in which case no children can be generated) or is it expandable?
|
||||
*/
|
||||
public isAlwaysLeaf: boolean;
|
||||
|
||||
/**
|
||||
* Message to show if this Node is in an error state. This indicates
|
||||
* that children could be retrieved
|
||||
*/
|
||||
public errorStateMessage: string;
|
||||
|
||||
/**
|
||||
* Parent of this node
|
||||
*/
|
||||
public parent: TreeNode;
|
||||
|
||||
/**
|
||||
* Path identifying this node
|
||||
*/
|
||||
public nodePath: string;
|
||||
|
||||
/**
|
||||
* Node sub type
|
||||
*/
|
||||
public nodeSubType: string;
|
||||
|
||||
/**
|
||||
* Node Status
|
||||
*/
|
||||
public nodeStatus: string;
|
||||
|
||||
/**
|
||||
* Children of this node
|
||||
*/
|
||||
public children: TreeNode[];
|
||||
|
||||
|
||||
public connection: ConnectionProfile;
|
||||
|
||||
public session: azdata.ObjectExplorerSession;
|
||||
|
||||
public metadata: azdata.ObjectMetadata;
|
||||
|
||||
public iconType: string | SqlThemeIcon;
|
||||
|
||||
public iconPath: URI | { light: URI, dark: URI };
|
||||
|
||||
constructor(nodeTypeId: string, label: string, isAlwaysLeaf: boolean, nodePath: string,
|
||||
nodeSubType: string, nodeStatus: string, parent: TreeNode, metadata: azdata.ObjectMetadata,
|
||||
iconType: string | SqlThemeIcon,
|
||||
private _objectExplorerCallbacks: ObjectExplorerCallbacks) {
|
||||
this.nodeTypeId = nodeTypeId;
|
||||
this.label = label;
|
||||
this.isAlwaysLeaf = isAlwaysLeaf;
|
||||
this.nodePath = nodePath;
|
||||
this.parent = parent;
|
||||
this.metadata = metadata;
|
||||
this.iconType = iconType;
|
||||
this.id = UUID.generateUuid();
|
||||
this.nodeSubType = nodeSubType;
|
||||
this.nodeStatus = nodeStatus;
|
||||
}
|
||||
public getConnectionProfile(): ConnectionProfile {
|
||||
let currentNode: TreeNode = this;
|
||||
while (!currentNode.connection && currentNode.parent) {
|
||||
currentNode = currentNode.parent;
|
||||
}
|
||||
return currentNode.connection;
|
||||
}
|
||||
|
||||
public getDatabaseName(): string {
|
||||
if (this.connection) {
|
||||
return undefined;
|
||||
}
|
||||
let currentNode: TreeNode = this;
|
||||
while (currentNode.nodeTypeId !== NodeType.Database && currentNode.nodeTypeId !== NodeType.Server && currentNode.parent) {
|
||||
currentNode = currentNode.parent;
|
||||
}
|
||||
|
||||
if (currentNode && currentNode.nodeTypeId === NodeType.Database) {
|
||||
return currentNode.metadata ? currentNode.metadata.name : null;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getSession(): azdata.ObjectExplorerSession {
|
||||
let currentNode: TreeNode = this;
|
||||
while (!currentNode.session && currentNode.parent) {
|
||||
currentNode = currentNode.parent;
|
||||
}
|
||||
return currentNode.session;
|
||||
}
|
||||
|
||||
public isTopLevel(): boolean {
|
||||
if (this.parent && this.parent.nodeTypeId === NodeType.Root) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public toNodeInfo(): azdata.NodeInfo {
|
||||
return <azdata.NodeInfo>{
|
||||
nodePath: this.nodePath,
|
||||
nodeType: this.nodeTypeId,
|
||||
nodeSubType: this.nodeSubType,
|
||||
nodeStatus: this.nodeStatus,
|
||||
label: this.label,
|
||||
isLeaf: this.isAlwaysLeaf,
|
||||
metadata: this.metadata,
|
||||
errorMessage: this.errorStateMessage
|
||||
};
|
||||
}
|
||||
|
||||
public getChildren(): Thenable<TreeNode[]> {
|
||||
return this._objectExplorerCallbacks.getChildren(this);
|
||||
}
|
||||
|
||||
public isExpanded(): Thenable<boolean> {
|
||||
return this._objectExplorerCallbacks.isExpanded(this);
|
||||
}
|
||||
|
||||
public setExpandedState(expandedState: TreeItemCollapsibleState): Thenable<void> {
|
||||
return this._objectExplorerCallbacks.setNodeExpandedState(this, expandedState);
|
||||
}
|
||||
|
||||
public setSelected(selected: boolean, clearOtherSelections?: boolean): Thenable<void> {
|
||||
return this._objectExplorerCallbacks.setNodeSelected(this, selected, clearOtherSelections);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
||||
|
||||
export class TreeNodeContextKey implements IContextKey<TreeNode> {
|
||||
|
||||
static NodeType = new RawContextKey<string>('nodeType', undefined);
|
||||
static SubType = new RawContextKey<string>('nodeSubType', undefined);
|
||||
static Status = new RawContextKey<string>('nodeStatus', undefined);
|
||||
static TreeNode = new RawContextKey<TreeNode>('treeNode', undefined);
|
||||
static NodeLabel = new RawContextKey<string>('nodeLabel', undefined);
|
||||
|
||||
private _nodeTypeKey: IContextKey<string>;
|
||||
private _subTypeKey: IContextKey<string>;
|
||||
private _statusKey: IContextKey<string>;
|
||||
private _treeNodeKey: IContextKey<TreeNode>;
|
||||
private _nodeLabelKey: IContextKey<string>;
|
||||
|
||||
constructor(
|
||||
@IContextKeyService contextKeyService: IContextKeyService
|
||||
) {
|
||||
this._nodeTypeKey = TreeNodeContextKey.NodeType.bindTo(contextKeyService);
|
||||
this._subTypeKey = TreeNodeContextKey.SubType.bindTo(contextKeyService);
|
||||
this._statusKey = TreeNodeContextKey.Status.bindTo(contextKeyService);
|
||||
this._treeNodeKey = TreeNodeContextKey.TreeNode.bindTo(contextKeyService);
|
||||
this._nodeLabelKey = TreeNodeContextKey.NodeLabel.bindTo(contextKeyService);
|
||||
}
|
||||
|
||||
set(value: TreeNode) {
|
||||
this._treeNodeKey.set(value);
|
||||
this._nodeTypeKey.set(value && value.nodeTypeId);
|
||||
this._subTypeKey.set(value && value.nodeSubType);
|
||||
this._statusKey.set(value && value.nodeStatus);
|
||||
this._nodeLabelKey.set(value && value.label);
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this._nodeTypeKey.reset();
|
||||
this._subTypeKey.reset();
|
||||
this._statusKey.reset();
|
||||
this._treeNodeKey.reset();
|
||||
this._nodeLabelKey.reset();
|
||||
}
|
||||
|
||||
public get(): TreeNode {
|
||||
return this._treeNodeKey.get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user