# all files / bpmn-js/lib/features/modeling/behavior/ CreateDataObjectBehavior.js

100% Statements 9/9
100% Branches 4/4
100% Functions 2/2
100% Lines 9/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38

    1189×

    1189×

    420×
    420×

    420×

    12×

    12×

    1×

    1×import inherits from 'inherits';

    import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

    import { is } from '../../../util/ModelUtil';

    /**
     * BPMN specific create data object behavior
     */
    export default function CreateDataObjectBehavior(eventBus, bpmnFactory, moddle) {

      CommandInterceptor.call(this, eventBus);

      this.preExecute('shape.create', function(event) {

        var context = event.context,
            shape = context.shape;

        if (is(shape, 'bpmn:DataObjectReference') && shape.type !== 'label') {

          // create a DataObject every time a DataObjectReference is created
          var dataObject = bpmnFactory.create('bpmn:DataObject');

          // set the reference to the DataObject
          shape.businessObject.dataObjectRef = dataObject;
        }
      });

    }

    CreateDataObjectBehavior.$inject = [
      'eventBus',
      'bpmnFactory',
      'moddle'
    ];

    inherits(CreateDataObjectBehavior, CommandInterceptor);