11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT license.
33
4+ import * as _ from "lodash" ;
45import { ProviderResult , ThemeIcon , TreeItem , TreeItemCollapsibleState , Uri } from "vscode" ;
56import { INodeData } from "../java/nodeData" ;
67import { ExplorerNode } from "./explorerNode" ;
@@ -15,6 +16,7 @@ export abstract class DataNode extends ExplorerNode {
1516 const item = new TreeItem ( this . _nodeData . name , this . hasChildren ( ) ? TreeItemCollapsibleState . Collapsed : TreeItemCollapsibleState . None ) ;
1617 item . iconPath = this . iconPath ;
1718 item . command = this . command ;
19+ item . contextValue = this . computeContextValue ( ) ;
1820 return item ;
1921 }
2022 }
@@ -31,6 +33,10 @@ export abstract class DataNode extends ExplorerNode {
3133 return this . _nodeData . path ;
3234 }
3335
36+ public get name ( ) { // return name like `referenced-library`
37+ return _ . kebabCase ( this . _nodeData . name ) ;
38+ }
39+
3440 public async revealPaths ( paths : INodeData [ ] ) : Promise < DataNode > {
3541 const childNodeData = paths . shift ( ) ;
3642 const children : ExplorerNode [ ] = await this . getChildren ( ) ;
@@ -49,6 +55,17 @@ export abstract class DataNode extends ExplorerNode {
4955 return this . createChildNodeList ( ) ;
5056 }
5157
58+ protected computeContextValue ( ) : string {
59+ let contextValue = this . contextValue ;
60+ if ( this . uri ) {
61+ contextValue = `${ contextValue || "" } +uri` ;
62+ }
63+ if ( contextValue ) {
64+ contextValue = `java:${ contextValue } ` ;
65+ }
66+ return contextValue ;
67+ }
68+
5269 protected sort ( ) {
5370 this . nodeData . children . sort ( ( a : INodeData , b : INodeData ) => {
5471 if ( a . kind === b . kind ) {
@@ -63,6 +80,10 @@ export abstract class DataNode extends ExplorerNode {
6380 return true ;
6481 }
6582
83+ protected get contextValue ( ) : string {
84+ return undefined ;
85+ }
86+
6687 protected abstract get iconPath ( ) : string | Uri | { light : string | Uri ; dark : string | Uri } | ThemeIcon ;
6788
6889 protected abstract loadData ( ) : Thenable < any [ ] > ;
0 commit comments