2018-04-02 21:01:53 +02:00
|
|
|
import inherits from 'inherits';
|
2015-03-23 15:15:32 +01:00
|
|
|
|
2018-04-02 21:01:53 +02:00
|
|
|
import BaseModeling from 'diagram-js/lib/features/modeling/Modeling';
|
2014-07-23 18:53:33 +02:00
|
|
|
|
2018-04-02 21:01:53 +02:00
|
|
|
import UpdatePropertiesHandler from './cmd/UpdatePropertiesHandler';
|
|
|
|
import UpdateCanvasRootHandler from './cmd/UpdateCanvasRootHandler';
|
|
|
|
import AddLaneHandler from './cmd/AddLaneHandler';
|
|
|
|
import SplitLaneHandler from './cmd/SplitLaneHandler';
|
|
|
|
import ResizeLaneHandler from './cmd/ResizeLaneHandler';
|
|
|
|
import UpdateFlowNodeRefsHandler from './cmd/UpdateFlowNodeRefsHandler';
|
|
|
|
import IdClaimHandler from './cmd/IdClaimHandler';
|
|
|
|
import SetColorHandler from './cmd/SetColorHandler';
|
2014-07-23 18:53:33 +02:00
|
|
|
|
2018-04-02 21:01:53 +02:00
|
|
|
import UpdateLabelHandler from '../label-editing/cmd/UpdateLabelHandler';
|
2018-01-24 20:25:28 +01:00
|
|
|
|
2015-02-02 14:46:21 +01:00
|
|
|
|
2014-07-23 18:53:33 +02:00
|
|
|
/**
|
|
|
|
* BPMN 2.0 modeling features activator
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
2014-12-07 13:08:50 +01:00
|
|
|
* @param {ElementFactory} elementFactory
|
2014-07-23 18:53:33 +02:00
|
|
|
* @param {CommandStack} commandStack
|
2015-04-16 09:11:04 +02:00
|
|
|
* @param {BpmnRules} bpmnRules
|
2014-07-23 18:53:33 +02:00
|
|
|
*/
|
2018-04-02 21:01:53 +02:00
|
|
|
export default function Modeling(
|
|
|
|
eventBus, elementFactory, commandStack,
|
|
|
|
bpmnRules) {
|
|
|
|
|
2014-12-07 13:08:50 +01:00
|
|
|
BaseModeling.call(this, eventBus, elementFactory, commandStack);
|
2015-04-16 09:11:04 +02:00
|
|
|
|
|
|
|
this._bpmnRules = bpmnRules;
|
2014-07-23 18:53:33 +02:00
|
|
|
}
|
|
|
|
|
2015-03-23 15:15:32 +01:00
|
|
|
inherits(Modeling, BaseModeling);
|
2014-07-23 18:53:33 +02:00
|
|
|
|
2018-04-02 21:01:53 +02:00
|
|
|
Modeling.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'elementFactory',
|
|
|
|
'commandStack',
|
|
|
|
'bpmnRules'
|
|
|
|
];
|
2014-07-23 18:53:33 +02:00
|
|
|
|
2015-03-23 15:15:32 +01:00
|
|
|
|
2015-01-06 16:28:39 +01:00
|
|
|
Modeling.prototype.getHandlers = function() {
|
|
|
|
var handlers = BaseModeling.prototype.getHandlers.call(this);
|
2014-07-23 18:53:33 +02:00
|
|
|
|
2015-01-06 16:28:39 +01:00
|
|
|
handlers['element.updateProperties'] = UpdatePropertiesHandler;
|
2015-03-31 15:02:04 +02:00
|
|
|
handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
|
2015-10-10 01:40:52 +02:00
|
|
|
handlers['lane.add'] = AddLaneHandler;
|
|
|
|
handlers['lane.resize'] = ResizeLaneHandler;
|
|
|
|
handlers['lane.split'] = SplitLaneHandler;
|
2015-10-15 23:50:15 +02:00
|
|
|
handlers['lane.updateRefs'] = UpdateFlowNodeRefsHandler;
|
2016-04-18 16:15:00 +02:00
|
|
|
handlers['id.updateClaim'] = IdClaimHandler;
|
2016-11-28 14:26:42 +01:00
|
|
|
handlers['element.setColor'] = SetColorHandler;
|
2018-01-24 20:25:28 +01:00
|
|
|
handlers['element.updateLabel'] = UpdateLabelHandler;
|
2015-01-02 16:15:18 +01:00
|
|
|
|
2015-01-06 16:28:39 +01:00
|
|
|
return handlers;
|
2014-07-23 18:53:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-08 16:01:40 +02:00
|
|
|
Modeling.prototype.updateLabel = function(element, newLabel, newBounds, hints) {
|
2014-08-04 09:32:36 +02:00
|
|
|
this._commandStack.execute('element.updateLabel', {
|
|
|
|
element: element,
|
2018-01-24 20:25:28 +01:00
|
|
|
newLabel: newLabel,
|
2018-06-08 16:01:40 +02:00
|
|
|
newBounds: newBounds,
|
|
|
|
hints: hints || {}
|
2014-08-04 09:32:36 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-22 14:38:44 +02:00
|
|
|
Modeling.prototype.connect = function(source, target, attrs, hints) {
|
2014-09-11 16:44:56 +02:00
|
|
|
|
2015-04-16 09:11:04 +02:00
|
|
|
var bpmnRules = this._bpmnRules;
|
2014-09-11 16:44:56 +02:00
|
|
|
|
|
|
|
if (!attrs) {
|
2017-04-10 14:21:14 +02:00
|
|
|
attrs = bpmnRules.canConnect(source, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!attrs) {
|
|
|
|
return;
|
2014-09-11 16:44:56 +02:00
|
|
|
}
|
|
|
|
|
2016-06-22 14:38:44 +02:00
|
|
|
return this.createConnection(source, target, attrs, source.parent, hints);
|
2014-10-27 12:07:57 +01:00
|
|
|
};
|
2015-01-02 16:15:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
Modeling.prototype.updateProperties = function(element, properties) {
|
|
|
|
this._commandStack.execute('element.updateProperties', {
|
|
|
|
element: element,
|
|
|
|
properties: properties
|
|
|
|
});
|
2015-03-31 15:02:04 +02:00
|
|
|
};
|
|
|
|
|
2015-10-10 01:40:52 +02: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 15:02:04 +02: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 23:50:15 +02:00
|
|
|
Modeling.prototype.updateLaneRefs = function(flowNodeShapes, laneShapes) {
|
|
|
|
|
|
|
|
this._commandStack.execute('lane.updateRefs', {
|
|
|
|
flowNodeShapes: flowNodeShapes,
|
|
|
|
laneShapes: laneShapes
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-31 15:02:04 +02: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 10:37:43 +02:00
|
|
|
};
|
2016-04-18 16:15:00 +02: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
|
|
|
|
});
|
|
|
|
};
|
2016-11-28 14:26:42 +01:00
|
|
|
|
|
|
|
Modeling.prototype.setColor = function(elements, colors) {
|
|
|
|
if (!elements.length) {
|
|
|
|
elements = [ elements ];
|
|
|
|
}
|
|
|
|
|
|
|
|
this._commandStack.execute('element.setColor', {
|
|
|
|
elements: elements,
|
|
|
|
colors: colors
|
|
|
|
});
|
|
|
|
};
|