@SuppressWarnings("unchecked")
List<GraphicInfo> bendpointList = (List<GraphicInfo>) addConnectionContext.getProperty("org.activiti.designer.bendpoints");
if(bendpointList != null && bendpointList.size() >= 0) {
for (GraphicInfo graphicInfo : bendpointList) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
bendPoint.setX((int)graphicInfo.getX());
bendPoint.setY((int)graphicInfo.getY());
connection.getBendpoints().add(bendPoint);
}
} else {
Shape sourceShape = (Shape) getPictogramElement(sourceElement);
ILocation sourceShapeLocation = Graphiti.getLayoutService().getLocationRelativeToDiagram(sourceShape);
int sourceX = sourceShapeLocation.getX();
int sourceY = sourceShapeLocation.getY();
Shape targetShape = (Shape) getPictogramElement(targetElement);
ILocation targetShapeLocation = Graphiti.getLayoutService().getLocationRelativeToDiagram(targetShape);
int targetX = targetShapeLocation.getX();
int targetY = targetShapeLocation.getY();
if (sourceElement instanceof Gateway && targetElement instanceof Gateway == false) {
if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
|| (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
(sourceGraphics.getX() + (sourceGraphics.getWidth() / 2)) < targetGraphics.getX()) {
boolean subProcessWithBendPoint = false;
if(targetElement instanceof SubProcess) {
int middleSub = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
if((sourceGraphics.getY() + 20) < middleSub || (sourceGraphics.getY() - 20) > middleSub) {
subProcessWithBendPoint = true;
}
}
if(targetElement instanceof SubProcess == false || subProcessWithBendPoint == true) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
bendPoint.setX(sourceX + 20);
bendPoint.setY(targetY + (targetGraphics.getHeight() / 2));
connection.getBendpoints().add(bendPoint);
}
}
} else if (targetElement instanceof Gateway) {
if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
|| (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) {
boolean subProcessWithBendPoint = false;
if(sourceElement instanceof SubProcess) {
int middleSub = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
if((middleSub + 20) < targetGraphics.getY() || (middleSub - 20) > targetGraphics.getY()) {
subProcessWithBendPoint = true;
}
}
if(sourceElement instanceof SubProcess == false || subProcessWithBendPoint == true) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
bendPoint.setX(targetX + 20);
bendPoint.setY(sourceY + (sourceGraphics.getHeight() / 2));
connection.getBendpoints().add(bendPoint);
}
}
} else if (targetElement instanceof EndEvent) {
int middleSource = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
int middleTarget = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
if (((middleSource + 10) < middleTarget &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) ||
((middleSource - 10) > middleTarget &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX())) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
bendPoint.setX(targetX + (targetGraphics.getWidth() / 2));
bendPoint.setY(sourceY + (sourceGraphics.getHeight() / 2));
connection.getBendpoints().add(bendPoint);
}
}
}