2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2015-03-23 14:15:32 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import BaseModeling from 'diagram-js/lib/features/modeling/Modeling';
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2020-11-19 10:20:30 +00:00
|
|
|
import UpdateModdlePropertiesHandler from './cmd/UpdateModdlePropertiesHandler';
|
2018-04-02 19:01:53 +00: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 16:53:33 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import UpdateLabelHandler from '../label-editing/cmd/UpdateLabelHandler';
|
2018-01-24 19:25:28 +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
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default 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
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
Modeling.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'elementFactory',
|
|
|
|
'commandStack',
|
|
|
|
'bpmnRules'
|
|
|
|
];
|
2014-07-23 16:53:33 +00:00
|
|
|
|
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
|
|
|
|
2020-11-19 10:20:30 +00:00
|
|
|
handlers['element.updateModdleProperties'] = UpdateModdlePropertiesHandler;
|
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;
|
2016-11-28 13:26:42 +00:00
|
|
|
handlers['element.setColor'] = SetColorHandler;
|
2018-01-24 19:25:28 +00:00
|
|
|
handlers['element.updateLabel'] = UpdateLabelHandler;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-08 14:01:40 +00:00
|
|
|
Modeling.prototype.updateLabel = function(element, newLabel, newBounds, hints) {
|
2014-08-04 07:32:36 +00:00
|
|
|
this._commandStack.execute('element.updateLabel', {
|
|
|
|
element: element,
|
2018-01-24 19:25:28 +00:00
|
|
|
newLabel: newLabel,
|
2018-06-08 14:01:40 +00:00
|
|
|
newBounds: newBounds,
|
|
|
|
hints: hints || {}
|
2014-08-04 07:32:36 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
Modeling.prototype.connect = function(source, target, attrs, hints) {
|
2014-09-11 14:44:56 +00:00
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
var bpmnRules = this._bpmnRules;
|
2014-09-11 14:44:56 +00:00
|
|
|
|
|
|
|
if (!attrs) {
|
2017-04-10 12:21:14 +00:00
|
|
|
attrs = bpmnRules.canConnect(source, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!attrs) {
|
|
|
|
return;
|
2014-09-11 14:44:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
return this.createConnection(source, target, attrs, source.parent, hints);
|
2014-10-27 11:07:57 +00:00
|
|
|
};
|
2015-01-02 15:15:18 +00:00
|
|
|
|
|
|
|
|
2020-11-19 10:20:30 +00:00
|
|
|
Modeling.prototype.updateModdleProperties = function(element, moddleElement, properties) {
|
|
|
|
this._commandStack.execute('element.updateModdleProperties', {
|
|
|
|
element: element,
|
|
|
|
moddleElement: moddleElement,
|
2020-11-06 10:03:29 +00:00
|
|
|
properties: properties
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
};
|
2016-11-28 13:26:42 +00:00
|
|
|
|
|
|
|
Modeling.prototype.setColor = function(elements, colors) {
|
|
|
|
if (!elements.length) {
|
|
|
|
elements = [ elements ];
|
|
|
|
}
|
|
|
|
|
|
|
|
this._commandStack.execute('element.setColor', {
|
|
|
|
elements: elements,
|
|
|
|
colors: colors
|
|
|
|
});
|
|
|
|
};
|