import { Widget } from '@phosphor/widgets' ; import { Message } from '@phosphor/messaging/lib' ; import { TYPES } from 'sprotty' ; import { DiagramWidget , DiagramWidgetOptions , TheiaSprottyConnector } from 'sprotty-theia' ; import { Deferred } from '@theia/core/lib/common/promise-util' ; import { SearchBoxFactory , SearchBox } from '@theia/core/lib/browser/tree/search-box' ; import { DepGraphModelSource } from '../graph/model-source' ; import { Container } from 'inversify' ; export class DepGraphWidget extends DiagramWidget { protected readonly searchBox : SearchBox ; attached = new Deferred < void > ( ) ; get modelSource ( ) : DepGraphModelSource { return this . diContainer . get ( TYPES . ModelSource ) ; } get diagramType ( ) : string { return this . options . diagramType ; } constructor ( options , searchBoxFactory , id , diContainer , connector ? ) { super ( options , id , diContainer , connector ) ; this . searchBox = searchBoxFactory ( { delay : 300 } ) ; this . toDispose . pushAll ( [ this . searchBox , this . searchBox . onTextChange ( data => ( this . modelSource ) . filter ( data || '' ) ) , this . searchBox . onClose ( ( ) => ( this . modelSource ) . filter ( '' ) ) ] ) ; } protected onAfterAttach ( msg ) { super . onAfterAttach ( msg ) ; if ( this . searchBox . isAttached ) { Widget . detach ( this . searchBox ) ; } Widget . attach ( this . searchBox , this . node . parentElement ! ) ; this . addKeyListener ( this . node , this . searchBox . keyCodePredicate . bind ( this . searchBox ) , this . searchBox . handle . bind ( this . searchBox ) ) ; this . attached . resolve ( ) ; } protected onBeforeDetach ( msg ) { this . attached = new Deferred < void > ( ) ; super . onBeforeDetach ( msg ) ; } }