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'),
|
2015-10-09 23:40:52 +00:00
|
|
|
UpdateCanvasRootHandler = require('./cmd/UpdateCanvasRootHandler'),
|
|
|
|
AddLaneHandler = require('./cmd/AddLaneHandler'),
|
|
|
|
SplitLaneHandler = require('./cmd/SplitLaneHandler'),
|
2015-10-15 21:50:15 +00:00
|
|
|
ResizeLaneHandler = require('./cmd/ResizeLaneHandler'),
|
2016-04-18 14:15:00 +00:00
|
|
|
UpdateFlowNodeRefsHandler = require('./cmd/UpdateFlowNodeRefsHandler'),
|
|
|
|
IdClaimHandler = require('./cmd/IdClaimHandler');
|
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-10-09 23:40:52 +00:00
|
|
|
handlers['lane.add'] = AddLaneHandler;
|
|
|
|
handlers['lane.resize'] = ResizeLaneHandler;
|
|
|
|
handlers['lane.split'] = SplitLaneHandler;
|
2015-10-15 21:50:15 +00:00
|
|
|
handlers['lane.updateRefs'] = UpdateFlowNodeRefsHandler;
|
2016-04-18 14:15:00 +00:00
|
|
|
handlers['id.updateClaim'] = IdClaimHandler;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-18 05:54:58 +00:00
|
|
|
Modeling.prototype.updateLabel = function(element, newLabel) {
|
2014-08-04 07:32:36 +00:00
|
|
|
this._commandStack.execute('element.updateLabel', {
|
|
|
|
element: element,
|
2016-05-18 05:54:58 +00:00
|
|
|
newLabel: newLabel
|
2014-08-04 07:32:36 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-10-09 23:40:52 +00:00
|
|
|
Modeling.prototype.resizeLane = function(laneShape, newBounds, balanced) {
|
|
|
|
this._commandStack.execute('lane.resize', {
|
|
|
|
shape: laneShape,
|
|
|
|
newBounds: newBounds,
|
|
|
|
balanced: balanced
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Modeling.prototype.addLane = function(targetLaneShape, location) {
|
|
|
|
var context = {
|
|
|
|
shape: targetLaneShape,
|
|
|
|
location: location
|
|
|
|
};
|
|
|
|
|
|
|
|
this._commandStack.execute('lane.add', context);
|
|
|
|
|
|
|
|
return context.newLane;
|
|
|
|
};
|
|
|
|
|
|
|
|
Modeling.prototype.splitLane = function(targetLane, count) {
|
|
|
|
this._commandStack.execute('lane.split', {
|
|
|
|
shape: targetLane,
|
|
|
|
count: count
|
|
|
|
});
|
|
|
|
};
|
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;
|
|
|
|
};
|
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
Modeling.prototype.updateLaneRefs = function(flowNodeShapes, laneShapes) {
|
|
|
|
|
|
|
|
this._commandStack.execute('lane.updateRefs', {
|
|
|
|
flowNodeShapes: flowNodeShapes,
|
|
|
|
laneShapes: laneShapes
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
};
|
2016-04-18 14:15:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
Modeling.prototype.claimId = function(id, moddleElement) {
|
|
|
|
this._commandStack.execute('id.updateClaim', {
|
|
|
|
id: id,
|
|
|
|
element: moddleElement,
|
|
|
|
claiming: true
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Modeling.prototype.unclaimId = function(id, moddleElement) {
|
|
|
|
this._commandStack.execute('id.updateClaim', {
|
|
|
|
id: id,
|
|
|
|
element: moddleElement
|
|
|
|
});
|
|
|
|
};
|