Skip to content

Commit

Permalink
impl, refactoring ChangeBoundsOperationHandler
Browse files Browse the repository at this point in the history
Issue imixs#208
  • Loading branch information
rsoika committed Mar 11, 2023
1 parent a6de4b9 commit 1f2a7b3
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<GNode> _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<GNode> _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<GNode> _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<GNode> _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<GNode> _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<GNode> _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<GNode> _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<GNode> _labelnode = modelState.getIndex()
.findElementByClass(bpmnElementNode.getId() + "_bpmnlabel", GNode.class);
updateLabel(_labelnode.get(), bpmnLabel, offsetX, offsetY);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}

}

0 comments on commit 1f2a7b3

Please sign in to comment.