| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import inherits from 'inherits-browser';
- import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
- import {
- is
- } from '../../../util/ModelUtil';
- /**
- * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
- * @typedef {import('../Modeling').default} Modeling
- * @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
- */
- var LOW_PRIORITY = 500,
- HIGH_PRIORITY = 5000;
- /**
- * BPMN specific delete lane behavior.
- *
- * @param {EventBus} eventBus
- * @param {Modeling} modeling
- * @param {Translate} translate
- */
- export default function UpdateFlowNodeRefsBehavior(eventBus, modeling, translate) {
- CommandInterceptor.call(this, eventBus);
- /**
- * Update Lane#flowNodeRefs and FlowNode#lanes with every flow node
- * move/resize and lane move/resize. Groups elements to recompute containments
- * as efficient as possible.
- */
- // the update context
- var context;
- function initContext() {
- context = context || new UpdateContext();
- context.enter();
- return context;
- }
- function getContext() {
- if (!context) {
- throw new Error(translate('out of bounds release'));
- }
- return context;
- }
- function releaseContext() {
- if (!context) {
- throw new Error(translate('out of bounds release'));
- }
- var triggerUpdate = context.leave();
- if (triggerUpdate) {
- modeling.updateLaneRefs(context.flowNodes, context.lanes);
- context = null;
- }
- return triggerUpdate;
- }
- var laneRefUpdateEvents = [
- 'spaceTool',
- 'lane.add',
- 'lane.resize',
- 'lane.split',
- 'elements.create',
- 'elements.delete',
- 'elements.move',
- 'shape.create',
- 'shape.delete',
- 'shape.move',
- 'shape.resize'
- ];
- // listen to a lot of stuff to group lane updates
- this.preExecute(laneRefUpdateEvents, HIGH_PRIORITY, function(event) {
- initContext();
- });
- this.postExecuted(laneRefUpdateEvents, LOW_PRIORITY, function(event) {
- releaseContext();
- });
- // Mark flow nodes + lanes that need an update
- this.preExecute([
- 'shape.create',
- 'shape.move',
- 'shape.delete',
- 'shape.resize'
- ], function(event) {
- var context = event.context,
- shape = context.shape;
- var updateContext = getContext();
- // no need to update labels
- if (shape.labelTarget) {
- return;
- }
- if (is(shape, 'bpmn:Lane')) {
- updateContext.addLane(shape);
- }
- if (is(shape, 'bpmn:FlowNode')) {
- updateContext.addFlowNode(shape);
- }
- });
- }
- UpdateFlowNodeRefsBehavior.$inject = [
- 'eventBus',
- 'modeling' ,
- 'translate'
- ];
- inherits(UpdateFlowNodeRefsBehavior, CommandInterceptor);
- function UpdateContext() {
- this.flowNodes = [];
- this.lanes = [];
- this.counter = 0;
- this.addLane = function(lane) {
- this.lanes.push(lane);
- };
- this.addFlowNode = function(flowNode) {
- this.flowNodes.push(flowNode);
- };
- this.enter = function() {
- this.counter++;
- };
- this.leave = function() {
- this.counter--;
- return !this.counter;
- };
- }
|