}
@Override
public PictogramElement add(final IAddContext context) {
final IAddConnectionContext addConnectionContext = (IAddConnectionContext) context;
final Association association = (Association) context.getNewObject();
Anchor sourceAnchor = addConnectionContext.getSourceAnchor();
Anchor targetAnchor = addConnectionContext.getTargetAnchor();
if (sourceAnchor == null) {
final List<Shape> shapes = getDiagram().getChildren();
for (final Shape shape : shapes) {
final BaseElement baseElement
= (BaseElement) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm()
.getPictogramElement());
if (baseElement == null || baseElement.getId() == null
|| association.getSourceRef() == null || association.getTargetRef() == null) {
continue;
}
if (baseElement.getId().equals(association.getSourceRef())) {
final List<Anchor> anchors = ((ContainerShape) shape).getAnchors();
for (final Anchor anchor : anchors) {
if (anchor instanceof ChopboxAnchor) {
sourceAnchor = anchor;
break;
}
}
}
if (baseElement.getId().equals(association.getTargetRef())) {
final List<Anchor> anchors = ((ContainerShape) shape).getAnchors();
for (final Anchor anchor : anchors) {
if (anchor instanceof ChopboxAnchor) {
targetAnchor = anchor;
break;
}
}
}
}
}
if (sourceAnchor == null || targetAnchor == null) {
return null;
}
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
// CONNECTION WITH POLYLINE
final 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()));
BaseElement sourceElement = model.getFlowElement(association.getSourceRef());
if (sourceElement == null) {
sourceElement = model.getArtifact(association.getSourceRef());
}
BaseElement targetElement = model.getFlowElement(association.getTargetRef());
if (targetElement == null) {
targetElement = model.getArtifact(association.getTargetRef());
}
final GraphicsAlgorithm sourceGraphics = getPictogramElement(sourceElement).getGraphicsAlgorithm();
GraphicsAlgorithm targetGraphics = getPictogramElement(targetElement).getGraphicsAlgorithm();