Set default Listener


#1

HI,

I’m trying to set listener when element is created. I’m using CustoemElementFactory to detect if selected element is my element. Here’s my code:

  this.create = function(elementType, attrs) {
    var type = attrs.type;

    if (elementType === 'label') {
      return self.baseCreate(elementType, assign({ type: 'label' }, LabelUtil.DEFAULT_LABEL_SIZE, attrs));
    }

    // check if element is my element
    if (/^custom\:/.test(type)) {
       
      [...]
      // convert my custom element to "bpmn:UserTask"
      [...]
      var element = self.createBpmnElement(elementType, attrs);
      element.businessObject.name = "Foobar";
     // here I want to set listener 
      return element;
    }

    return self.createBpmnElement(elementType, attrs);
};

#2

Looks good. What is your question?


#3

get the ‘moddle’ module from the bpmnDiagram and create the listener like this:

var moddle = bpmnDiagram.get('moddle');
var extensionElements = moddle.create('bpmn:ExtensionElements');
var executionListener = moddle.create('camunda:ExecutionListener');
executionListener.class = 'myCustomDelegateClassName';
executionListener.event = 'start';
extensionElements.values.push(executionListener);

now update the properties using the modeling.

var modeling = bpmnDiagram.get('modeling');
modeling.updateProperties(element, {extensionElements: extensionElements});