From 1f2a7b39f777198e939878f38a3d2f518e564416 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sat, 11 Mar 2023 09:39:51 +0100 Subject: [PATCH] impl, refactoring ChangeBoundsOperationHandler Issue #208 --- .../BPMNChangeBoundsOperationHandler.java | 135 +++++++++--------- .../org/openbpmn/bpmn/elements/Activity.java | 20 +++ 2 files changed, 88 insertions(+), 67 deletions(-) diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNChangeBoundsOperationHandler.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNChangeBoundsOperationHandler.java index 161dfd32..ac2bc73b 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNChangeBoundsOperationHandler.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNChangeBoundsOperationHandler.java @@ -188,82 +188,83 @@ private void updateFlowElement(final GNode gNode, final BPMNElementNode bpmnElem double offsetX = newPoint.getX() - gNode.getPosition().getX(); double offsetY = newPoint.getY() - gNode.getPosition().getY(); - BPMNBounds bpmnBounds = bpmnElementNode.getBounds(); - if (bpmnBounds != null) { - BPMNPoint oldBpmnPoint = bpmnBounds.getPosition(); - BPMNPoint newBpmnPoint = new BPMNPoint(oldBpmnPoint.getX() + offsetX, oldBpmnPoint.getY() + offsetY); - - // now we can verify if the element is contained by a new BPMN Pool. This is - // only needed for CollaborationDiagrams... - if (modelState.getBpmnModel().isCollaborationDiagram()) { - // find the containing participant - Participant participant = modelState.getBpmnModel().findParticipantByPoint(newBpmnPoint); - // verify if the participant ID has changed - if (participant != null && !bpmnElementNode.getProcessId().equals(participant.getProcessId())) { - logger.debug("Element was dropped on a new Participant - Processid=" + participant.getId()); - bpmnElementNode.updateParticipant(participant); - // next we can update the GModel Parent node - Optional _participantGNode = modelState.getIndex().findElementByClass(participant.getId(), - GNode.class); - if (_participantGNode.isPresent()) { - GNode parentGnode = _participantGNode.get(); - gNode.setParent(parentGnode); - - // update relative position... - GPoint relativePoint = GraphUtil.point(newBpmnPoint.getX() - parentGnode.getPosition().getX(), - newBpmnPoint.getY() - parentGnode.getPosition().getY()); - gNode.setPosition(relativePoint); - - // update Label parent... - String labelID = gNode.getId() + "_bpmnlabel"; - Optional _labelNode = modelState.getIndex().findElementByClass(labelID, GNode.class); - if (_labelNode.isPresent()) { - _labelNode.get().setParent(parentGnode); - } - } else { - // move to root - gNode.setParent(modelState.getIndex().getRoot()); - // update absolute position... - GPoint absolutePoint = GraphUtil.point(newBpmnPoint.getX(), newBpmnPoint.getY()); - gNode.setPosition(absolutePoint); - - // update Label parent... - String labelID = gNode.getId() + "_bpmnlabel"; - Optional _labelNode = modelState.getIndex().findElementByClass(labelID, GNode.class); - if (_labelNode.isPresent()) { - _labelNode.get().setParent(modelState.getIndex().getRoot()); - } + BPMNPoint oldBpmnPoint = bpmnElementNode.getBounds().getPosition(); + BPMNPoint newBpmnPoint = new BPMNPoint(oldBpmnPoint.getX() + offsetX, oldBpmnPoint.getY() + offsetY); + + // now we can verify if the element is contained by a new BPMN Pool. This is + // only needed for CollaborationDiagrams... + if (modelState.getBpmnModel().isCollaborationDiagram()) { + // find the containing participant + Participant participant = modelState.getBpmnModel().findParticipantByPoint(newBpmnPoint); + // verify if the participant ID has changed + if (participant != null && !bpmnElementNode.getProcessId().equals(participant.getProcessId())) { + logger.debug("Element was dropped on a new Participant - Processid=" + participant.getId()); + bpmnElementNode.updateParticipant(participant); + // next we can update the GModel Parent node + Optional _participantGNode = modelState.getIndex().findElementByClass(participant.getId(), + GNode.class); + if (_participantGNode.isPresent()) { + GNode parentGnode = _participantGNode.get(); + gNode.setParent(parentGnode); + + // update relative position... + GPoint relativePoint = GraphUtil.point(newBpmnPoint.getX() - parentGnode.getPosition().getX(), + newBpmnPoint.getY() - parentGnode.getPosition().getY()); + gNode.setPosition(relativePoint); + + // update Label parent... + String labelID = gNode.getId() + "_bpmnlabel"; + Optional _labelNode = modelState.getIndex().findElementByClass(labelID, GNode.class); + if (_labelNode.isPresent()) { + _labelNode.get().setParent(parentGnode); } } else { - // we are still in the same pool so we can simply update the x/y offset - gNode.setPosition(newPoint); + // move to root + gNode.setParent(modelState.getIndex().getRoot()); + // update absolute position... + GPoint absolutePoint = GraphUtil.point(newBpmnPoint.getX(), newBpmnPoint.getY()); + gNode.setPosition(absolutePoint); + + // update Label parent... + String labelID = gNode.getId() + "_bpmnlabel"; + Optional _labelNode = modelState.getIndex().findElementByClass(labelID, GNode.class); + if (_labelNode.isPresent()) { + _labelNode.get().setParent(modelState.getIndex().getRoot()); + } } } else { - // update absolute position as we are not in a collaboration diagram + // we are still in the same pool so we can simply update the x/y offset gNode.setPosition(newPoint); } + } else { + // update absolute position as we are not in a collaboration diagram + gNode.setPosition(newPoint); + } - // The BPMN Position is always absolute so we can simply update the element - // BPMN Position by the new offset and new dimensions. - bpmnBounds.setPosition(newBpmnPoint); - bpmnBounds.setDimension(newSize.getWidth(), newSize.getHeight()); + // The BPMN Position is always absolute so we can simply update the element + // bounds by the new offset and new dimensions. + // @see https://github.com/imixs/open-bpmn/issues/208 + bpmnElementNode.setBounds(newBpmnPoint.getX(), newBpmnPoint.getY(), newSize.getWidth(), + newSize.getHeight()); + // bpmnBounds.setPosition(newBpmnPoint); + // bpmnBounds.setDimension(newSize.getWidth(), newSize.getHeight()); - // Finally Update GNode dimension.... - gNode.getLayoutOptions().put(GLayoutOptions.KEY_PREF_WIDTH, newSize.getWidth()); - gNode.getLayoutOptions().put(GLayoutOptions.KEY_PREF_HEIGHT, newSize.getHeight()); - // calling the size method does not have an effect. - // see: - // https://github.com/eclipse-glsp/glsp/discussions/741#discussioncomment-3688606 - gNode.setSize(newSize); - // if the flow Element has a BPMNLabel, than we need to adjust finally the - // position of the label too - if (bpmnElementNode.hasBPMNLabel()) { - BPMNLabel bpmnLabel = bpmnElementNode.getLabel(); - Optional _labelnode = modelState.getIndex() - .findElementByClass(bpmnElementNode.getId() + "_bpmnlabel", GNode.class); - updateLabel(_labelnode.get(), bpmnLabel, offsetX, offsetY); - } + // Finally Update GNode dimension.... + gNode.getLayoutOptions().put(GLayoutOptions.KEY_PREF_WIDTH, newSize.getWidth()); + gNode.getLayoutOptions().put(GLayoutOptions.KEY_PREF_HEIGHT, newSize.getHeight()); + // calling the size method does not have an effect. + // see: + // https://github.com/eclipse-glsp/glsp/discussions/741#discussioncomment-3688606 + gNode.setSize(newSize); + // if the flow Element has a BPMNLabel, than we need to adjust finally the + // position of the label too + if (bpmnElementNode.hasBPMNLabel()) { + BPMNLabel bpmnLabel = bpmnElementNode.getLabel(); + Optional _labelnode = modelState.getIndex() + .findElementByClass(bpmnElementNode.getId() + "_bpmnlabel", GNode.class); + updateLabel(_labelnode.get(), bpmnLabel, offsetX, offsetY); } + } /** diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/Activity.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/Activity.java index 2a0df7a4..f51db937 100644 --- a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/Activity.java +++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/Activity.java @@ -1,7 +1,10 @@ package org.openbpmn.bpmn.elements; import org.openbpmn.bpmn.BPMNModel; +import org.openbpmn.bpmn.BPMNNS; +import org.openbpmn.bpmn.elements.core.BPMNBounds; import org.openbpmn.bpmn.elements.core.BPMNElementNode; +import org.openbpmn.bpmn.exceptions.BPMNMissingElementException; import org.openbpmn.bpmn.exceptions.BPMNModelException; import org.w3c.dom.Element; @@ -37,4 +40,21 @@ public double getDefaultWidth() { public double getDefaultHeight() { return DEFAULT_HEIGHT; } + + /** + * Remove any embedded bpmndi:BPMNLabel element within the bpmndi:BPMNShape + */ + @Override + public BPMNBounds setBounds(double x, double y, double width, double height) throws BPMNMissingElementException { + + BPMNBounds result = super.setBounds(x, y, width, height); + + // remove optional BPMNLabel + Element bpmnLabel = getModel().findChildNodeByName(this.bpmnShape, BPMNNS.BPMNDI, "BPMNLabel"); + if (bpmnLabel != null) { + this.bpmnShape.removeChild(bpmnLabel); + } + return result; + } + }