Skip to content

Commit

Permalink
feat(replace): add switch between DataStore and DataObject in replace…
Browse files Browse the repository at this point in the history
… menu

Closes #1372
  • Loading branch information
azeghers committed Nov 26, 2020
1 parent 4b46f69 commit 4f79c7b
Show file tree
Hide file tree
Showing 9 changed files with 10,824 additions and 24 deletions.
20 changes: 20 additions & 0 deletions lib/features/modeling/behavior/ReplaceElementBehaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ export default function ReplaceElementBehaviour(
modeling.unclaimId(oldShape.businessObject.id, oldShape.businessObject);
modeling.updateProperties(newShape, { id: oldShape.id });
});

// The DataStoreReference element is 14px wider than the DataObjectReference element
// This ensures that they stay centered on the x axis when replaced
this.postExecute('shape.replace', function(e) {
var oldShape = e.context.oldShape;
var newShape = e.context.newShape;
var newX;

if (newShape.type === 'bpmn:DataStoreReference') {
newX = oldShape.x - 7;
newShape.x = newX;
modeling.updateProperties(newShape, { x: newX });
}

if (newShape.type === 'bpmn:DataObjectReference') {
newX = oldShape.x + 7;
newShape.x = newX;
modeling.updateProperties(newShape, { x: newX });
}
});
}

inherits(ReplaceElementBehaviour, CommandInterceptor);
Expand Down
8 changes: 8 additions & 0 deletions lib/features/popup-menu/ReplaceMenuProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ ReplaceMenuProvider.prototype.getEntries = function(element) {

var differentType = isDifferentType(element);

if (is(businessObject, 'bpmn:DataObjectReference')) {
return this._createEntries(element, replaceOptions.DATA_OBJECT_REFERENCE);
}

if (is(businessObject, 'bpmn:DataStoreReference')) {
return this._createEntries(element, replaceOptions.DATA_STORE_REFERENCE);
}

// start events outside sub processes
if (is(businessObject, 'bpmn:StartEvent') && !is(businessObject.$parent, 'bpmn:SubProcess')) {

Expand Down
7 changes: 7 additions & 0 deletions lib/features/replace/BpmnReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function BpmnReplace(
moddleCopy,
modeling,
replace,
rules,
selection
) {

Expand Down Expand Up @@ -221,6 +222,11 @@ export default function BpmnReplace(
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
}

if (!rules.allowed('shape.resize', { shape: newBusinessObject })) {
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
newElement.width = elementFactory._getDefaultSize(newBusinessObject).width;
}

newBusinessObject.name = oldBusinessObject.name;

// retain default flow's reference between inclusive <-> exclusive gateways and activities
Expand Down Expand Up @@ -273,6 +279,7 @@ BpmnReplace.$inject = [
'moddleCopy',
'modeling',
'replace',
'rules',
'selection'
];

Expand Down
22 changes: 22 additions & 0 deletions lib/features/replace/ReplaceOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,28 @@ export var TASK = [
}
];

export var DATA_OBJECT_REFERENCE = [
{
label: 'Data Store Reference',
actionName: 'replace-with-data-store-reference',
className: 'bpmn-icon-data-store',
target: {
type: 'bpmn:DataStoreReference'
}
}
];

export var DATA_STORE_REFERENCE = [
{
label: 'Data Object Reference',
actionName: 'replace-with-data-object-reference',
className: 'bpmn-icon-data-object',
target: {
type: 'bpmn:DataObjectReference'
}
}
];

export var BOUNDARY_EVENT = [
{
label: 'Message Boundary Event',
Expand Down
2 changes: 1 addition & 1 deletion lib/util/DiUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function isExpanded(element) {
}

if (is(element, 'bpmn:SubProcess')) {
return !!getBusinessObject(element).di.isExpanded;
return getBusinessObject(element).di && !!getBusinessObject(element).di.isExpanded;
}

if (is(element, 'bpmn:Participant')) {
Expand Down

0 comments on commit 4f79c7b

Please sign in to comment.