Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Issue #341
  • Loading branch information
rsoika committed Mar 6, 2024
1 parent d808c20 commit 561c4c0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ private void updateSignalEvents() {
Set<Element> signalEventDefinitions = event.getEventDefinitionsByType("signalEventDefinition");
if (signalEventDefinitions.size() > 0) {
// find the gmodel
BPMNGNode _baseElement = modelState.getIndex().findElementByClass(event.getId(),
BPMNGNode.class).orElse(null);
BPMNGNode _baseElement = (BPMNGNode) modelState.getIndex().get(event.getId()).orElse(null);
if (_baseElement != null) {
bpmnGModelFactory.applyBPMNElementExtensions(_baseElement, event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.openbpmn.glsp.elements.event.BPMNCreateEventDefinitionHandler;
import org.openbpmn.glsp.elements.event.BPMNCreateEventHandler;
import org.openbpmn.glsp.elements.gateway.BPMNCreateGatewayHandler;
import org.openbpmn.glsp.elements.label.BPMNApplyEditLabelOperationHandler;
import org.openbpmn.glsp.elements.pool.CreateLaneHandler;
import org.openbpmn.glsp.elements.pool.CreatePoolHandler;
import org.openbpmn.glsp.elements.task.BPMNCreateTaskHandler;
Expand Down Expand Up @@ -121,7 +120,7 @@ protected void configureOperationHandlers(final MultiBinding<OperationHandler<?>
super.configureOperationHandlers(binding);

// Inline Edit
binding.add(BPMNApplyEditLabelOperationHandler.class);
// binding.add(BPMNApplyEditLabelOperationHandler.class);

binding.add(GModelCutOperationHandler.class);
// binding.add(DeleteOperationHandler.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

import com.google.inject.Inject;

/**
* Handler to create a BPMN SequenceFlow, MessageFlow or Association.
*/
public class BPMNGEdgeCreateHandler extends CreateBPMNEdgeOperationHandler {

protected final String label;
Expand Down Expand Up @@ -63,36 +66,27 @@ public Optional<Command> createCommand(final CreateEdgeOperation operation) {

/**
* Adds a new BPMNEdge to the diagram. Depending on the type a SequenceFlow,
* MessageFlow or Association is crated.
* MessageFlow or Association is created.
*/
protected void executeOperation(final CreateEdgeOperation operation) {
if (operation.getSourceElementId() == null || operation.getTargetElementId() == null) {
throw new IllegalArgumentException("Incomplete create connection action");
}
String edgeId = null;
BPMNGNode sourceNode = null;
BPMNGNode targetNode = null;
BPMNGNode sourceGNode = null;
BPMNGNode targetGNode = null;
BPMNElementNode sourceElementNode = null;
BPMNElementNode targetElementNode = null;

String edgeType = operation.getElementTypeId();
try {
Optional<BPMNGNode> element = null;
String targetId = operation.getTargetElementId();
// find GNode
element = modelState.getIndex().findElementByClass(targetId, BPMNGNode.class);
if (element.isPresent()) {
targetNode = element.get();
targetId = targetNode.getId();
}
targetGNode = (BPMNGNode) modelState.getIndex().get(targetId).orElse(null);

String sourceId = operation.getSourceElementId();
// find GNode
element = modelState.getIndex().findElementByClass(sourceId, BPMNGNode.class);
if (element.isPresent()) {
sourceNode = element.get();
sourceId = sourceNode.getId();
}
sourceGNode = (BPMNGNode) modelState.getIndex().get(sourceId).orElse(null);

// Depending on the edgeType we use here different method to create the BPMN
// edge
Expand Down Expand Up @@ -140,7 +134,7 @@ protected void executeOperation(final CreateEdgeOperation operation) {
targetElementNode.resetValidation();

// finally update he current selection
updateSelection(sourceNode, targetNode, edgeId);
updateSelection(sourceGNode, targetGNode, edgeId);
modelState.reset();

} catch (BPMNModelException e) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,4 @@ public void setProperties(final LabelGNode node) {
.add(BPMNGModelUtil.createMultiLineTextNode(node, name, BPMNGModelUtil.MULTILINETEXT_ALIGN_MIDDLE, 0));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,13 @@ private void executeOperation(final ChangeBoundsOperation operation) {
GPoint newPoint = BPMNGridSnapper.round(elementBound.getNewPosition());
GDimension newSize = BPMNGridSnapper.round(elementBound.getNewSize());
// find the corresponding GNode Element
Optional<GNode> _node = modelState.getIndex().findElementByClass(id, GNode.class);
if (!_node.isPresent()) {
GNode gNode = (GNode) modelState.getIndex().get(id).orElse(null);
if (gNode == null) {
// this case should not happen!
logger.error("GNode '" + id + "' not found in current modelState!");
continue;
}

GNode gNode = _node.get();
// compute the new offset x/y
double offsetX = Math.round(newPoint.getX() - gNode.getPosition().getX());
double offsetY = Math.round(newPoint.getY() - gNode.getPosition().getY());
Expand Down Expand Up @@ -196,15 +195,14 @@ private void updateLaneSizeByDividerPos(GNode gNode, double offsetY) throws BPMN
String lowerLaneID = gNode.getArgs().get("lowerlaneid").toString();

// Upper Lane
GNode upperGLane = modelState.getIndex().findElementByClass(upperLaneID, GNode.class)
GNode upperGLane = modelState.getIndex().get(upperLaneID, GNode.class)
.orElse(null);
if (upperGLane == null) {
throw new BPMNMissingElementException(BPMNMissingElementException.MISSING_ELEMENT,
"Lane " + upperLaneID + " not found in model!");
}
// Lower Lane
GNode lowerGLane = modelState.getIndex().findElementByClass(lowerLaneID, GNode.class)
.orElse(null);
GNode lowerGLane = (GNode) modelState.getIndex().get(lowerLaneID).orElse(null);
if (lowerGLane == null) {
throw new BPMNMissingElementException(BPMNMissingElementException.MISSING_ELEMENT,
"Lane " + upperLaneID + " not found in model!");
Expand Down Expand Up @@ -368,9 +366,9 @@ private void updateFlowElement(final GNode gNode, final BPMNElementNode bpmnElem
// 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);
GNode _labelnode = (GNode) modelState.getIndex()
.get(bpmnElementNode.getId() + "_bpmnlabel").orElse(null);
updateLabel(_labelnode, bpmnLabel, offsetX, offsetY);
}

}
Expand Down Expand Up @@ -551,10 +549,8 @@ private void updateLaneSet(final Participant participant, final double offsetWid
lane.setPosition(bpmnLaneX, bpmnLaneY);

// update Gnode
Optional<GNode> _lanenode = modelState.getIndex().findElementByClass(lane.getId(), GNode.class);
if (_lanenode.isPresent()) {

GNode gLaneNode = _lanenode.get();
GNode gLaneNode = (GNode) modelState.getIndex().get(lane.getId()).orElse(null);
if (gLaneNode != null) {
gLaneNode.setSize(GraphUtil.dimension(bpmnLaneWidth, laneHeight));
gLaneNode.setPosition(GraphUtil.point(bpmnLaneX - poolBounds.getPosition().getX(),
bpmnLaneY - poolBounds.getPosition().getY()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class BPMNChangeRoutingPointsOperationHandler extends GModelOperationHand
@Inject
protected BPMNGModelState modelState;


@Override
public Optional<Command> createCommand(ChangeRoutingPointsOperation operation) {
return commandOf(() -> executeOperation(operation));
Expand All @@ -62,10 +61,9 @@ private void executeOperation(final ChangeRoutingPointsOperation operation) {
String id = routingPoint.getElementId();
List<GPoint> newGLSPRoutingPoints = routingPoint.getNewRoutingPoints();
// update the GModel.
Optional<GEdge> _edge = modelState.getIndex().findElementByClass(id, GEdge.class);
if (_edge.isPresent()) {
GEdge edge = (GEdge) modelState.getIndex().get(id).orElse(null);
if (edge != null) {
logger.fine("===== Updating GLSP RoutingPoints =======");
GEdge edge = _edge.get();
edge.getRoutingPoints().clear();
edge.getRoutingPoints().addAll(newGLSPRoutingPoints);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,12 @@ private void executeOperation(final BPMNPropertiesApplyOperation operation) {
bpmnElement = modelState.getBpmnModel().openDefaultProces();
} else {
// find the corresponding gModelElement and bpmnElement....
Optional<BPMNGNode> _baseElement = modelState.getIndex().findElementByClass(elementID, BPMNGNode.class);
gModelElement = _baseElement.orElse(null);
gModelElement = modelState.getIndex().get(elementID).orElse(null);
if (gModelElement != null) {
bpmnElement = modelState.getBpmnModel().findElementNodeById(elementID);
} else {
// not yet found - check Edges....
Optional<BPMNGEdge> _baseEdge = modelState.getIndex().findElementByClass(elementID, BPMNGEdge.class);
gModelElement = _baseEdge.orElse(null);
if (gModelElement != null) {
if (gModelElement instanceof BPMNGNode) {
bpmnElement = modelState.getBpmnModel().findElementNodeById(elementID);
}
if (gModelElement instanceof BPMNGEdge) {
bpmnElement = modelState.getBpmnModel().findElementEdgeById(elementID);
}
}
Expand Down

0 comments on commit 561c4c0

Please sign in to comment.