Skip to content

Commit 0394754

Browse files
committed
prepare version 3.0
1 parent 83e3dbe commit 0394754

11 files changed

Lines changed: 299 additions & 96 deletions

File tree

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/CreateBPMNNodeOperationHandler.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717

1818
import java.util.List;
1919
import java.util.Optional;
20+
import java.util.logging.Logger;
2021

2122
import org.eclipse.glsp.graph.GCompartment;
2223
import org.eclipse.glsp.graph.GModelElement;
23-
import org.eclipse.glsp.server.model.GModelState;
2424
import org.eclipse.glsp.server.operations.AbstractCreateOperationHandler;
2525
import org.eclipse.glsp.server.operations.CreateNodeOperation;
2626
import org.eclipse.glsp.server.operations.CreateNodeOperationHandler;
27+
import org.openbpmn.bpmn.elements.BPMNParticipant;
28+
import org.openbpmn.bpmn.elements.BPMNProcess;
2729
import org.openbpmn.glsp.bpmn.Pool;
30+
import org.openbpmn.glsp.elements.task.BPMNCreateTaskHandler;
2831
import org.openbpmn.glsp.utils.ModelTypes;
32+
import org.openbpmn.model.BPMNGModelState;
2933

3034
import com.google.common.collect.Lists;
3135
import com.google.inject.Inject;
@@ -39,9 +43,10 @@
3943
*/
4044
public abstract class CreateBPMNNodeOperationHandler extends AbstractCreateOperationHandler<CreateNodeOperation>
4145
implements CreateNodeOperationHandler {
46+
private static Logger logger = Logger.getLogger(BPMNCreateTaskHandler.class.getName());
4247

4348
@Inject
44-
protected GModelState modelState;
49+
protected BPMNGModelState modelState;
4550

4651
public CreateBPMNNodeOperationHandler(final String elementTypeId) {
4752
super(elementTypeId);
@@ -84,4 +89,36 @@ protected Optional<GCompartment> getCategoryCompartment(final Pool category) {
8489
.filter(comp -> ModelTypes.CONTAINER.equals(comp.getType())).findFirst();
8590
}
8691

92+
/**
93+
* Helper method computes the container BPMNProcess for a CreateNodeOperation.
94+
* The method first computes the GModel container Element. Than the method tests
95+
* if the container is the Model root or a BPMNPool. In the later case the
96+
* method computes the BPMNProcess from the corresponding BPMNParticipant.
97+
*
98+
* @param operation - a CreateNodeOperation
99+
* @return the corresponding BPMNProcess
100+
*/
101+
public BPMNProcess findProcessByCreateNodeOperation(final CreateNodeOperation operation) {
102+
GModelElement container = getContainer(operation).orElseGet(modelState::getRoot);
103+
String containerId = container.getId();
104+
logger.info(" ==> Container ID : " + container.getId());
105+
106+
BPMNProcess bpmnProcess = null;
107+
// is it the root?
108+
if (modelState.getRoot().getId().equals(containerId)) {
109+
bpmnProcess = modelState.getBpmnModel().openDefaultProcess();
110+
} else {
111+
// it should be a participant container
112+
if (containerId.startsWith("participant_")) {
113+
// compute participant
114+
String participantID = containerId.substring(0, containerId.lastIndexOf("_"));
115+
BPMNParticipant bpmnParticipant = modelState.getBpmnModel().findBPMNParticipantById(participantID);
116+
if (bpmnParticipant != null) {
117+
bpmnProcess = bpmnParticipant.openProcess();
118+
}
119+
}
120+
}
121+
return bpmnProcess;
122+
}
123+
87124
}

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/event/BPMNCreateEventHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ public void executeOperation(final CreateNodeOperation operation) {
7272
String eventID = "event-" + BPMNModel.generateShortID();
7373
logger.fine("===== > createNode eventnodeID=" + eventID);
7474
try {
75-
BPMNProcess process = modelState.getBpmnModel().openDefaultProcess();
76-
BPMNEvent event = process.addEvent(eventID, getLabel(), operation.getElementTypeId());
75+
// find the process - either the default process for Root container or the
76+
// corresponding participant process
77+
BPMNProcess bpmnProcess = findProcessByCreateNodeOperation(operation);
78+
BPMNEvent event = bpmnProcess.addEvent(eventID, getLabel(), operation.getElementTypeId());
7779
Optional<GPoint> point = operation.getLocation();
7880
if (point.isPresent()) {
7981
event.getBounds().updateLocation(point.get().getX(), point.get().getY());
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/********************************************************************************
2+
* Copyright (c) 2022 Imixs Software Solutions GmbH and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
* with the GNU Classpath Exception which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
********************************************************************************/
16+
package org.openbpmn.glsp.elements.event;
17+
18+
import org.eclipse.glsp.graph.GLabel;
19+
import org.eclipse.glsp.graph.GraphFactory;
20+
import org.eclipse.glsp.graph.builder.AbstractGLabelBuilder;
21+
import org.openbpmn.bpmn.BPMNTypes;
22+
import org.openbpmn.bpmn.elements.BPMNEvent;
23+
24+
/**
25+
* BPMN 2.0 Event Element.
26+
* <p>
27+
* The method builds a GNode from a BPMNEvent element. The builder is called
28+
* from the method createGModelFromProcess of the BPMNGModelFactory.
29+
* <p>
30+
* The EventNodeBuilder defines the layout and properties for all types of BPMN
31+
* Event elements. The radius of the circle symbol is 36. The label is below the
32+
* symbol.
33+
*
34+
* @author rsoika
35+
*
36+
*/
37+
38+
//public class GLabelBuilder extends AbstractGLabelBuilder<GLabel, GLabelBuilder> {
39+
//
40+
// public GLabelBuilder() {
41+
// this(DefaultTypes.LABEL);
42+
// }
43+
//
44+
// public GLabelBuilder(String type) {
45+
// super(type);
46+
// }
47+
//
48+
// @Override
49+
// protected GLabel instantiate() {
50+
// return GraphFactory.eINSTANCE.createGLabel();
51+
// }
52+
//
53+
// @Override
54+
// protected GLabelBuilder self() {
55+
// return this;
56+
// }
57+
//
58+
//}
59+
60+
public class EventLabelBuilder extends AbstractGLabelBuilder<GLabel, EventLabelBuilder> {
61+
62+
private final String name;
63+
64+
public EventLabelBuilder(final BPMNEvent event) {
65+
super(BPMNTypes.BPMN_LABEL);
66+
this.name = event.getName();
67+
this.id = event.getId() + "_bpmnlabel";
68+
69+
}
70+
71+
@Override
72+
protected GLabel instantiate() {
73+
return GraphFactory.eINSTANCE.createGLabel();
74+
}
75+
76+
@Override
77+
protected EventLabelBuilder self() {
78+
return this;
79+
}
80+
81+
@Override
82+
public void setProperties(final GLabel node) {
83+
super.setProperties(node);
84+
85+
}
86+
87+
}

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/gateway/BPMNCreateGatewayHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ public void executeOperation(final CreateNodeOperation operation) {
6969
String gatewayID = "gateway-" + BPMNModel.generateShortID();
7070
logger.fine("===== > createNode gatewaynodeID=" + gatewayID);
7171
try {
72-
BPMNProcess process = modelState.getBpmnModel().openDefaultProcess();
73-
BPMNGateway gateway = process.addGateway(gatewayID, getLabel(), operation.getElementTypeId());
72+
// find the process - either the default process for Root container or the
73+
// corresponding participant process
74+
BPMNProcess bpmnProcess = findProcessByCreateNodeOperation(operation);
75+
BPMNGateway gateway = bpmnProcess.addGateway(gatewayID, getLabel(), operation.getElementTypeId());
7476
Optional<GPoint> point = operation.getLocation();
7577
if (point.isPresent()) {
7678
gateway.getBounds().updateLocation(point.get().getX(), point.get().getY());

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/task/BPMNCreateTaskHandler.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
import java.util.Optional;
2020
import java.util.logging.Logger;
2121

22-
import org.eclipse.glsp.graph.GModelElement;
2322
import org.eclipse.glsp.graph.GPoint;
2423
import org.eclipse.glsp.server.actions.ActionDispatcher;
2524
import org.eclipse.glsp.server.actions.SelectAction;
2625
import org.eclipse.glsp.server.operations.CreateNodeOperation;
2726
import org.eclipse.glsp.server.utils.GModelUtil;
2827
import org.openbpmn.bpmn.BPMNModel;
2928
import org.openbpmn.bpmn.elements.BPMNActivity;
30-
import org.openbpmn.bpmn.elements.BPMNParticipant;
3129
import org.openbpmn.bpmn.elements.BPMNProcess;
3230
import org.openbpmn.bpmn.exceptions.BPMNModelException;
3331
import org.openbpmn.glsp.bpmn.BpmnPackage;
@@ -68,33 +66,14 @@ public BPMNCreateTaskHandler() {
6866
@Override
6967
protected void executeOperation(final CreateNodeOperation operation) {
7068

71-
GModelElement container = getContainer(operation).orElseGet(modelState::getRoot);
72-
73-
logger.info(" ==> Wir setzten das Task Element in den Container : " + container.getId());
74-
7569
elementTypeId = operation.getElementTypeId();
7670
// now we add this task into the source model
7771
String taskID = "task-" + BPMNModel.generateShortID();
7872
logger.fine("===== > createNode tasknodeID=" + taskID);
7973
try {
8074
// find the process - either the default process for Root container or the
8175
// corresponding participant process
82-
BPMNProcess bpmnProcess = null;
83-
// is it the root?
84-
if (modelState.getRoot().getId().equals(container.getId())) {
85-
bpmnProcess = modelState.getBpmnModel().openDefaultProcess();
86-
} else {
87-
// it should be a participant container
88-
if (container.getId().startsWith("participant_")) {
89-
// compute participant
90-
String participantID = container.getId().substring(0, container.getId().lastIndexOf("_"));
91-
BPMNParticipant bpmnParticipant = modelState.getBpmnModel().findBPMNParticipantById(participantID);
92-
if (bpmnParticipant != null) {
93-
bpmnProcess = bpmnParticipant.openProcess();
94-
}
95-
}
96-
}
97-
76+
BPMNProcess bpmnProcess = findProcessByCreateNodeOperation(operation);
9877
if (bpmnProcess != null) {
9978
BPMNActivity task = bpmnProcess.addTask(taskID, getLabel(), operation.getElementTypeId());
10079
Optional<GPoint> point = operation.getLocation();
@@ -115,16 +94,6 @@ protected void executeOperation(final CreateNodeOperation operation) {
11594
actionDispatcher.dispatchAfterNextUpdate(new SelectAction(), new SelectAction(List.of(taskID)));
11695
}
11796

118-
// @Override
119-
// public void executeOperation(final CreateNodeOperation operation) {
120-
// GModelElement container = getContainer(operation).orElseGet(modelState::getRoot);
121-
// Optional<GPoint> absoluteLocation = getLocation(operation);
122-
// Optional<GPoint> relativeLocation = getRelativeLocation(operation, absoluteLocation, container);
123-
// GModelElement element = createNode(relativeLocation, operation.getArgs());
124-
// container.getChildren().add(element);
125-
// actionDispatcher.dispatchAfterNextUpdate(new SelectAction(), new SelectAction(List.of(element.getId())));
126-
// }
127-
12897
@Override
12998
public String getLabel() {
13099
int nodeCounter = GModelUtil.generateId(BpmnPackage.Literals.TASK_NODE, elementTypeId, modelState);

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNChangeBoundsOperationHandler.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.List;
1919
import java.util.Optional;
20+
import java.util.Set;
2021
import java.util.logging.Logger;
2122

2223
import org.eclipse.glsp.graph.GDimension;
@@ -33,6 +34,8 @@
3334
import org.openbpmn.bpmn.elements.BPMNFlowElement;
3435
import org.openbpmn.bpmn.elements.BPMNGateway;
3536
import org.openbpmn.bpmn.elements.BPMNLabel;
37+
import org.openbpmn.bpmn.elements.BPMNParticipant;
38+
import org.openbpmn.bpmn.elements.BPMNProcess;
3639
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
3740
import org.openbpmn.model.BPMNGModelState;
3841

@@ -72,19 +75,23 @@ public class BPMNChangeBoundsOperationHandler extends AbstractOperationHandler<C
7275

7376
@Override
7477
public void executeOperation(final ChangeBoundsOperation operation) {
75-
76-
// BPMNProcess context = modelState.getBpmnModel().openDefaultProcess();
7778
// iterate over all new Bounds...
7879
try {
7980
List<ElementAndBounds> elementBounds = operation.getNewBounds();
8081
for (ElementAndBounds elementBound : elementBounds) {
8182
String id = elementBound.getElementId();
83+
8284
GPoint newPoint = elementBound.getNewPosition();
8385
GDimension newSize = elementBound.getNewSize();
86+
8487
// find the corresponding BPMN and GNode element
8588

89+
logger.info("...bounds update for: " + id);
8690
BPMNBounds bpmnBounds = modelState.getBpmnModel().findBPMNBoundsById(id);
8791
if (bpmnBounds != null) {
92+
double offsetX = newPoint.getX() - bpmnBounds.getPosition().getX();
93+
double offsetY = newPoint.getY() - bpmnBounds.getPosition().getY();
94+
8895
// find the corresponding GNode element and update the dimension and position...
8996
Optional<GNode> _node = modelState.getIndex().findElementByClass(id, GNode.class);
9097
if (_node.isPresent()) {
@@ -106,6 +113,15 @@ public void executeOperation(final ChangeBoundsOperation operation) {
106113
// finally update BPMNElement bounds....
107114
bpmnBounds.updateLocation(newPoint.getX(), newPoint.getY());
108115
bpmnBounds.updateDimension(newSize.getWidth(), newSize.getHeight());
116+
117+
// if we have a Participant element selected than we need to iterate over all
118+
// embedded BPMNFlow Elements and update the bounds too.
119+
BPMNParticipant participant = modelState.getBpmnModel().findBPMNParticipantById(id);
120+
if (participant != null) {
121+
logger.info("...update participant pool elements: offset= " + offsetX + " , " + offsetY);
122+
updateProcessElementBounds(participant.openProcess(), offsetX, offsetY);
123+
}
124+
109125
} else {
110126
// test if we have a BPMNLable element was selected?
111127
if (id.endsWith("_bpmnlabel")) {
@@ -142,4 +158,28 @@ public void executeOperation(final ChangeBoundsOperation operation) {
142158
// no more action - the GModel is now up to date
143159
}
144160

161+
/**
162+
* This method updates the position for all BPMNFlowElements contained in a pool
163+
* given a x and y offset.
164+
*
165+
* @param process
166+
* @param participant
167+
* @throws BPMNMissingElementException
168+
*/
169+
void updateProcessElementBounds(final BPMNProcess process, final double offsetX, final double offsetY) {
170+
Set<BPMNFlowElement> bpmnFlowElements = process.getBPMNFlowElements();
171+
// Add all Tasks
172+
for (BPMNFlowElement flowElement : bpmnFlowElements) {
173+
logger.info("update element bounds: " + flowElement.getId());
174+
try {
175+
BPMNBounds bounds = flowElement.getBounds();
176+
if (bounds != null) {
177+
bounds.updateLocation(bounds.getPosition().getX() + offsetX, bounds.getPosition().getY() + offsetY);
178+
}
179+
} catch (BPMNMissingElementException e) {
180+
logger.warning("Failed to update FlowElement bounds for : " + flowElement.getId());
181+
}
182+
}
183+
}
184+
145185
}

open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNDeleteNodeHandler.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
2121
import org.eclipse.glsp.server.operations.DeleteOperation;
22-
import org.openbpmn.bpmn.elements.BPMNActivity;
2322
import org.openbpmn.bpmn.elements.BPMNBaseElement;
24-
import org.openbpmn.bpmn.elements.BPMNEvent;
25-
import org.openbpmn.bpmn.elements.BPMNGateway;
26-
import org.openbpmn.bpmn.elements.BPMNSequenceFlow;
23+
import org.openbpmn.bpmn.elements.BPMNFlowElement;
24+
import org.openbpmn.bpmn.elements.BPMNParticipant;
25+
import org.openbpmn.bpmn.elements.BPMNProcess;
2726
import org.openbpmn.model.BPMNGModelState;
2827

2928
import com.google.inject.Inject;
@@ -41,24 +40,23 @@ public void executeOperation(final DeleteOperation operation) {
4140
System.out.println("Elements to delete are not specified");
4241
}
4342
for (String id : elementIds) {
44-
System.out.println("...delete Element " + id);
45-
4643
// Update the source model
47-
BPMNBaseElement baseElement = modelState.getBpmnModel().openDefaultProcess().findBaseElementById(id);
48-
if (baseElement == null) {
49-
System.out.println("...no BPMN elmenet with id: " + id + " found!");
50-
}
51-
if (baseElement instanceof BPMNActivity) {
52-
modelState.getBpmnModel().openDefaultProcess().deleteTask(id);
53-
}
54-
if (baseElement instanceof BPMNEvent) {
55-
modelState.getBpmnModel().openDefaultProcess().deleteEvent(id);
56-
}
57-
if (baseElement instanceof BPMNGateway) {
58-
modelState.getBpmnModel().openDefaultProcess().deleteGateway(id);
59-
}
60-
if (baseElement instanceof BPMNSequenceFlow) {
61-
modelState.getBpmnModel().openDefaultProcess().deleteSequenceFlow(id);
44+
System.out.println("...delete Element " + id);
45+
// test if the element is a participant or a FlowElement
46+
BPMNParticipant participant = modelState.getBpmnModel().findBPMNParticipantById(id);
47+
if (participant != null) {
48+
// delete participant with the pool and all contained elements
49+
modelState.getBpmnModel().deleteBPMNParticipant(participant);
50+
} else {
51+
// find the bpmnFlowElement
52+
BPMNBaseElement baseElement = modelState.getBpmnModel().findBPMNBaseElementById(id);
53+
if (baseElement != null && baseElement instanceof BPMNFlowElement) {
54+
// open the corresponding process
55+
BPMNProcess process = ((BPMNFlowElement) baseElement).getBpmnProcess();
56+
process.deleteBPMNBaseElement(id);
57+
} else {
58+
System.out.println("...no BPMN elmenet with id: " + id + " found!");
59+
}
6260
}
6361
}
6462

0 commit comments

Comments
 (0)