2015-07-13 08:37:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var assign = require('lodash/object/assign'),
|
|
|
|
inherits = require('inherits');
|
|
|
|
|
2015-09-02 13:13:18 +00:00
|
|
|
var LabelUtil = require('../../util/LabelUtil'),
|
|
|
|
is = require('../../util/ModelUtil').is;
|
2015-07-13 08:37:43 +00:00
|
|
|
|
|
|
|
var hasExternalLabel = LabelUtil.hasExternalLabel,
|
|
|
|
getExternalLabelMid = LabelUtil.getExternalLabelMid;
|
|
|
|
|
|
|
|
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
|
|
|
|
|
|
|
|
|
|
|
function LabelSupport(eventBus, modeling, bpmnFactory) {
|
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
// create external labels on shape creation
|
|
|
|
|
|
|
|
this.postExecute([ 'shape.create', 'connection.create' ], function(e) {
|
|
|
|
var context = e.context;
|
|
|
|
|
|
|
|
var element = context.shape || context.connection,
|
|
|
|
businessObject = element.businessObject;
|
|
|
|
|
|
|
|
var position;
|
|
|
|
|
|
|
|
if (hasExternalLabel(businessObject)) {
|
|
|
|
position = getExternalLabelMid(element);
|
|
|
|
modeling.createLabel(element, position, {
|
|
|
|
id: businessObject.id + '_label',
|
|
|
|
businessObject: businessObject
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// update di information on label movement and creation
|
|
|
|
this.executed([ 'label.create', 'shape.moved' ], function(e) {
|
|
|
|
var element = e.context.shape,
|
2015-09-02 13:13:18 +00:00
|
|
|
businessObject,
|
|
|
|
di;
|
2015-07-13 08:37:43 +00:00
|
|
|
|
|
|
|
// we want to trigger on real labels only
|
|
|
|
if (!element.labelTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-02 13:13:18 +00:00
|
|
|
// we want to trigger on BPMN elements only
|
|
|
|
if (!is(element.labelTarget || element, 'bpmn:BaseElement')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
businessObject = element.businessObject,
|
|
|
|
di = businessObject.di;
|
|
|
|
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
if (!di.label) {
|
|
|
|
di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
|
|
|
|
bounds: bpmnFactory.create('dc:Bounds')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
assign(di.label.bounds, {
|
|
|
|
x: element.x,
|
|
|
|
y: element.y,
|
|
|
|
width: element.width,
|
|
|
|
height: element.height
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(LabelSupport, CommandInterceptor);
|
|
|
|
|
|
|
|
LabelSupport.$inject = [ 'eventBus', 'modeling', 'bpmnFactory' ];
|
|
|
|
|
|
|
|
module.exports = LabelSupport;
|