diff --git a/lib/features/context-pad/ContextPadProvider.js b/lib/features/context-pad/ContextPadProvider.js index 0fd1a047..80b04913 100644 --- a/lib/features/context-pad/ContextPadProvider.js +++ b/lib/features/context-pad/ContextPadProvider.js @@ -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); diff --git a/lib/features/copy-paste/BpmnCopyPaste.js b/lib/features/copy-paste/BpmnCopyPaste.js index f2c358ab..b7edf679 100644 --- a/lib/features/copy-paste/BpmnCopyPaste.js +++ b/lib/features/copy-paste/BpmnCopyPaste.js @@ -1,5 +1,6 @@ import { getBusinessObject, + getDi, is } from '../../util/ModelUtil'; @@ -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; @@ -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; } @@ -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); diff --git a/lib/features/di-ordering/BpmnDiOrdering.js b/lib/features/di-ordering/BpmnDiOrdering.js index b419ef0b..85a17ed9 100644 --- a/lib/features/di-ordering/BpmnDiOrdering.js +++ b/lib/features/di-ordering/BpmnDiOrdering.js @@ -1,5 +1,4 @@ import { getDi } from '../../draw/BpmnRenderUtil'; -import { getBusinessObject } from '../../util/ModelUtil'; import { filter, @@ -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; diff --git a/lib/features/label-editing/LabelEditingPreview.js b/lib/features/label-editing/LabelEditingPreview.js index b9f62ce7..4ce2cf87 100644 --- a/lib/features/label-editing/LabelEditingPreview.js +++ b/lib/features/label-editing/LabelEditingPreview.js @@ -6,7 +6,7 @@ import { } from 'tiny-svg'; import { - getBusinessObject, + getDi, is } from '../../util/ModelUtil'; @@ -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'; } \ No newline at end of file diff --git a/lib/features/label-editing/cmd/UpdateLabelHandler.js b/lib/features/label-editing/cmd/UpdateLabelHandler.js index 0c4e44ee..8dfbb851 100644 --- a/lib/features/label-editing/cmd/UpdateLabelHandler.js +++ b/lib/features/label-editing/cmd/UpdateLabelHandler.js @@ -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 }); } } diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index 8026c4f4..5e356cea 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -16,6 +16,7 @@ import { import { getBusinessObject, + getDi, is } from '../../util/ModelUtil'; @@ -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); @@ -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; @@ -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; } }; @@ -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) { @@ -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); }; diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index 24a8f695..31ae257f 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -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); @@ -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) { @@ -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' }); } @@ -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', @@ -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, @@ -135,6 +131,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { attrs = assign({ businessObject: businessObject, + di: di, id: businessObject.id }, size, attrs); diff --git a/lib/features/modeling/behavior/DataStoreBehavior.js b/lib/features/modeling/behavior/DataStoreBehavior.js index ce3d0d96..c6643e7c 100644 --- a/lib/features/modeling/behavior/DataStoreBehavior.js +++ b/lib/features/modeling/behavior/DataStoreBehavior.js @@ -4,6 +4,7 @@ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; import { getBusinessObject, + getDi, is } from '../../../util/ModelUtil'; @@ -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) }); } } diff --git a/lib/features/modeling/behavior/IsHorizontalFix.js b/lib/features/modeling/behavior/IsHorizontalFix.js index b9ded0ce..7a5ebbb6 100644 --- a/lib/features/modeling/behavior/IsHorizontalFix.js +++ b/lib/features/modeling/behavior/IsHorizontalFix.js @@ -3,7 +3,8 @@ import inherits from 'inherits'; import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; import { - getBusinessObject + getBusinessObject, + getDi } from '../../../util/ModelUtil'; import { @@ -26,12 +27,14 @@ export default function IsHorizontalFix(eventBus) { ]; this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], function(event) { - var bo = getBusinessObject(event.context.shape); + var shape = event.context.shape, + bo = getBusinessObject(shape), + di = getDi(shape); - if (isAny(bo, elementTypesToUpdate) && !bo.di.get('isHorizontal')) { + if (isAny(bo, elementTypesToUpdate) && !di.get('isHorizontal')) { // set attribute directly to avoid modeling#updateProperty side effects - bo.di.set('isHorizontal', true); + di.set('isHorizontal', true); } }); diff --git a/lib/features/modeling/behavior/LabelBehavior.js b/lib/features/modeling/behavior/LabelBehavior.js index 43241c64..b56cf07e 100644 --- a/lib/features/modeling/behavior/LabelBehavior.js +++ b/lib/features/modeling/behavior/LabelBehavior.js @@ -6,7 +6,8 @@ import inherits from 'inherits'; import { is, - getBusinessObject + getBusinessObject, + getDi } from '../../../util/ModelUtil'; import { @@ -153,27 +154,27 @@ export default function LabelBehavior( var context = event.context, element = context.shape, - businessObject, + labelTarget = context.labelTarget, di; // we want to trigger on real labels only - if (!element.labelTarget) { + if (!labelTarget) { return; } // we want to trigger on BPMN elements only - if (!is(element.labelTarget || element, 'bpmn:BaseElement')) { + if (!is(labelTarget, 'bpmn:BaseElement')) { return; } - businessObject = element.businessObject, - di = businessObject.di; - + di = getDi(labelTarget); if (!di.label) { di.label = bpmnFactory.create('bpmndi:BPMNLabel', { bounds: bpmnFactory.create('dc:Bounds') }); + + element.di = di; } assign(di.label.bounds, { diff --git a/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js b/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js index d533272f..afcb405f 100644 --- a/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js +++ b/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js @@ -3,7 +3,7 @@ import inherits from 'inherits'; import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; import { - getBusinessObject, + getDi, is } from '../../../util/ModelUtil'; @@ -85,11 +85,11 @@ export default function ToggleElementCollapseBehaviour( hideEmptyLabels(shape.children); // remove collapsed marker - getBusinessObject(shape).di.isExpanded = true; + getDi(shape).isExpanded = true; } else { // place collapsed marker - getBusinessObject(shape).di.isExpanded = false; + getDi(shape).isExpanded = false; } }); @@ -101,10 +101,10 @@ export default function ToggleElementCollapseBehaviour( // revert removing/placing collapsed marker if (!shape.collapsed) { - getBusinessObject(shape).di.isExpanded = true; + getDi(shape).isExpanded = true; } else { - getBusinessObject(shape).di.isExpanded = false; + getDi(shape).isExpanded = false; } }); diff --git a/lib/features/modeling/cmd/UpdateCanvasRootHandler.js b/lib/features/modeling/cmd/UpdateCanvasRootHandler.js index db84ed3d..7b37b897 100644 --- a/lib/features/modeling/cmd/UpdateCanvasRootHandler.js +++ b/lib/features/modeling/cmd/UpdateCanvasRootHandler.js @@ -3,6 +3,8 @@ import { remove as collectionRemove } from 'diagram-js/lib/util/Collections'; +import { getDi } from '../../../util/ModelUtil'; + export default function UpdateCanvasRootHandler(canvas, modeling) { this._canvas = canvas; @@ -24,7 +26,7 @@ UpdateCanvasRootHandler.prototype.execute = function(context) { oldRoot = canvas.getRootElement(), oldRootBusinessObject = oldRoot.businessObject, bpmnDefinitions = oldRootBusinessObject.$parent, - diPlane = oldRootBusinessObject.di; + diPlane = getDi(oldRoot); // (1) replace process old <> new root canvas.setRootElement(newRoot, true); @@ -37,10 +39,10 @@ UpdateCanvasRootHandler.prototype.execute = function(context) { oldRootBusinessObject.$parent = null; // (3) wire di - oldRootBusinessObject.di = null; + oldRoot.di = null; diPlane.bpmnElement = newRootBusinessObject; - newRootBusinessObject.di = diPlane; + newRoot.di = diPlane; context.oldRoot = oldRoot; @@ -58,7 +60,7 @@ UpdateCanvasRootHandler.prototype.revert = function(context) { oldRoot = context.oldRoot, oldRootBusinessObject = oldRoot.businessObject, bpmnDefinitions = newRootBusinessObject.$parent, - diPlane = newRootBusinessObject.di; + diPlane = getDi(newRoot); // (1) replace process old <> new root canvas.setRootElement(oldRoot, true); @@ -71,10 +73,10 @@ UpdateCanvasRootHandler.prototype.revert = function(context) { oldRootBusinessObject.$parent = bpmnDefinitions; // (3) wire di - newRootBusinessObject.di = null; + newRoot.di = null; diPlane.bpmnElement = oldRootBusinessObject; - oldRootBusinessObject.di = diPlane; + oldRoot.di = diPlane; // TODO(nikku): return changed elements? // return [ newRoot, oldRoot ]; diff --git a/lib/features/modeling/cmd/UpdatePropertiesHandler.js b/lib/features/modeling/cmd/UpdatePropertiesHandler.js index b9d35535..437c4d0b 100644 --- a/lib/features/modeling/cmd/UpdatePropertiesHandler.js +++ b/lib/features/modeling/cmd/UpdatePropertiesHandler.js @@ -6,7 +6,8 @@ import { } from 'min-dash'; import { - getBusinessObject + getBusinessObject, + getDi } from '../../../util/ModelUtil'; var DEFAULT_FLOW = 'default', @@ -74,7 +75,7 @@ UpdatePropertiesHandler.prototype.execute = function(context) { var businessObject = element.businessObject, properties = unwrapBusinessObjects(context.properties), - oldProperties = context.oldProperties || getProperties(businessObject, properties); + oldProperties = context.oldProperties || getProperties(element, properties); if (isIdChange(properties, businessObject)) { ids.unclaim(businessObject[ID]); @@ -97,7 +98,7 @@ UpdatePropertiesHandler.prototype.execute = function(context) { } // update properties - setProperties(businessObject, properties); + setProperties(element, properties); // store old values context.oldProperties = oldProperties; @@ -142,7 +143,7 @@ UpdatePropertiesHandler.prototype.revert = function(context) { ids = this._moddle.ids; // update properties - setProperties(businessObject, oldProperties); + setProperties(element, oldProperties); if (isIdChange(properties, businessObject)) { ids.unclaim(properties[ID]); @@ -161,16 +162,19 @@ function isIdChange(properties, businessObject) { } -function getProperties(businessObject, properties) { - var propertyNames = keys(properties); +function getProperties(element, properties) { + var propertyNames = keys(properties), + businessObject = element.businessObject, + di = getDi(element); return reduce(propertyNames, function(result, key) { // handle DI separately if (key !== DI) { result[key] = businessObject.get(key); + } else { - result[key] = getDiProperties(businessObject.di, keys(properties.di)); + result[key] = getDiProperties(di, keys(properties.di)); } return result; @@ -180,23 +184,26 @@ function getProperties(businessObject, properties) { function getDiProperties(di, propertyNames) { return reduce(propertyNames, function(result, key) { - result[key] = di.get(key); + result[key] = di && di.get(key); return result; }, {}); } -function setProperties(businessObject, properties) { +function setProperties(element, properties) { + var businessObject = element.businessObject, + di = getDi(element); + forEach(properties, function(value, key) { if (key !== DI) { businessObject.set(key, value); } else { - // only update, if businessObject.di exists - if (businessObject.di) { - setDiProperties(businessObject.di, value); + // only update, if di exists + if (di) { + setDiProperties(di, value); } } }); diff --git a/lib/features/modeling/cmd/UpdateSemanticParentHandler.js b/lib/features/modeling/cmd/UpdateSemanticParentHandler.js index 1c6efc40..fb16fad4 100644 --- a/lib/features/modeling/cmd/UpdateSemanticParentHandler.js +++ b/lib/features/modeling/cmd/UpdateSemanticParentHandler.js @@ -7,21 +7,23 @@ UpdateSemanticParentHandler.$inject = [ 'bpmnUpdater' ]; UpdateSemanticParentHandler.prototype.execute = function(context) { var dataStoreBo = context.dataStoreBo, + dataStoreDi = context.dataStoreDi, newSemanticParent = context.newSemanticParent, newDiParent = context.newDiParent; context.oldSemanticParent = dataStoreBo.$parent; - context.oldDiParent = dataStoreBo.di.$parent; + context.oldDiParent = dataStoreDi.$parent; // update semantic parent this._bpmnUpdater.updateSemanticParent(dataStoreBo, newSemanticParent); // update DI parent - this._bpmnUpdater.updateDiParent(dataStoreBo.di, newDiParent); + this._bpmnUpdater.updateDiParent(dataStoreDi, newDiParent); }; UpdateSemanticParentHandler.prototype.revert = function(context) { var dataStoreBo = context.dataStoreBo, + dataStoreDi = context.dataStoreDi, oldSemanticParent = context.oldSemanticParent, oldDiParent = context.oldDiParent; @@ -29,6 +31,6 @@ UpdateSemanticParentHandler.prototype.revert = function(context) { this._bpmnUpdater.updateSemanticParent(dataStoreBo, oldSemanticParent); // update DI parent - this._bpmnUpdater.updateDiParent(dataStoreBo.di, oldDiParent); + this._bpmnUpdater.updateDiParent(dataStoreDi, oldDiParent); }; diff --git a/lib/features/palette/PaletteProvider.js b/lib/features/palette/PaletteProvider.js index ab90c5e4..9c2227c5 100644 --- a/lib/features/palette/PaletteProvider.js +++ b/lib/features/palette/PaletteProvider.js @@ -1,6 +1,7 @@ import { assign } from 'min-dash'; +import { getDi } from '../../util/ModelUtil'; /** @@ -52,7 +53,8 @@ PaletteProvider.prototype.getPaletteEntries = function(element) { var shape = elementFactory.createShape(assign({ type: type }, options)); if (options) { - shape.businessObject.di.isExpanded = options.isExpanded; + var di = getDi(shape); + di.isExpanded = options.isExpanded; } create.start(event, shape); diff --git a/lib/features/popup-menu/ReplaceMenuProvider.js b/lib/features/popup-menu/ReplaceMenuProvider.js index 4aaf2fe6..538cf710 100644 --- a/lib/features/popup-menu/ReplaceMenuProvider.js +++ b/lib/features/popup-menu/ReplaceMenuProvider.js @@ -99,7 +99,7 @@ ReplaceMenuProvider.prototype.getEntries = function(element) { if (is(businessObject, 'bpmn:Participant')) { entries = filter(replaceOptions.PARTICIPANT, function(entry) { - return isExpanded(businessObject) !== entry.target.isExpanded; + return isExpanded(element) !== entry.target.isExpanded; }); return this._createEntries(element, entries); @@ -195,7 +195,7 @@ ReplaceMenuProvider.prototype.getEntries = function(element) { } // expanded event sub processes - if (isEventSubProcess(businessObject) && isExpanded(businessObject)) { + if (isEventSubProcess(businessObject) && isExpanded(element)) { entries = filter(replaceOptions.EVENT_SUB_PROCESS, differentType); @@ -203,7 +203,7 @@ ReplaceMenuProvider.prototype.getEntries = function(element) { } // expanded sub processes - if (is(businessObject, 'bpmn:SubProcess') && isExpanded(businessObject)) { + if (is(businessObject, 'bpmn:SubProcess') && isExpanded(element)) { entries = filter(replaceOptions.SUBPROCESS_EXPANDED, differentType); @@ -211,7 +211,7 @@ ReplaceMenuProvider.prototype.getEntries = function(element) { } // collapsed ad hoc sub processes - if (is(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(businessObject)) { + if (is(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(element)) { entries = filter(replaceOptions.TASK, function(entry) { @@ -237,7 +237,7 @@ ReplaceMenuProvider.prototype.getEntries = function(element) { entries = filter(replaceOptions.TASK, differentType); // collapsed SubProcess can not be replaced with itself - if (is(businessObject, 'bpmn:SubProcess') && !isExpanded(businessObject)) { + if (is(businessObject, 'bpmn:SubProcess') && !isExpanded(element)) { entries = filter(entries, function(entry) { return entry.label !== 'Sub Process (collapsed)'; }); diff --git a/lib/features/popup-menu/util/TypeUtil.js b/lib/features/popup-menu/util/TypeUtil.js index 3f65d89e..99ae6a9f 100644 --- a/lib/features/popup-menu/util/TypeUtil.js +++ b/lib/features/popup-menu/util/TypeUtil.js @@ -36,7 +36,7 @@ export function isDifferentType(element) { var isExpandedEqual = ( target.isExpanded === undefined || - target.isExpanded === isExpanded(businessObject) + target.isExpanded === isExpanded(element) ); return !isTypeEqual || !isEventDefinitionEqual || !isTriggeredByEventEqual || !isExpandedEqual; diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js index eb1eea36..cc1a28e6 100644 --- a/lib/features/replace/BpmnReplace.js +++ b/lib/features/replace/BpmnReplace.js @@ -2,15 +2,13 @@ import { pick, assign, filter, - forEach, - isArray, - isUndefined, has } from 'min-dash'; import { is, - getBusinessObject + getBusinessObject, + getDi } from '../../util/ModelUtil'; import { @@ -24,17 +22,6 @@ import { import { getPropertyNames } from '../copy-paste/ModdleCopy'; -function copyProperties(source, target, properties) { - if (!isArray(properties)) { - properties = [ properties ]; - } - - forEach(properties, function(property) { - if (!isUndefined(source[property])) { - target[property] = source[property]; - } - }); -} var CUSTOM_PROPERTIES = [ 'cancelActivity', @@ -121,7 +108,8 @@ export default function BpmnReplace( var newElement = { type: type, - businessObject: newBusinessObject + businessObject: newBusinessObject, + di: getDi(element) }; var elementProps = getPropertyNames(oldBusinessObject.$descriptor), @@ -183,7 +171,7 @@ export default function BpmnReplace( if (isSubProcess(oldBusinessObject)) { // no toggeling, so keep old state - newElement.isExpanded = isExpanded(oldBusinessObject); + newElement.isExpanded = isExpanded(element); } // else if property is explicitly set, use it @@ -194,7 +182,7 @@ export default function BpmnReplace( // TODO: need also to respect min/max Size // copy size, from an expanded subprocess to an expanded alternative subprocess // except bpmn:Task, because Task is always expanded - if ((isExpanded(oldBusinessObject) && !is(oldBusinessObject, 'bpmn:Task')) && newElement.isExpanded) { + if ((isExpanded(element) && !is(oldBusinessObject, 'bpmn:Task')) && newElement.isExpanded) { newElement.width = element.width; newElement.height = element.height; } @@ -262,16 +250,6 @@ export default function BpmnReplace( newElement.x = element.x + (element.width - newElement.width) / 2; } - newElement.di = {}; - - // colors will be set to DI - copyProperties(oldBusinessObject.di, newElement.di, [ - 'fill', - 'stroke', - 'background-color', - 'border-color', - 'color' - ]); newElement = replace.replaceElement(element, newElement, hints);