public static void updateDIEdge(Diagram diagram, Connection connection, Class clazz) { try { ModelHandler modelHandler = ModelHandlerLocator.getModelHandler( connection.getLink().getBusinessObjects().get(0).eResource()); EObject be = BusinessObjectUtil.getFirstElementOfType(connection, clazz); BPMNEdge edge = (BPMNEdge) modelHandler.findDIElement(diagram, (BaseElement) be); Point point = DcFactory.eINSTANCE.createPoint(); List<Point> waypoint = edge.getWaypoint(); waypoint.clear(); GraphicsAlgorithm graphicsAlgorithm = connection.getStart().getGraphicsAlgorithm(); // FIXME connections must create anchors!!! if (graphicsAlgorithm != null) { point.setX(graphicsAlgorithm.getX()); point.setY(graphicsAlgorithm.getY()); } else { point.setX(connection.getStart().getParent().getGraphicsAlgorithm().getX()); point.setY(connection.getStart().getParent().getGraphicsAlgorithm().getY()); } waypoint.add(point); if (connection instanceof FreeFormConnectionImpl) { FreeFormConnectionImpl freeForm = (FreeFormConnectionImpl) connection; EList<org.eclipse.graphiti.mm.algorithms.styles.Point> bendpoints = freeForm.getBendpoints(); for (org.eclipse.graphiti.mm.algorithms.styles.Point bp : bendpoints) { addBendPoint(freeForm, point); } } point = DcFactory.eINSTANCE.createPoint(); graphicsAlgorithm = connection.getEnd().getGraphicsAlgorithm(); if (graphicsAlgorithm != null) { point.setX(graphicsAlgorithm.getX()); point.setY(graphicsAlgorithm.getY()); } else { point.setX(connection.getEnd().getParent().getGraphicsAlgorithm().getX()); point.setY(connection.getEnd().getParent().getGraphicsAlgorithm().getY()); } waypoint.add(point); } catch (IOException e) { Activator.logError(e); } }
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); } }