private void addReferenceToDiagram( IFeatureProvider fp, Diagram diagram, String sourceClass, String targetClass) { ICreateConnectionFeature[] ccfs = fp.getCreateConnectionFeatures(); if (ccfs != null) { Shape sourceShape = findShapeForEClass(diagram, sourceClass); Anchor sourceAnchor = getPeService().getChopboxAnchor(sourceShape); Shape targetShape = findShapeForEClass(diagram, targetClass); Anchor targetAnchor = getPeService().getChopboxAnchor(targetShape); CreateConnectionContext ccc = new CreateConnectionContext(); ccc.setSourceAnchor(sourceAnchor); ccc.setTargetAnchor(targetAnchor); // question instantiate create feature directly? for (ICreateConnectionFeature ccf : ccfs) { if (ccf.canCreate(ccc)) { ccf.execute(ccc); break; } } } }
protected Connection createNewConnection( ModelHandler mh, ContainerShape oldShape, ContainerShape newShape) { Anchor sourceAnchor = LayoutUtil.getCenterAnchor(oldShape); Anchor targetAnchor = LayoutUtil.getCenterAnchor(newShape); // TODO: Use create features to create connection CreateConnectionContext createConnectionContext = new CreateConnectionContext(); createConnectionContext.setSourcePictogramElement(oldShape); createConnectionContext.setTargetPictogramElement(newShape); createConnectionContext.setSourceAnchor(sourceAnchor); createConnectionContext.setTargetAnchor(targetAnchor); FlowNode oldObject = BusinessObjectUtil.getFirstElementOfType(oldShape, FlowNode.class); FlowNode newObject = BusinessObjectUtil.getFirstElementOfType(newShape, FlowNode.class); AddConnectionContext acc = new AddConnectionContext(sourceAnchor, targetAnchor); SequenceFlow flow = mh.createSequenceFlow(oldObject, newObject); acc.setNewObject(flow); Connection connection = (Connection) getFeatureProvider().addIfPossible(acc); return connection; }