Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
Issue #355
  • Loading branch information
rsoika committed Sep 15, 2024
1 parent 462372d commit 659955f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 54 deletions.
20 changes: 11 additions & 9 deletions open-bpmn.glsp-client/workspace/demo/test.bpmn
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:open-bpmn="http://open-bpmn.org/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exporter="org.openbpmn" exporterVersion="1.0.0" targetNamespace="http://open-bpmn.org">
<bpmn2:extensionElements>
<open-bpmn:auto-align/>
</bpmn2:extensionElements>
<bpmn2:process id="process_1" name="Default Process" processType="Public">
<bpmn2:documentation id="documentation_WfiOvw"/>
<bpmn2:task id="task_tkoHCw" name="Task-1">
<bpmn2:task id="task_tkoHCw" name="Task-1f">
<bpmn2:documentation id="documentation_zSYcyA"/>
<bpmn2:incoming>sequenceFlow_lSyUUw</bpmn2:incoming>
<bpmn2:outgoing>sequenceFlow_Z90WfQ</bpmn2:outgoing>
Expand All @@ -13,16 +16,16 @@
<bpmn2:outgoing>sequenceFlow_fOGZ3Q</bpmn2:outgoing>
<bpmn2:incoming>sequenceFlow_FM0m0Q</bpmn2:incoming>
</bpmn2:manualTask>
<bpmn2:startEvent id="event_tv6dLQ" name="Event-1">
<bpmn2:startEvent id="event_tv6dLQ" name="Start">
<bpmn2:documentation id="documentation_MvQFPA"/>
<bpmn2:outgoing>sequenceFlow_lSyUUw</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:endEvent id="event_bo2HLQ" name="Event-2">
<bpmn2:endEvent id="event_bo2HLQ" name="End">
<bpmn2:documentation id="documentation_anXNMg"/>
<bpmn2:incoming>sequenceFlow_1avBJw</bpmn2:incoming>
<bpmn2:incoming>sequenceFlow_fOGZ3Q</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:exclusiveGateway gatewayDirection="Diverging" id="gateway_uk0WOA" name="Gateway-1">
<bpmn2:exclusiveGateway gatewayDirection="Diverging" id="gateway_uk0WOA" name="Gateway">
<bpmn2:documentation id="documentation_VxD7yA"/>
<bpmn2:incoming>sequenceFlow_Z90WfQ</bpmn2:incoming>
<bpmn2:outgoing>sequenceFlow_1avBJw</bpmn2:outgoing>
Expand All @@ -33,7 +36,7 @@
<bpmn2:sequenceFlow id="sequenceFlow_Z90WfQ" sourceRef="task_tkoHCw" targetRef="gateway_uk0WOA">
<bpmn2:documentation id="documentation_GIcc1A"/>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="sequenceFlow_1avBJw" sourceRef="gateway_uk0WOA" targetRef="event_bo2HLQ">
<bpmn2:sequenceFlow id="sequenceFlow_1avBJw" name="Flow" sourceRef="gateway_uk0WOA" targetRef="event_bo2HLQ">
<bpmn2:documentation id="documentation_9HTztw"/>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="sequenceFlow_fOGZ3Q" sourceRef="task_bbl20g" targetRef="event_bo2HLQ">
Expand All @@ -52,9 +55,9 @@
<dc:Bounds height="50.0" width="120.0" x="530.0" y="130.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="event_tv6dLQ" id="BPMNShape_84lOnQ">
<dc:Bounds height="36.0" width="36.0" x="140.0" y="137.0"/>
<dc:Bounds height="36.0" width="36.0" x="124.0" y="137.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_4c0r7Q">
<dc:Bounds height="20.0" width="100.0" x="108.0" y="176.0"/>
<dc:Bounds height="20.0" width="100.0" x="92.0" y="176.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="event_bo2HLQ" id="BPMNShape_kt4kJg">
Expand All @@ -70,12 +73,11 @@
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_lSyUUw" id="BPMNEdge_cfMCEg" sourceElement="BPMNShape_84lOnQ" targetElement="BPMNShape_CklJlA">
<di:waypoint x="176.0" y="155.0"/>
<di:waypoint x="160.0" y="155.0"/>
<di:waypoint x="240.0" y="155.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_Z90WfQ" id="BPMNEdge_AVFs2w" sourceElement="BPMNShape_CklJlA" targetElement="BPMNShape_bn5GyA">
<di:waypoint x="310.0" y="180.0"/>
<di:waypoint x="310.0" y="190.0"/>
<di:waypoint x="310.0" y="225.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_1avBJw" id="BPMNEdge_8IxMiw" sourceElement="BPMNShape_bn5GyA" targetElement="BPMNShape_kt4kJg">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import org.openbpmn.bpmn.BPMNNS;
import org.openbpmn.bpmn.elements.Event;
import org.openbpmn.bpmn.elements.core.BPMNElement;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.elements.core.BPMNLabel;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.glsp.bpmn.BPMNGEdge;
import org.openbpmn.glsp.bpmn.BPMNGNode;
Expand Down Expand Up @@ -103,9 +100,13 @@ public int getPriority() {
* corresponding GNode Element in the diagram plane.
* <p>
* The method distinguish between embedded labels (Task) and BPMNLabes.
*
* In case of a LabelGNode elements can support multilineor simple line
* <p>
* In case of a LabelGNode elements can support multiline or simple line
* GLabel elements
* <p>
* Note: If the name is empty an existing gMultiLineTextNode will be removed.
* This has the effect that not blank area is shown in the diagram for elements
* with out a label. The method automatically recreates the label if missing.
*
* @param json
* @param bpmnElement
Expand All @@ -117,6 +118,7 @@ public void updateNameProperty(final JsonObject json, BPMNElement bpmnElement,
// Update the name feature
String name = json.getString("name", "");
if (!name.equals(bpmnElement.getName())) {

bpmnElement.setName(name);
if (gNodeElement instanceof BPMNGNode
|| gNodeElement instanceof BPMNGEdge) {
Expand All @@ -134,24 +136,23 @@ public void updateNameProperty(final JsonObject json, BPMNElement bpmnElement,
if (gModelElement instanceof LabelGNode) {
LabelGNode lgn = (LabelGNode) gModelElement;
// update the bpmn-text-node of the GNodeElement.
// Here we use the recomputeBPMNLabelHeight method to optimize
// the height of the BPMNLabel
gMultiLineTextNode = BPMNGModelUtil.findMultiLineTextNode(lgn);
if (gMultiLineTextNode != null) {
gMultiLineTextNode.getArgs().put("text", name);
LabelGNode label = (LabelGNode) gModelElement;
try {
BPMNLabel bpmnLabel = ((BPMNElementNode) bpmnElement).getLabel();
// BPMNGModelUtil.optimizeBPMNLabelHeight(label, bpmnLabel, name);
} catch (BPMNMissingElementException e) {
e.printStackTrace();
}
}
// if empty then we remove the lable element
if (name.isEmpty()) {
modelState.reset();
}
} else {
// default to GLabel
GLabel gLabel = (GLabel) gModelElement;
gLabel.setText(name);
}
} else {
// the gLabel was not found. This can be the case if the element had no label
// before. So we reset the model to ensure the correct position of the label.
modelState.reset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.eclipse.glsp.graph.util.GConstants;
import org.eclipse.glsp.graph.util.GraphUtil;
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.Event;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.elements.core.BPMNLabel;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.bpmn.util.BPMNXMLUtil;
import org.openbpmn.glsp.bpmn.BpmnFactory;
import org.openbpmn.glsp.bpmn.LabelGNode;
import org.openbpmn.glsp.utils.BPMNGModelUtil;
Expand Down Expand Up @@ -65,34 +65,11 @@ public LabelGNodeBuilder(final BPMNElementNode flowElement) {
y = flowElement.getLabel().getBounds().getPosition().getY();
width = flowElement.getLabel().getBounds().getDimension().getWidth();
height = flowElement.getLabel().getBounds().getDimension().getHeight();

// If no x/y is set we compute the default position. This will also reflect to
// the source model, if the model will be saved later by the user...
if (x == 0 || y == 0) {
x = flowElement.getBounds().getPosition().getX() + (Event.DEFAULT_WIDTH / 2)
- (BPMNLabel.DEFAULT_WIDTH / 2);
y = flowElement.getBounds().getPosition().getY() + Event.DEFAULT_HEIGHT + Event.LABEL_OFFSET;
// update source model with default width/height!
flowElement.getLabel().getBounds().setPosition(x, y);
}
// If no width/heigh is set or the width/height does not match
// the open bpmn DEFAULT_WIDTH/HEIGHT, we adjust the dimensions
// to the default settings. This will also reflect to the source model,
// if the model will be saved later by the user...
if (width != BPMNLabel.DEFAULT_WIDTH || height != BPMNLabel.DEFAULT_HEIGHT) {
if (width > 0) {
// adjust x postion .....
double xOffset = ((BPMNLabel.DEFAULT_WIDTH - width) / 2);
x = x - xOffset;
flowElement.getLabel().getBounds().setPosition(x, y);
}

width = BPMNLabel.DEFAULT_WIDTH;
height = BPMNLabel.DEFAULT_HEIGHT;
// update source model with default width/height!
flowElement.getLabel().getBounds().setDimension(width, height);
if (x == 0 || y == 0 || width == 0 || height == 0) {
BPMNXMLUtil.resetLabelBounds(flowElement);
}

}
} catch (BPMNMissingElementException e) {
// failed to compute size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.openbpmn.bpmn.elements.core.BPMNPoint;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.bpmn.util.BPMNXMLUtil;
import org.openbpmn.extensions.BPMNElementExtension;
import org.openbpmn.glsp.bpmn.BPMNGEdge;
import org.openbpmn.glsp.bpmn.DataObjectGNode;
Expand Down Expand Up @@ -586,8 +587,15 @@ List<GModelElement> computeGModelElements(final BPMNProcess process, final Parti

// now add a GLabel
BPMNLabel bpmnLabel = event.getLabel();
LabelGNode labelNode = createLabelNode(bpmnLabel, event, participant);
gNodeList.add(labelNode);
// create only if name is defined
if (!event.getName().isEmpty()) {
LabelGNode labelNode = createLabelNode(bpmnLabel, event, participant);
gNodeList.add(labelNode);
} else {
// we do not draw gLabel because name is empty
// reset the position
BPMNXMLUtil.resetLabelBounds(event);
}
}

// Add all Gateways...
Expand All @@ -607,8 +615,15 @@ List<GModelElement> computeGModelElements(final BPMNProcess process, final Parti

// now add a GLabel
BPMNLabel bpmnLabel = gateway.getLabel();
LabelGNode labelNode = createLabelNode(bpmnLabel, gateway, participant);
gNodeList.add(labelNode);
// create only if name is defined
if (!gateway.getName().isEmpty()) {
LabelGNode labelNode = createLabelNode(bpmnLabel, gateway, participant);
gNodeList.add(labelNode);
} else {
// we do not draw gLabel because name is empty
// reset the position
BPMNXMLUtil.resetLabelBounds(gateway);
}
}

// Add all Dataobjects...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ private void updateFlowElement(final GNode gNode, final BPMNElementNode bpmnElem
BPMNLabel bpmnLabel = bpmnElementNode.getLabel();
GNode _labelnode = (GNode) modelState.getIndex()
.get(bpmnElementNode.getId() + "_bpmnlabel").orElse(null);
updateLabel(_labelnode, bpmnLabel, offsetX, offsetY);
if (_labelnode != null) {
updateLabel(_labelnode, bpmnLabel, offsetX, offsetY);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
********************************************************************************/
package org.openbpmn.bpmn.util;

import org.openbpmn.bpmn.BPMNModel;
import org.openbpmn.bpmn.elements.Event;
import org.openbpmn.bpmn.elements.Gateway;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.elements.core.BPMNLabel;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;

/**
* The BPMNXMLUtil provides helper methods for xml strings
*
Expand All @@ -23,6 +30,35 @@
*/
public class BPMNXMLUtil {

/**
* This method resets the Label Postion and bounds to its default values. The
* method is used in cases where no bounds are set or in case the postion should
* be reset to the default position of a label. This will also reflect to the
* source model, if the model will be saved later by the user...
*
* @throws BPMNMissingElementException
*/
public static void resetLabelBounds(final BPMNElementNode flowElement) throws BPMNMissingElementException {
double x = 0;
double y = 0;
if (BPMNModel.isGateway(flowElement)) {
// gateway dimensions...
x = flowElement.getBounds().getPosition().getX() + (Gateway.DEFAULT_WIDTH / 2)
- (BPMNLabel.DEFAULT_WIDTH / 2);
y = flowElement.getBounds().getPosition().getY() + Gateway.DEFAULT_HEIGHT + Gateway.LABEL_OFFSET;
} else {
// default (events)
x = flowElement.getBounds().getPosition().getX() + (Event.DEFAULT_WIDTH / 2)
- (BPMNLabel.DEFAULT_WIDTH / 2);
y = flowElement.getBounds().getPosition().getY() + Event.DEFAULT_HEIGHT + Event.LABEL_OFFSET;
}

// update source model with default width/height!
flowElement.getLabel().getBounds().setPosition(x, y);
// update source model with default width/height!
flowElement.getLabel().getBounds().setDimension(BPMNLabel.DEFAULT_WIDTH, BPMNLabel.DEFAULT_HEIGHT);
}

/**
* This method removes whitespace around CDATA Tags like:
*
Expand Down

0 comments on commit 659955f

Please sign in to comment.