Adding and updating bpmn:Resource in bpmn:Definitions using property panel

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.

According to the specification bpmn:ResourceRole elements can not be added to bpmn:Definitions elements. They can however be added to bpmn:Process elements. Are you sure you’re not trying to add resources to the wrong element?

I am actually concerned with bpmn:Resource and not bpmn:ResourceRole. In the BPMN 2.02 spec, page 169, Table 10.19, the resource element is a direct child of definitions. This is what I want to achieve.

I assume that there is some better way to register a property panel entry to trigger updates than patching PropertyPanel.js, but so far I didn’t figure out how to.