@@ -66,12 +66,79 @@ export default class BpmnPropertiesPanelRenderer {
6666 this . _selectedElement = null ;
6767 this . _groups = [ ] ;
6868
69- eventBus . on ( 'selection.changed' , ( ) => this . _update ( ) ) ;
70- eventBus . on ( 'elements.changed' , ( ) => this . _update ( ) ) ;
71- eventBus . on ( 'elementTemplates.changed' , ( ) => this . _update ( ) ) ;
72- eventBus . on ( 'propertiesPanel.providersChanged' , ( ) => this . _update ( ) ) ;
69+ const update = ( ) => {
70+ updateSelectedElement ( ) ;
71+ updateGroups ( ) ;
7372
74- eventBus . on ( 'propertiesPanel.setLayout' , event => this . _updateLayout ( event ) ) ;
73+ this . _render ( ) ;
74+
75+ eventBus . fire ( 'propertiesPanel.updated' , {
76+ element : this . _selectedElement
77+ } ) ;
78+ } ;
79+
80+ const updateSelectedElement = ( ) => {
81+ const canvas = injector . get ( 'canvas' ) ,
82+ selection = injector . get ( 'selection' ) ;
83+
84+ const rootElement = canvas . getRootElement ( ) ;
85+
86+ if ( isImplicitRoot ( rootElement ) ) {
87+ this . _selectedElement = rootElement ;
88+
89+ return ;
90+ }
91+
92+ const selectedElements = selection . get ( ) ;
93+
94+ if ( selectedElements . length > 1 ) {
95+ this . _selectedElement = selectedElements ;
96+ } else if ( selectedElements . length === 1 ) {
97+ let newSelectedElement = selectedElements [ 0 ] ;
98+
99+ // handle labels
100+ if ( newSelectedElement . type === 'label' ) {
101+ newSelectedElement = newSelectedElement . labelTarget ;
102+ }
103+
104+ this . _selectedElement = newSelectedElement ;
105+ } else {
106+ this . _selectedElement = rootElement ;
107+ }
108+ } ;
109+
110+ const updateGroups = ( ) => {
111+ if ( ! this . _selectedElement || isImplicitRoot ( this . _selectedElement ) || isArray ( this . _selectedElement ) ) {
112+ this . _groups = [ ] ;
113+
114+ return ;
115+ }
116+
117+ const providers = this . _getProviders ( this . _selectedElement ) ;
118+
119+ this . _groups = reduce ( providers , ( groups , provider ) => {
120+ const updater = provider . getGroups ( this . _selectedElement ) ;
121+
122+ return updater ( groups ) ;
123+ } , [ ] ) ;
124+ } ;
125+
126+ const updateLayout = ( { layout } ) => {
127+ this . _layoutConfig = layout ;
128+
129+ this . _render ( ) ;
130+
131+ eventBus . fire ( 'propertiesPanel.updated' , {
132+ element : this . _selectedElement
133+ } ) ;
134+ } ;
135+
136+ eventBus . on ( 'selection.changed' , update ) ;
137+ eventBus . on ( 'elements.changed' , update ) ;
138+ eventBus . on ( 'elementTemplates.changed' , update ) ;
139+ eventBus . on ( 'propertiesPanel.providersChanged' , update ) ;
140+
141+ eventBus . on ( 'propertiesPanel.setLayout' , updateLayout ) ;
75142 }
76143
77144 /**
@@ -192,73 +259,6 @@ export default class BpmnPropertiesPanelRenderer {
192259 this . _eventBus . fire ( 'propertiesPanel.destroyed' ) ;
193260 }
194261 }
195-
196- _update ( ) {
197- this . _updateSelectedElement ( ) ;
198- this . _updateGroups ( ) ;
199-
200- this . _render ( ) ;
201-
202- this . _eventBus . fire ( 'propertiesPanel.updated' , {
203- element : this . _selectedElement
204- } ) ;
205- }
206-
207- _updateSelectedElement ( ) {
208- const canvas = this . _injector . get ( 'canvas' ) ,
209- selection = this . _injector . get ( 'selection' ) ;
210-
211- const rootElement = canvas . getRootElement ( ) ;
212-
213- if ( isImplicitRoot ( rootElement ) ) {
214- this . _selectedElement = rootElement ;
215-
216- return ;
217- }
218-
219- const selectedElements = selection . get ( ) ;
220-
221- if ( selectedElements . length > 1 ) {
222- this . _selectedElement = selectedElements ;
223- } else if ( selectedElements . length === 1 ) {
224- let newSelectedElement = selectedElements [ 0 ] ;
225-
226- // handle labels
227- if ( newSelectedElement . type === 'label' ) {
228- newSelectedElement = newSelectedElement . labelTarget ;
229- }
230-
231- this . _selectedElement = newSelectedElement ;
232- } else {
233- this . _selectedElement = rootElement ;
234- }
235- }
236-
237- _updateGroups ( ) {
238- if ( ! this . _selectedElement || isImplicitRoot ( this . _selectedElement ) || isArray ( this . _selectedElement ) ) {
239- this . _groups = [ ] ;
240-
241- return ;
242- }
243-
244- const providers = this . _getProviders ( this . _selectedElement ) ;
245-
246- this . _groups = reduce ( providers , ( groups , provider ) => {
247- const updater = provider . getGroups ( this . _selectedElement ) ;
248-
249- return updater ( groups ) ;
250- } , [ ] ) ;
251- }
252-
253- _updateLayout ( { layout } ) {
254- this . _layoutConfig = layout ;
255-
256- this . _render ( ) ;
257-
258- this . _eventBus . fire ( 'propertiesPanel.updated' , {
259- element : this . _selectedElement
260- } ) ;
261- }
262262}
263263
264264BpmnPropertiesPanelRenderer . $inject = [ 'config.propertiesPanel' , 'injector' , 'eventBus' ] ;
0 commit comments