parent
4e161427b8
commit
34e3fa33fd
|
@ -11,6 +11,7 @@ import {
|
|||
} from '../../../util/LabelUtil';
|
||||
|
||||
import {
|
||||
getDi,
|
||||
is
|
||||
} from '../../../util/ModelUtil';
|
||||
|
||||
|
@ -23,7 +24,30 @@ var NULL_DIMENSIONS = {
|
|||
/**
|
||||
* A handler that updates the text of a BPMN element.
|
||||
*/
|
||||
export default function UpdateLabelHandler(modeling, textRenderer) {
|
||||
export default function UpdateLabelHandler(modeling, textRenderer, bpmnFactory) {
|
||||
|
||||
/**
|
||||
* Creates an empty `diLabel` attribute for embedded labels.
|
||||
*
|
||||
* @param {djs.model.Base} element
|
||||
* @param {string} text
|
||||
*/
|
||||
function ensureInternalLabelDi(element, text) {
|
||||
if (isLabelExternal(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var di = getDi(element);
|
||||
|
||||
if (text && !di.label) {
|
||||
di.label = bpmnFactory.create('bpmndi:BPMNLabel');
|
||||
}
|
||||
|
||||
if (!text && di.label) {
|
||||
di.label = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the label and return the changed elements.
|
||||
|
@ -42,6 +66,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
|
|||
|
||||
setLabel(label, text, labelTarget !== label);
|
||||
|
||||
ensureInternalLabelDi(element, text);
|
||||
|
||||
return [ label, labelTarget ];
|
||||
}
|
||||
|
||||
|
@ -127,7 +153,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
|
|||
|
||||
UpdateLabelHandler.$inject = [
|
||||
'modeling',
|
||||
'textRenderer'
|
||||
'textRenderer',
|
||||
'bpmnFactory'
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
|
||||
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.10.0">
|
||||
<bpmn:process id="Process_1" isExecutable="false">
|
||||
<bpmn:startEvent id="StartEvent_1" name="Foo" />
|
||||
<bpmn:startEvent id="StartEvent_2" />
|
||||
<bpmn:task id="Task_1" />
|
||||
<bpmn:task id="Task_2" name="Task 2" />
|
||||
<bpmn:textAnnotation id="TextAnnotation_1">
|
||||
<bpmn:text></bpmn:text>
|
||||
</bpmn:textAnnotation>
|
||||
|
@ -29,6 +30,10 @@
|
|||
<bpmndi:BPMNShape id="TextAnnotation_1_di" bpmnElement="TextAnnotation_1">
|
||||
<dc:Bounds x="426" y="220" width="100" height="30" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_0rxkqbk_di" bpmnElement="Task_2">
|
||||
<dc:Bounds x="460" y="80" width="100" height="80" />
|
||||
<bpmndi:BPMNLabel />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Group_1_di" bpmnElement="Group_1">
|
||||
<dc:Bounds x="165" y="190" width="150" height="120" />
|
||||
</bpmndi:BPMNShape>
|
||||
|
|
|
@ -131,20 +131,6 @@ describe('features/modeling - update label', function() {
|
|||
));
|
||||
|
||||
|
||||
it('should change name of task', inject(function(modeling, elementRegistry) {
|
||||
|
||||
// given
|
||||
var task_1 = elementRegistry.get('Task_1');
|
||||
|
||||
// when
|
||||
modeling.updateLabel(task_1, 'foo');
|
||||
|
||||
// then
|
||||
expect(task_1.businessObject.name).to.equal('foo');
|
||||
expect(task_1.label).to.be.undefined;
|
||||
}));
|
||||
|
||||
|
||||
it('should change text annotation text and bounds', inject(
|
||||
function(modeling, elementRegistry) {
|
||||
|
||||
|
@ -234,4 +220,36 @@ describe('features/modeling - update label', function() {
|
|||
expect(element).to.have.bounds(newBounds);
|
||||
}));
|
||||
|
||||
|
||||
describe('embedded labels', function() {
|
||||
|
||||
it('should change name of task', inject(function(modeling, elementRegistry) {
|
||||
|
||||
// given
|
||||
var task_1 = elementRegistry.get('Task_1');
|
||||
|
||||
// when
|
||||
modeling.updateLabel(task_1, 'foo');
|
||||
|
||||
// then
|
||||
expect(task_1.businessObject.name).to.equal('foo');
|
||||
expect(task_1.di.label).to.exist;
|
||||
}));
|
||||
|
||||
|
||||
it('should delete label of task', inject(function(modeling, elementRegistry) {
|
||||
|
||||
// given
|
||||
var task_2 = elementRegistry.get('Task_2');
|
||||
|
||||
// when
|
||||
modeling.updateLabel(task_2, '');
|
||||
|
||||
// then
|
||||
expect(task_2.businessObject.name).to.equal('');
|
||||
expect(task_2.di.label).not.to.exist;
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue