Skip to content

Commit

Permalink
chore: adjust features to new DI structure
Browse files Browse the repository at this point in the history
Related to #1472
  • Loading branch information
marstamm committed Oct 8, 2021
1 parent 4d59772 commit 8ecc37d
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 134 deletions.
2 changes: 1 addition & 1 deletion lib/features/context-pad/ContextPadProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
}


if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(businessObject)) {
if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(element)) {

var childLanes = getChildLanes(element);

Expand Down
26 changes: 13 additions & 13 deletions lib/features/copy-paste/BpmnCopyPaste.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getBusinessObject,
getDi,
is
} from '../../util/ModelUtil';

Expand Down Expand Up @@ -45,23 +46,13 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
element = context.element;

var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
var di = descriptor.oldDi = getDi(element);

descriptor.type = element.type;

copyProperties(businessObject, descriptor, 'name');

descriptor.di = {};

// colors will be set to DI
copyProperties(businessObject.di, descriptor.di, [
'fill',
'stroke',
'background-color',
'border-color',
'color'
]);

copyProperties(businessObject.di, descriptor, 'isExpanded');
copyProperties(di, descriptor, 'isExpanded');

if (isLabel(descriptor)) {
return descriptor;
Expand Down Expand Up @@ -135,11 +126,13 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
var cache = context.cache,
descriptor = context.descriptor,
oldBusinessObject = descriptor.oldBusinessObject,
newBusinessObject;
oldDi = descriptor.oldDi,
newBusinessObject, newDi;

// do NOT copy business object if external label
if (isLabel(descriptor)) {
descriptor.businessObject = getBusinessObject(cache[ descriptor.labelTarget ]);
descriptor.di = getDi(cache[ descriptor.labelTarget ]);

return;
}
Expand All @@ -151,6 +144,13 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
newBusinessObject
);

newDi = bpmnFactory.create(oldDi.$type);

descriptor.di = moddleCopy.copyElement(
oldDi,
newDi
);

// resolve references e.g. default sequence flow
resolveReferences(descriptor, cache);

Expand Down
3 changes: 1 addition & 2 deletions lib/features/di-ordering/BpmnDiOrdering.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getDi } from '../../draw/BpmnRenderUtil';
import { getBusinessObject } from '../../util/ModelUtil';

import {
filter,
Expand All @@ -17,7 +16,7 @@ export default function BpmnDiOrdering(eventBus, canvas) {

function orderDi() {
var root = canvas.getRootElement(),
rootDi = getBusinessObject(root).di,
rootDi = getDi(root),
elements,
diElements;

Expand Down
6 changes: 3 additions & 3 deletions lib/features/label-editing/LabelEditingPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'tiny-svg';

import {
getBusinessObject,
getDi,
is
} from '../../util/ModelUtil';

Expand Down Expand Up @@ -132,7 +132,7 @@ LabelEditingPreview.$inject = [
// helpers ///////////////////

function getStrokeColor(element, defaultColor) {
var bo = getBusinessObject(element);
var di = getDi(element);

return bo.di.get('stroke') || defaultColor || 'black';
return di.get('stroke') || defaultColor || 'black';
}
3 changes: 2 additions & 1 deletion lib/features/label-editing/cmd/UpdateLabelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {

modeling.createLabel(element, labelCenter, {
id: businessObject.id + '_label',
businessObject: businessObject
businessObject: businessObject,
di: element.di
});
}
}
Expand Down
67 changes: 40 additions & 27 deletions lib/features/modeling/BpmnUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

import {
getBusinessObject,
getDi,
is
} from '../../util/ModelUtil';

Expand Down Expand Up @@ -307,8 +308,9 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
var parentShape = element.parent;

var businessObject = element.businessObject,
di = getDi(element),
parentBusinessObject = parentShape && parentShape.businessObject,
parentDi = parentBusinessObject && parentBusinessObject.di;
parentDi = getDi(parentShape);

if (is(element, 'bpmn:FlowNode')) {
this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
Expand Down Expand Up @@ -336,13 +338,13 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
this.updateSemanticParent(businessObject.dataObjectRef, parentBusinessObject);
}

this.updateDiParent(businessObject.di, parentDi);
this.updateDiParent(di, parentDi);
};


BpmnUpdater.prototype.updateBounds = function(shape) {

var di = shape.businessObject.di;
var di = getDi(shape);

var target = (shape instanceof Label) ? this._getLabel(di) : di;

Expand Down Expand Up @@ -382,14 +384,17 @@ BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainme


// update existing sourceElement and targetElement di information
BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
BpmnUpdater.prototype.updateDiConnection = function(connection, newSource, newTarget) {
var connectionDi = getDi(connection),
newSourceDi = getDi(newSource),
newTargetDi = getDi(newTarget);

if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
di.sourceElement = newSource && newSource.di;
if (connectionDi.sourceElement && connectionDi.sourceElement.bpmnElement !== getBusinessObject(newSource)) {
connectionDi.sourceElement = newSource && newSourceDi;
}

if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
di.targetElement = newTarget && newTarget.di;
if (connectionDi.targetElement && connectionDi.targetElement.bpmnElement !== getBusinessObject(newTarget)) {
connectionDi.targetElement = newTarget && newTargetDi;
}

};
Expand All @@ -405,6 +410,11 @@ BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
return;
}

// Cover the case where di.$parent === undefined and parentDi === null
if (!parentDi && !di.$parent) {
return;
}

var planeElements = (parentDi || di.$parent).get('planeElement');

if (parentDi) {
Expand Down Expand Up @@ -614,69 +624,72 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent,


BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
var di = getDi(connection);

di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
};


BpmnUpdater.prototype.updateConnection = function(context) {

var connection = context.connection,
businessObject = getBusinessObject(connection),
newSource = getBusinessObject(connection.source),
newTarget = getBusinessObject(connection.target),
newSource = connection.source,
newSourceBo = getBusinessObject(newSource),
newTarget = connection.target,
newTargetBo = getBusinessObject(connection.target),
visualParent;

if (!is(businessObject, 'bpmn:DataAssociation')) {

var inverseSet = is(businessObject, 'bpmn:SequenceFlow');

if (businessObject.sourceRef !== newSource) {
if (businessObject.sourceRef !== newSourceBo) {
if (inverseSet) {
collectionRemove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);

if (newSource && newSource.get('outgoing')) {
newSource.get('outgoing').push(businessObject);
if (newSourceBo && newSourceBo.get('outgoing')) {
newSourceBo.get('outgoing').push(businessObject);
}
}

businessObject.sourceRef = newSource;
businessObject.sourceRef = newSourceBo;
}

if (businessObject.targetRef !== newTarget) {
if (businessObject.targetRef !== newTargetBo) {
if (inverseSet) {
collectionRemove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);

if (newTarget && newTarget.get('incoming')) {
newTarget.get('incoming').push(businessObject);
if (newTargetBo && newTargetBo.get('incoming')) {
newTargetBo.get('incoming').push(businessObject);
}
}

businessObject.targetRef = newTarget;
businessObject.targetRef = newTargetBo;
}
} else

if (is(businessObject, 'bpmn:DataInputAssociation')) {

// handle obnoxious isMsome sourceRef
businessObject.get('sourceRef')[0] = newSource;
businessObject.get('sourceRef')[0] = newSourceBo;

visualParent = context.parent || context.newParent || newTarget;
visualParent = context.parent || context.newParent || newTargetBo;

this.updateSemanticParent(businessObject, newTarget, visualParent);
this.updateSemanticParent(businessObject, newTargetBo, visualParent);
} else

if (is(businessObject, 'bpmn:DataOutputAssociation')) {
visualParent = context.parent || context.newParent || newSource;
visualParent = context.parent || context.newParent || newSourceBo;

this.updateSemanticParent(businessObject, newSource, visualParent);
this.updateSemanticParent(businessObject, newSourceBo, visualParent);

// targetRef = new target
businessObject.targetRef = newTarget;
businessObject.targetRef = newTargetBo;
}

this.updateConnectionWaypoints(connection);

this.updateDiConnection(businessObject.di, newSource, newTarget);
this.updateDiConnection(connection, newSource, newTarget);
};


Expand Down
25 changes: 11 additions & 14 deletions lib/features/modeling/ElementFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ ElementFactory.prototype.create = function(elementType, attrs) {
// we assume their businessObjects have already been created
// and wired via attrs
if (elementType === 'label') {
return this.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE, attrs));
var di = attrs.di || this._bpmnFactory.createDiLabel();
return this.baseCreate(elementType, assign({ type: 'label', di: di }, DEFAULT_LABEL_SIZE, attrs));
}

return this.createBpmnElement(elementType, attrs);
Expand All @@ -58,7 +59,8 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {

attrs = attrs || {};

var businessObject = attrs.businessObject;
var businessObject = attrs.businessObject,
di = attrs.di;

if (!businessObject) {
if (!attrs.type) {
Expand All @@ -68,18 +70,18 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
businessObject = this._bpmnFactory.create(attrs.type);
}

if (!businessObject.di) {
if (!di) {
if (elementType === 'root') {
businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
di = this._bpmnFactory.createDiPlane(businessObject, [], {
id: businessObject.id + '_di'
});
} else
if (elementType === 'connection') {
businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
di = this._bpmnFactory.createDiEdge(businessObject, [], {
id: businessObject.id + '_di'
});
} else {
businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
di = this._bpmnFactory.createDiShape(businessObject, {}, {
id: businessObject.id + '_di'
});
}
Expand All @@ -91,12 +93,6 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
}, attrs);
}

if (attrs.di) {
assign(businessObject.di, attrs.di);

delete attrs.di;
}

applyAttributes(businessObject, attrs, [
'processRef',
'isInterrupting',
Expand All @@ -105,11 +101,11 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
]);

if (attrs.isExpanded) {
applyAttribute(businessObject.di, attrs, 'isExpanded');
applyAttribute(di, attrs, 'isExpanded');
}

if (is(businessObject, 'bpmn:ExclusiveGateway')) {
businessObject.di.isMarkerVisible = true;
di.isMarkerVisible = true;
}

var eventDefinitions,
Expand All @@ -135,6 +131,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {

attrs = assign({
businessObject: businessObject,
di: di,
id: businessObject.id
}, size, attrs);

Expand Down
4 changes: 3 additions & 1 deletion lib/features/modeling/behavior/DataStoreBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

import {
getBusinessObject,
getDi,
is
} from '../../../util/ModelUtil';

Expand Down Expand Up @@ -45,8 +46,9 @@ export default function DataStoreBehavior(

commandStack.execute('dataStore.updateContainment', {
dataStoreBo: dataStoreBo,
dataStoreDi: getDi(dataStore),
newSemanticParent: newDataStoreParentBo.processRef || newDataStoreParentBo,
newDiParent: newDataStoreParentBo.di
newDiParent: getDi(newDataStoreParent)
});
}
}
Expand Down
Loading

0 comments on commit 8ecc37d

Please sign in to comment.