feat(modeling): move external labels with nodes

Closes #105
This commit is contained in:
Nico Rehwaldt 2014-09-11 17:22:59 +02:00
parent eaddbb31c4
commit 8cc530bf58
2 changed files with 62 additions and 1 deletions

View File

@ -10,6 +10,8 @@ var hasExternalLabel = LabelUtil.hasExternalLabel,
function LabelSupport(eventBus, modeling, bpmnFactory) {
// create external labels on shape creation
eventBus.on([
'commandStack.shape.create.postExecute',
'commandStack.connection.create.postExecute'
@ -30,15 +32,52 @@ function LabelSupport(eventBus, modeling, bpmnFactory) {
}
});
// indicate label is dragged during move
eventBus.on('shape.move.start', 50000, function(e) {
var dragContext = e.dragContext,
element = dragContext.element;
var label = element.label;
if (label && dragContext.shapes.indexOf(label) === -1) {
dragContext.shapes.push(label);
}
});
// move labels with shapes
eventBus.on([
'commandStack.shape.move.postExecute'
], function(e) {
var context = e.context,
shape = context.shape;
if (shape.label && context.hints.layout !== false) {
modeling.moveShape(shape.label, context.delta);
}
});
// update di information on label movement and creation
eventBus.on([
'commandStack.label.create.executed',
'commandStack.label.moved.executed'
'commandStack.shape.moved.executed'
], function(e) {
var element = e.context.shape,
businessObject = element.businessObject,
di = businessObject.di;
// we want to trigger on real labels only
if (!element.labelTarget) {
return;
}
if (!di.label) {
di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
bounds: bpmnFactory.create('dc:Bounds')

View File

@ -84,6 +84,28 @@ describe('features/modeling - move shape', function() {
expect(startEvent.di.label.bounds.y).toBe(oldPosition.y + 50);
}));
it('should move label with element', inject(function(elementRegistry, modeling) {
// given
var startEventElement = elementRegistry.getById('StartEvent_1'),
startEvent = startEventElement.businessObject;
var label = startEventElement.label;
var labelPosition = {
x: label.x,
y: label.y
};
// when
modeling.moveShape(startEventElement, { x: 40, y: -80 });
// then
expect(label.x).toBe(labelPosition.x + 40);
expect(label.y).toBe(labelPosition.y - 80);
}));
});