Hi,
I managed to include bpmn:resource
elements to bpmn:definitions
using the properties panel by adpating the ExtensionElements.js example as follows:
set: function(element, values, node) {
var action = this.__action;
delete this.__action;
var commands = [];
var definitions = modeler.getDefinitions();
element = definitions;
if (action.id === CREATE_RESOURCE_ELEMENT_ACTION) {
/// Create bpmn:resource element and include an extension element
var resourceElement = elementHelper.createElement('bpmn:Resource', { id: action.value}, definitions, bpmnFactory);
var extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, resourceElement, bpmnFactory);
commands.push(cmdHelper.addElementsTolist(definitions, definitions, 'rootElements', [ resourceElement ]));
commands.push(cmdHelper.updateBusinessObject(definitions, {},{}));
}
else if (action.id === REMOVE_RESOURCE_ELEMENT_ACTION) {
/// Remove bpmn:resource element
var resourceElement = resourceHelper.getResource(action.value);
commands.push(cmdHelper.removeElementsFromList(definitions, definitions, 'rootElements', 'resource', [ resourceElement ]));
commands.push(cmdHelper.updateBusinessObject(definitions, {},{}));
}
return commands;
},
The resource elements are included in the XML as wanted. However, I cannot make the update mechanism for the property panel group function properly. The elements.changed
-event appears to expect an element that can be selected in the modeler - which is not the case for bpmn:Definitions
.
I found a patch by changing PropertiesPanel.js to
eventBus.on('elements.changed', function(e) {
var current = self._current;
var element = current && current.element;
if (element) {
if (e.elements.indexOf(element) !== -1) {
self.update(element);
}
else if ( e.elements[0].$type == 'bpmn:Definitions' ) {
if ( confirm("Use patch to update 'bpmn:Definitions'?") ) {
self.update(e.elements[0]);
}
}
}
});
With this patch the functionality is close to what it should be (except for the annoying popup that I will remove eventually) and my example modeler allows to create, change the id, and remove resource elements after the patch is confirmed once. If the patch is not used, the property panel group is not properly updated and, for example, the entry field for the resource id is not shown or updated.
I assume there is a better way to change model properties (for elements that cannot be selected) and trigger the update for the property panel group. Any suggestions would be very appreciated.