2014-07-23 16:53:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-23 14:15:32 +00:00
|
|
|
var inherits = require('inherits');
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
var BaseModeling = require('diagram-js/lib/features/modeling/Modeling');
|
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
var UpdatePropertiesHandler = require('./cmd/UpdatePropertiesHandler'),
|
|
|
|
UpdateCanvasRootHandler = require('./cmd/UpdateCanvasRootHandler');
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* BPMN 2.0 modeling features activator
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
2014-12-07 12:08:50 +00:00
|
|
|
* @param {ElementFactory} elementFactory
|
2014-07-23 16:53:33 +00:00
|
|
|
* @param {CommandStack} commandStack
|
2015-04-16 07:11:04 +00:00
|
|
|
* @param {BpmnRules} bpmnRules
|
2014-07-23 16:53:33 +00:00
|
|
|
*/
|
2015-04-16 07:11:04 +00:00
|
|
|
function Modeling(eventBus, elementFactory, commandStack, bpmnRules) {
|
2014-12-07 12:08:50 +00:00
|
|
|
BaseModeling.call(this, eventBus, elementFactory, commandStack);
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
this._bpmnRules = bpmnRules;
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 14:15:32 +00:00
|
|
|
inherits(Modeling, BaseModeling);
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
Modeling.$inject = [ 'eventBus', 'elementFactory', 'commandStack', 'bpmnRules' ];
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
module.exports = Modeling;
|
|
|
|
|
2015-03-23 14:15:32 +00:00
|
|
|
|
2015-01-06 15:28:39 +00:00
|
|
|
Modeling.prototype.getHandlers = function() {
|
|
|
|
var handlers = BaseModeling.prototype.getHandlers.call(this);
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-01-06 15:28:39 +00:00
|
|
|
handlers['element.updateProperties'] = UpdatePropertiesHandler;
|
2015-03-31 13:02:04 +00:00
|
|
|
handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
|
2015-01-02 15:15:18 +00:00
|
|
|
|
2015-01-06 15:28:39 +00:00
|
|
|
return handlers;
|
2014-07-23 16:53:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-04 07:32:36 +00:00
|
|
|
Modeling.prototype.updateLabel = function(element, newLabel) {
|
|
|
|
this._commandStack.execute('element.updateLabel', {
|
|
|
|
element: element,
|
|
|
|
newLabel: newLabel
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-11 14:44:56 +00:00
|
|
|
Modeling.prototype.connect = function(source, target, attrs) {
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
var bpmnRules = this._bpmnRules;
|
2014-09-11 14:44:56 +00:00
|
|
|
|
|
|
|
if (!attrs) {
|
2015-10-06 10:33:21 +00:00
|
|
|
attrs = bpmnRules.canConnect(source, target) || { type: 'bpmn:Association' };
|
2014-09-11 14:44:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 12:21:56 +00:00
|
|
|
return this.createConnection(source, target, attrs, source.parent);
|
2014-10-27 11:07:57 +00:00
|
|
|
};
|
2015-01-02 15:15:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
Modeling.prototype.updateProperties = function(element, properties) {
|
|
|
|
this._commandStack.execute('element.updateProperties', {
|
|
|
|
element: element,
|
|
|
|
properties: properties
|
|
|
|
});
|
2015-03-31 13:02:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the current diagram into a collaboration.
|
|
|
|
*
|
|
|
|
* @return {djs.model.Root} the new root element
|
|
|
|
*/
|
|
|
|
Modeling.prototype.makeCollaboration = function() {
|
|
|
|
|
|
|
|
var collaborationElement = this._create('root', {
|
|
|
|
type: 'bpmn:Collaboration'
|
|
|
|
});
|
|
|
|
|
|
|
|
var context = {
|
|
|
|
newRoot: collaborationElement
|
|
|
|
};
|
|
|
|
|
|
|
|
this._commandStack.execute('canvas.updateRoot', context);
|
|
|
|
|
|
|
|
return collaborationElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the current diagram into a process.
|
|
|
|
*
|
|
|
|
* @return {djs.model.Root} the new root element
|
|
|
|
*/
|
|
|
|
Modeling.prototype.makeProcess = function() {
|
|
|
|
|
|
|
|
var processElement = this._create('root', {
|
|
|
|
type: 'bpmn:Process'
|
|
|
|
});
|
|
|
|
|
|
|
|
var context = {
|
|
|
|
newRoot: processElement
|
|
|
|
};
|
|
|
|
|
|
|
|
this._commandStack.execute('canvas.updateRoot', context);
|
2015-07-13 08:37:43 +00:00
|
|
|
};
|