/** * Delete the given connection as well its net.sf.orcc.df.Connection linked (its business object) * * @param fp The current FeatureProvider instance * @param c A connection pictogram (FreeFormConnection or any other class derived from Connection) */ public static boolean deleteConnection( final IFeatureProvider fp, final org.eclipse.graphiti.mm.pictograms.Connection c) { // Initialize the delete context final DeleteContext delCtxt = new DeleteContext(c); delCtxt.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 1)); // Silently execute deletion (user will not be asked before deletion) final IDeleteFeature delFeature = fp.getDeleteFeature(delCtxt); if (delFeature.canDelete(delCtxt)) { delFeature.delete(delCtxt); return true; } return false; }
private void updateConnectionIfNeeded(DataAssociation association, ItemAwareElement value) { DiagramEditor diagramEditor = ModelUtil.getDiagramEditor(association); if (diagramEditor == null) return; boolean hasDoneChanges = false; Diagram diagram = diagramEditor.getDiagramTypeProvider().getDiagram(); IFeatureProvider fp = diagramEditor.getDiagramTypeProvider().getFeatureProvider(); Shape taskShape = null; EObject container = association.eContainer(); if (container instanceof Activity || container instanceof Event) { for (PictogramElement pe : Graphiti.getLinkService().getPictogramElements(diagram, container)) { if (pe instanceof Shape && BusinessObjectUtil.getFirstElementOfType(pe, BPMNShape.class) != null) { taskShape = (Shape) pe; break; } } } Shape dataShape = null; if (value instanceof DataObject || value instanceof DataObjectReference || value instanceof DataStore || value instanceof DataStoreReference || value instanceof DataInput || value instanceof DataOutput) { List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, (EObject) value); for (PictogramElement p : pes) { if (BusinessObjectUtil.getFirstElementOfType(p, BPMNShape.class) != null) { dataShape = (Shape) p; break; } } } Connection connection = DataAssociationFeatureContainer.findDataAssociation(diagram, association); if (connection != null) { // There's an existing DataAssociation connection which needs to // either be reconnected or deleted, depending on what the combobox // selection is. if (dataShape != null) { // need to reconnect the DataAssociation ReconnectionContext rc = null; if (association instanceof DataInputAssociation) { Point p = GraphicsUtil.createPoint(connection.getStart()); Anchor a = AnchorUtil.createAnchor((AnchorContainer) dataShape, p); rc = new ReconnectionContext(connection, connection.getStart(), a, null); rc.setTargetPictogramElement(dataShape); rc.setTargetLocation(Graphiti.getPeService().getLocationRelativeToDiagram(a)); rc.setReconnectType(ReconnectionContext.RECONNECT_SOURCE); } else { Point p = GraphicsUtil.createPoint(connection.getEnd()); Anchor a = AnchorUtil.createAnchor(dataShape, p); rc = new ReconnectionContext(connection, a, connection.getEnd(), null); rc.setTargetPictogramElement(dataShape); rc.setTargetLocation(Graphiti.getPeService().getLocationRelativeToDiagram(a)); rc.setReconnectType(ReconnectionContext.RECONNECT_TARGET); } IReconnectionFeature rf = fp.getReconnectionFeature(rc); if (rf.canReconnect(rc)) { rf.reconnect(rc); hasDoneChanges = true; } } else { // need to delete the DataAssociation connection DeleteContext dc = new DeleteContext(connection); connection.getLink().getBusinessObjects().remove(0); IDeleteFeature df = fp.getDeleteFeature(dc); df.delete(dc); } } else if (dataShape != null) { // There is no existing DataAssociation connection, but the newly selected source or target // is some kind of data object shape, so we need to create a connection between the Activity // (or Throw/Catch Event) that owns the DataAssociation, and the new data object shape. Point p = GraphicsUtil.createPoint((AnchorContainer) dataShape); Anchor ownerAnchor = AnchorUtil.createAnchor(taskShape, p); p = GraphicsUtil.createPoint(taskShape); Anchor peAnchor = AnchorUtil.createAnchor((AnchorContainer) dataShape, p); AddConnectionContext ac = null; if (association instanceof DataOutputAssociation) { ac = new AddConnectionContext(ownerAnchor, peAnchor); } else { ac = new AddConnectionContext(peAnchor, ownerAnchor); } ac.putProperty(GraphitiConstants.BUSINESS_OBJECT, association); ac.setNewObject(association); IAddFeature af = fp.getAddFeature(ac); if (af.canAdd(ac)) { PictogramElement pe = af.add(ac); if (pe instanceof Connection) { connection = (Connection) pe; hasDoneChanges = true; } } } if (hasDoneChanges) { FeatureSupport.updateConnection( diagramEditor.getDiagramTypeProvider().getFeatureProvider(), connection); } }