@SuppressWarnings("unchecked")
public PictogramElement add(IAddContext context) {
IAddConnectionContext addConContext = (IAddConnectionContext) context;
SequenceFlow addedSequenceFlow = (SequenceFlow) context.getNewObject();
Anchor sourceAnchor = null;
Anchor targetAnchor = null;
if(addConContext.getSourceAnchor() == null) {
EList<Shape> shapeList = getDiagram().getChildren();
for (Shape shape : shapeList) {
FlowNode flowNode = (FlowNode) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm().getPictogramElement());
if(flowNode == null || flowNode.getId() == null || addedSequenceFlow.getSourceRef() == null ||
addedSequenceFlow.getTargetRef() == null) continue;
if(flowNode.getId().equals(addedSequenceFlow.getSourceRef())) {
EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
for (Anchor anchor : anchorList) {
if(anchor instanceof ChopboxAnchor) {
sourceAnchor = anchor;
break;
}
}
}
if(flowNode.getId().equals(addedSequenceFlow.getTargetRef())) {
EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
for (Anchor anchor : anchorList) {
if(anchor instanceof ChopboxAnchor) {
targetAnchor = anchor;
break;
}
}
}
}
} else {
sourceAnchor = addConContext.getSourceAnchor();
targetAnchor = addConContext.getTargetAnchor();
}
if(sourceAnchor == null || targetAnchor == null) {
return null;
}
IPeCreateService peCreateService = Graphiti.getPeCreateService();
// CONNECTION WITH POLYLINE
FreeFormConnection connection = peCreateService.createFreeFormConnection(getDiagram());
connection.setStart(sourceAnchor);
connection.setEnd(targetAnchor);
sourceAnchor.getOutgoingConnections().add(connection);
targetAnchor.getIncomingConnections().add(connection);
Bpmn2MemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram()));
FlowElement sourceElement = model.getFlowElement(addedSequenceFlow.getSourceRef());
FlowElement targetElement = model.getFlowElement(addedSequenceFlow.getTargetRef());