addContext.setLocation(x, y);
addContext.setTargetContainer(getDiagram());
// execute the add to diagram action
IAddFeature addFeature = getFeatureProvider().getAddFeature(addContext);
PictogramElement newNode = null;
if (addFeature.canAdd(addContext)) {
newNode = addFeature.add(addContext);
if (newNode != null) {
RouteSupport selectedRoute = Activator.getDiagramEditor().getSelectedRoute();
if (selectedRoute != null) {
selectedRoute.addChild(node);
}
}
}
PictogramElement srcState = null;
PictogramElement destState = null;
if (!firstNode) {
CreateFlowFeature createFeature = new CreateFlowFeature(getFeatureProvider());
CreateConnectionContext connectContext = new CreateConnectionContext();
srcState = context.getPictogramElements()[0];
destState = getFeatureProvider().getPictogramElementForBusinessObject(node);
if (srcState == destState) {
Activator.getLogger().warning("Should not be the same element for different nodes: " + context.getPictogramElements()[0].getLink().getBusinessObjects().get(0) + " and " + node);
}
connectContext.setSourcePictogramElement(srcState);
connectContext.setTargetPictogramElement(destState);
Anchor srcAnchor = DiagramUtils.getAnchor(srcState);
Anchor destAnchor = DiagramUtils.getAnchor(destState);
if (destAnchor != null) {
connectContext.setSourceAnchor(srcAnchor);
connectContext.setTargetAnchor(destAnchor);
if (createFeature.canCreate(connectContext)) {
createFeature.execute(connectContext);
}
}
}
final PictogramElement dState = destState;
final PictogramElement nNode = newNode;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
RiderDesignEditor ed = Activator.getDiagramEditor();