import { Event , EventEmitter , extensions , TreeDataProvider , TreeItem , TreeItemCollapsibleState } from 'vscode' ; import { Item } from './Item' ; import { ItemsModel } from './ItemsModel' ; import * as path from 'path' ; author Kuba Wolanin - Initial contribution
  export class ItemsExplorer implements TreeDataProvider < Item > { private _onDidChangeTreeData : EventEmitter < any > = new EventEmitter < any > ( ) ; readonly onDidChangeTreeData : Event < any > = this . _onDidChangeTreeData . event ; constructor ( ) { this . extensionpath = extensions . getExtension ( "openhab.openhab" ) . extensionPath ; } private extensionpath : string ; private model : ItemsModel ; refresh ( ) { this . _onDidChangeTreeData . fire ( null ) ; } public getTreeItem ( item ) { return { label : item . name + ( item . state ? ' (' + item . state + ')' : '' ) , collapsibleState : item . isGroup ? TreeItemCollapsibleState . Collapsed : TreeItemCollapsibleState . None , contextValue : this . getViewItem ( item ) , iconPath : { light : this . getIcon ( 'light' , item . type ) , dark : this . getIcon ( 'dark' , item . type ) } } ; } param item private getViewItem ( item ) { let type = item . isGroup ? 'Group' : 'Item' ; return item . state ? type : 'stateless' + type ; } param shade param name private getIcon ( shade , name ) { return path . join ( this . extensionpath , 'resources' , shade , name . toLowerCase ( ) + '.svg' ) ; } public getChildren ( item ? ) { if ( ! item ) { if ( ! this . model ) { this . model = new ItemsModel ( ) ; } return this . model . roots ; } return this . model . getChildren ( item ) ; } }