2014-06-11 13:08:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
var LabelUtil = require('../LabelUtil');
|
|
|
|
|
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
/**
|
|
|
|
* A handler that updates the text a BPMN element.
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
|
|
|
* @param {BpmnRegistry} bpmnRegistry
|
|
|
|
* @param {ElementRegistry} elementRegistry
|
|
|
|
*/
|
|
|
|
function UpdateTextHandler(eventBus, bpmnRegistry, elementRegistry) {
|
|
|
|
|
|
|
|
function setText(element, text) {
|
|
|
|
|
|
|
|
var semantic = bpmnRegistry.getSemantic(element);
|
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
LabelUtil.setLabel(semantic, text);
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
eventBus.fire('element.changed', { element: element.label || element });
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function execute(ctx) {
|
|
|
|
setText(ctx.element, ctx.newText);
|
|
|
|
}
|
|
|
|
|
|
|
|
function revert(ctx) {
|
|
|
|
setText(ctx.element, ctx.oldText);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function canExecute(ctx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// API
|
|
|
|
|
|
|
|
this.execute = execute;
|
|
|
|
this.revert = revert;
|
|
|
|
|
|
|
|
this.canExecute = canExecute;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateTextHandler.$inject = [ 'eventBus', 'bpmnRegistry' ];
|
|
|
|
|
|
|
|
module.exports = UpdateTextHandler;
|