I created a command handler following this post Update custom BPMN meta data so it can be undone via CTRL+Z - #4 by nikku. I am trying to implement Ctrl+Z, Ctrl+Y for my custom shapes.
Originally I had this code for my custom ContextPadProvider:
function createLoopShapes(event, elementFactory, create) {
const source = elementFactory.createShape({
type: ElementType.ExclusiveGateway,
gatewayType: GatewayTypeValue.Open,
looped: true,
x: 350,
y: 0,
});
const target = elementFactory.createShape({
type: ElementType.ExclusiveGateway,
gatewayType: GatewayTypeValue.Close,
looped: true,
x: 0,
y: 0,
});
const sequenceFlow = elementFactory.createConnection({
type: ElementType.SequenceFlow,
looped: true,
source,
target,
waypoints: [
{ x: 375, y: 50 },
{ x: 375, y: 150 },
{ x: 25, y: 150 },
{ x: 25, y: 50 },
],
});
create.start(event, [target, source, sequenceFlow]);
}
and I converted that into the following code, for the custom command handler, but it is not adding the shapes and no errors that I can see:
export default function CreateLoopHandler(elementFactory, create, canvas, modeling) {
this._elementFactory = elementFactory;
this._create = create;
this._canvas = canvas;
this._modeling = modeling;
}
CreateLoopHandler.$inject = [
'modeling',
'create',
'canvas',
'elementFactory'
];
CreateLoopHandler.prototype.postExecute = function(context) {
const elementFactory = this._elementFactory,
create = this._create,
canvas = this._canvas,
modeling = this._modeling;
const sourceDataObject = {
type: ElementType.ExclusiveGateway,
gatewayType: GatewayTypeValue.Open,
looped: true};
const sourceShape =modeling.createShape(sourceDataObject,{x: 350, y: 0,}, canvas.getRootElement());
const targetDataObject = {
type: ElementType.ExclusiveGateway,
gatewayType: GatewayTypeValue.Close,
looped: true};
const targetShape = modeling.createShape(targetDataObject, {x: 0, y: 0}, canvas.getRootElement());
modeling.createConnection({
type: ElementType.SequenceFlow,
looped: true,
sourceShape,
targetShape,
waypoints: [
{ x: 375, y: 50 },
{ x: 375, y: 150 },
{ x: 25, y: 150 },
{ x: 25, y: 50 },
],
},canvas.getRootElement());
};
What is the correct code for what I’m trying to achieve?