import { DataProvider } from "./dataprovider" ; import { Event , EventEmitter , TreeItem } from "vscode" ; import { DataProviderEnum } from "../../bll/utils/constants" ; import { injectable } from "inversify" ; import { CheckInInfo } from "../../bll/entities/checkininfo" ; import { CvsResource } from "../../bll/entities/cvsresources/cvsresource" ; import { CvsResourceItem } from "../../bll/entities/cvsresources/cvsresourceitem" ; import { Logger } from "../../bll/utils/logger" ; import { CheckInInfoItem } from "../../bll/entities/presentable/checkininfoitem" ; import { Utils } from "../../bll/utils/utils" ; import { IResourceProvider } from "./interfaces/iresourceprovider" ; @ injectable ( ) export class ResourceProvider extends DataProvider implements IResourceProvider { private _onDidChangeTreeData : EventEmitter < any > = new EventEmitter < any > ( ) ; readonly onDidChangeTreeData : Event < any > = this . _onDidChangeTreeData . event ; private checkInArray : CheckInInfoItem [ ] = [ ] ; setContent ( checkInArray ) { Utils . clearArray ( this . checkInArray ) ; checkInArray . forEach ( ( changes ) => this . checkInArray . push ( new CheckInInfoItem ( changes ) ) ) ; } resetTreeContent ( ) { this . checkInArray = [ ] ; } refreshTreePresentation ( ) { this . _onDidChangeTreeData . fire ( ) ; } getChildren ( element ? ) { if ( ! element ) { return this . checkInArray ; } else if ( element instanceof CheckInInfoItem ) { return element . cvsLocalResources ; } Logger . logError ( "A content of a Resource Provider was not determined." + element ) ; return [ ] ; } public getSelectedContent ( ) { const result = [ ] ; if ( this . checkInArray ) { this . checkInArray . forEach ( ( checkInInfoItem ) => { const checkInInfoToPush = this . getCheckInInfoWithIncludedResources ( checkInInfoItem ) ; if ( checkInInfoToPush . cvsLocalResources . length !== 0 ) { result . push ( checkInInfoToPush ) ; } } ) ; } return result ; } private getCheckInInfoWithIncludedResources ( checkInInfo ) { const includedResources = [ ] ; const localResources = checkInInfo . cvsLocalResources ; localResources . forEach ( ( resource ) => { if ( resource . isIncluded ) { includedResources . push ( resource . item ) ; } } ) ; return new CheckInInfo ( includedResources , checkInInfo . item . getCvsProvider ( ) , checkInInfo . item . getWorkspaceRootPath ( ) ) ; } public getType ( ) { return DataProviderEnum . ResourcesProvider ; } }