@Override public Object getAdapter(Class key) { if (PictogramElement.class == key) { EObject bpmnModel = (EObject) super.getModel(); if (bpmnModel instanceof BPMNDiagram) { BPMNDiagram bpmnDiagram = (BPMNDiagram) bpmnModel; bpmnModel = bpmnDiagram.getPlane().getBpmnElement(); } if (diagramEditPart != null) { // the model is actually a BPMN element - convert this // to a PictogramElement for the SelectionSynchronizer for (Diagram diagram : diagramEditPart.getAllDiagrams()) { if (diagram != null) { List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, bpmnModel); for (PictogramElement pe : pes) { if (pe instanceof ContainerShape) return pe; if (pe instanceof FreeFormConnection) return pe; } } } } } return super.getAdapter(key); }
/* (non-Javadoc) * @see org.eclipse.graphiti.features.IFeature#canExecute(org.eclipse.graphiti.features.context.IContext) */ @Override public boolean canExecute(IContext context) { // TODO: clean this mess up: use {@code getWorkItemEditor()) to check if the selected task // has a WID and if the WID defines a customEditor BPMN2Editor editor = (BPMN2Editor) getFeatureProvider() .getDiagramTypeProvider() .getDiagramBehavior() .getDiagramContainer(); IBpmn2RuntimeExtension rte = editor.getTargetRuntime().getRuntimeExtension(); if (rte instanceof JBPM5RuntimeExtension && context instanceof ICustomContext) { PictogramElement[] pes = ((ICustomContext) context).getPictogramElements(); if (pes.length == 1) { Object o = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pes[0]); if (o instanceof Task) { Task task = (Task) o; List<EStructuralFeature> features = ModelDecorator.getAnyAttributes(task); for (EStructuralFeature f : features) { if ("taskName".equals(f.getName())) { // $NON-NLS-1$ // make sure the Work Item Definition exists String taskName = (String) task.eGet(f); return ((JBPM5RuntimeExtension) rte).getWorkItemDefinition(taskName) != null; } } } } } return false; }
@Override protected Task createFlowElement(ICreateContext context) { EObject target = Graphiti.getLinkService() .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer()); return (Task) customTaskDescriptor.createObject(target); }
/** * Initialize a ready to use AddConnectionContext object from a network connection. This method * does not add the given connection to the network. * * <p>The returned IAddConnectionContext is ready to use. The business object has been set to the * given connection and the target container has been set to the given diagram. * * @param fp The IFeatureProviderWithPatterns instance * @param diagram The diagram where the connection will be added * @param connection The connection * @return */ public static IAddConnectionContext getAddConnectionContext( final IFeatureProviderWithPatterns fp, final Diagram diagram, final Connection connection) { final ILinkService linkServ = Graphiti.getLinkService(); // retrieve the source and target PictogramElements final List<PictogramElement> sourcesPE = linkServ.getPictogramElements(diagram, connection.getSource()); if (sourcesPE == null || sourcesPE.isEmpty()) { OrccLogger.warnln( "[getAddConnectionContext] Unable to " + "retrieve the PictogramElement corresponding to the source " + connection.getSource() + "."); return null; } final List<PictogramElement> targetsPE = linkServ.getPictogramElements(diagram, connection.getTarget()); if (targetsPE == null || targetsPE.isEmpty()) { OrccLogger.warnln( "[getAddConnectionContext] Unable to " + "retrieve the PictogramElement corresponding to the target " + connection.getTarget() + "."); return null; } // source/target PictogramElement final PictogramElement sourcePe = sourcesPE.get(0); final PictogramElement targetPe = targetsPE.get(0); final Anchor sourceAnchor, targetAnchor; if (PropsUtil.isInputPort(sourcePe)) { // Connection from a network port final InputNetworkPortPattern spattern = (InputNetworkPortPattern) fp.getPatternForPictogramElement(sourcePe); sourceAnchor = spattern.getAnchor((AnchorContainer) sourcePe); } else { // Connection from an instance port final InstancePattern spattern = (InstancePattern) fp.getPatternForPictogramElement(sourcePe); sourceAnchor = spattern.getAnchorForPort(sourcePe, connection.getSourcePort()); } if (PropsUtil.isOutputPort(targetPe)) { // Connection to a network port final OutputNetworkPortPattern tpattern = (OutputNetworkPortPattern) fp.getPatternForPictogramElement(targetPe); targetAnchor = tpattern.getAnchor((AnchorContainer) targetPe); } else { // Connection to an instance port final InstancePattern tpattern = (InstancePattern) fp.getPatternForPictogramElement(targetPe); targetAnchor = tpattern.getAnchorForPort(targetPe, connection.getTargetPort()); } final AddConnectionContext result = new AddConnectionContext(sourceAnchor, targetAnchor); result.setTargetContainer(diagram); result.setNewObject(connection); return result; }
@Override protected boolean accept(PictogramElement pictogramElement) { EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pictogramElement); if (bo instanceof PlatformService) { return true; } return false; }
@Override public boolean canCreate(ICreateContext context) { EObject bo = Graphiti.getLinkService() .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer()); // System.out.println("CreatePortFeature.canCreate: modelObject=" + modelObject); return (actorEditModel != null) && actorEditModel.isEntity(bo, EntityViewModel.EntityKind.ACTOR); }
/** * Get the {@link FreeFormConnection} associated to an edge of the {@link Diagram}. The Edge can * either be a {@link Fifo} or a {@link Dependency}. * * @param diagram the {@link Diagram} containing the edge. * @param edge the {@link Fifo} or the {@link Dependency} whose {@link FreeFormConnection} is * searched. * @return the searched {@link FreeFormConnection}. * @throws RuntimeException if not {@link FreeFormConnection} could be found, a {@link * RuntimeException} is thrown */ public static FreeFormConnection getFreeFormConnectionOfEdge(Diagram diagram, EObject edge) throws RuntimeException { List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, edge); FreeFormConnection ffc = null; for (PictogramElement pe : pes) { if (Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe) == edge && pe instanceof FreeFormConnection) { ffc = (FreeFormConnection) pe; } } // if PE is still null.. something is deeply wrong with this // graph ! if (ffc == null) { throw new RuntimeException( "Pictogram element associated Edge " + edge + " could not be found."); } return ffc; }
/** * Retrieve the {@link PictogramElement} of the {@link Diagram} corresponding to the given {@link * Fifo}. * * @param diagram the {@link Diagram} containing the {@link PictogramElement} * @param fifo the {@link Fifo} whose {@link PictogramElement} is searched. * @return the {@link PictogramElement} of the {@link Fifo}. * @throws RuntimeException if no {@link PictogramElement} could be found in this {@link Diagram} * for this {@link Fifo}. */ public static ContainerShape getDelayPE(Diagram diagram, Fifo fifo) throws RuntimeException { // Get all delays with identical attributes (may not be the // right delay is several delays have the same properties.) List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, fifo.getDelay()); PictogramElement pe = null; for (PictogramElement p : pes) { if (p instanceof ContainerShape && Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(p) == fifo.getDelay()) { pe = p; } } // if PE is still null.. something is deeply wrong with this // graph ! if (pe == null) { throw new RuntimeException( "Pictogram element associated to delay of Fifo " + fifo.getId() + " could not be found."); } return (ContainerShape) pe; }
@Override public void refresh() { PictogramElement pe = getSelectedPictogramElement(); if (pe != null) { Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); _interface = null; // the filter assured, that it is a Service or Reference if (bo == null) { _composite.showPage(_blank); _composite.redraw(); return; } if (bo instanceof Contract) { Contract contract = (Contract) bo; _interface = contract.getInterface(); } if (_interface != null) { if (_modelComposites.get(_interface) == null) { TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); IInterfaceComposite composite = (IInterfaceComposite) InterfaceCompositeAdapter.adaptModelToComposite(_interface); if (composite != null) { ((AbstractSwitchyardComposite) composite).createContents(_composite, SWT.NONE); factory.adapt(((AbstractSwitchyardComposite) composite).getPanel()); _modelComposites.put(_interface, composite); } } IInterfaceComposite composite = (IInterfaceComposite) _modelComposites.get(_interface); if (composite != null) { composite.setInterface(_interface); _composite.showPage(((AbstractSwitchyardComposite) composite).getPanel()); Composite parent = _composite; // this is a hack to get it to refresh properly while (parent != null) { parent.layout(true, true); parent = parent.getParent(); } } else { _composite.getParent().layout(); _composite.showPage(_blank); _composite.layout(true, true); } } else { _composite.showPage(_blank); _composite.getParent().layout(); _composite.layout(true, true); } } }
public static boolean isChoreographyParticipantBand(PictogramElement element) { if (element != null) { EObject container = element.eContainer(); if (container instanceof PictogramElement) { PictogramElement containerElem = (PictogramElement) container; Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(containerElem); if (bo instanceof ChoreographyActivity) { return true; } } } return false; }
public EObject[] create(ICreateContext context) { EObject parent = Graphiti.getLinkService() .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer()); ActorViewModel.PortKind ioKind = getIOPortKind(context); String name = actorEditModel.getUniqueName(parent, ioKind.name().toLowerCase()); EObject newPort = actorEditModel.createPort(ioKind, name, parent); if (multi != null) { actorEditModel.setMultiPort(newPort, multi.booleanValue()); } addGraphicalRepresentation(context, newPort); return new EObject[] {newPort}; }
/** {@inheritDoc} */ @Override public void refresh() { nameWidget.removeModifyListener(nameListener); final PictogramElement pe = getSelectedPictogramElement(); if (pe != null) { final EObject bo = (EObject) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); // the filter assured, that it is a node if (bo == null) return; bc = (node) bo; String value = ""; value = bc.getName(); nameWidget.setText(value == null ? "" : value); nameWidget.addModifyListener(nameListener); } }
@Override public void refresh() { super.refresh(); PictogramElement pe = getSelectedPictogramElement(); if (pe != null) { EObject port = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); boolean canEdit = actorViewModel.isPort(port, null) && actorViewModel instanceof ActorEditModel; inputButton.setEnabled(canEdit); outputButton.setEnabled(canEdit); multiportButton.setEnabled(canEdit); inputButton.setSelection(canEdit && actorViewModel.isPort(port, PortKind.INPUT)); outputButton.setSelection(canEdit && actorViewModel.isPort(port, PortKind.OUTPUT)); multiportButton.setSelection(canEdit); } }
/** * Creates a new instance based on the given edit part. * * @param originEditPart Origin edit part */ public ConnectionEditPartAdapter(EditPart originEditPart) { this(new ViewImpl() {}); // Origin references fOriginEditPart = originEditPart; fOriginEditPartModel = (EObject) originEditPart.getModel(); fOriginConnectionEditPart = (org.eclipse.graphiti.ui.internal.parts.ConnectionEditPart) originEditPart; // Underlying references PictogramElement connectionModel = (PictogramElement) fOriginEditPartModel; fUnderlyingModelObject = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(connectionModel); fUnderlyingSequenceFlow = (SequenceFlow) fUnderlyingModelObject; getPrimaryView().setElement(fUnderlyingModelObject); }
protected Shape findShapeForEClass(Diagram diagram, String className) { Object[] allShapes = getPeService().getAllContainedShapes(diagram).toArray(); Shape shape = null; for (int i = 0; i < allShapes.length; i++) { shape = (Shape) allShapes[i]; if (shape instanceof ContainerShape) { Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape); if (bo instanceof EClass) { String boName = ((EClass) bo).getName(); if (boName.equals(className)) { return shape; } } } } return null; }
/** * Retrieve the {@link PictogramElement} of the {@link Diagram} corresponding to the given {@link * AbstractActor}. * * @param diagram the {@link Diagram} containing the {@link PictogramElement} * @param actor the {@link AbstractActor} whose {@link PictogramElement} is searched. * @return the {@link PictogramElement} of the {@link AbstractActor}. * @throws RuntimeException if no {@link PictogramElement} could be found in this {@link Diagram} * for this {@link AbstractActor}. */ public static PictogramElement getActorPE(Diagram diagram, AbstractActor actor) throws RuntimeException { // Get the PE List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, actor); PictogramElement actorPE = null; for (PictogramElement pe : pes) { if (pe instanceof ContainerShape) { actorPE = pe; break; } } if (actorPE == null) { throw new RuntimeException("No PE was found for actor :" + actor.getName()); } return actorPE; }
protected PictogramElement findPictogramElement(String id) { PictogramElement pictogramElement = null; if (id != null) { BaseElement be = bpmn2Editor.getModelHandler().findElement(id); List<PictogramElement> pes = Graphiti.getLinkService() .getPictogramElements(bpmn2Editor.getDiagramTypeProvider().getDiagram(), be); for (PictogramElement pe : pes) { if (pe instanceof ContainerShape) { pictogramElement = pe; } else if (pe instanceof FreeFormConnection) { pictogramElement = pe; } } } return pictogramElement; }
public static void updateCategoryValues(IFeatureProvider fp, PictogramElement pe) { Resource resource = ObjectPropertyProvider.getResource(pe); if (Bpmn2Preferences.getInstance(resource).getPropagateGroupCategories()) { // only do this if User Preference is enabled: assign the Group's CategoryValue // to the FlowElement represented by the given PictogramElement Diagram diagram = fp.getDiagramTypeProvider().getDiagram(); FlowElement flowElement = BusinessObjectUtil.getFirstElementOfType(pe, FlowElement.class); if (flowElement == null) return; // remove any previous Category Values from this FlowElement flowElement.getCategoryValueRef().clear(); // find all Groups in this Resource and check if it contains the given FlowElement if (pe instanceof ContainerShape) { for (Group group : ModelUtil.getAllObjectsOfType(resource, Group.class)) { CategoryValue cv = group.getCategoryValueRef(); if (cv == null) continue; for (PictogramElement groupShape : Graphiti.getLinkService().getPictogramElements(diagram, group)) { if (groupShape instanceof ContainerShape) { for (ContainerShape flowElementShape : FeatureSupport.findGroupedShapes((ContainerShape) groupShape)) { FlowElement fe = BusinessObjectUtil.getFirstElementOfType(flowElementShape, FlowElement.class); if (fe == flowElement) { fe.getCategoryValueRef().add(cv); break; } } } } } } else if (pe instanceof Connection && flowElement instanceof SequenceFlow) { SequenceFlow sf = (SequenceFlow) flowElement; FlowNode source = sf.getSourceRef(); FlowNode target = sf.getTargetRef(); sf.getCategoryValueRef().clear(); sf.getCategoryValueRef().addAll(source.getCategoryValueRef()); sf.getCategoryValueRef().addAll(target.getCategoryValueRef()); } } }
// TODO: move this to the adapter registry public IFeature getCreateFeatureForPictogramElement(PictogramElement pe) { if (pe != null) { String id = Graphiti.getPeService().getPropertyValue(pe, ICustomTaskFeature.CUSTOM_TASK_ID); if (id != null) { for (FeatureContainer container : containers) { if (container instanceof CustomTaskFeatureContainer) { CustomTaskFeatureContainer ctf = (CustomTaskFeatureContainer) container; if (id.equals(ctf.getId())) { return ctf.getCreateFeature(this); } } } } EObject be = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); return getCreateFeatureForBusinessObject(be); } return null; }
@Override public void refresh() { _implementation = null; final PictogramElement pe = getSelectedPictogramElement(); if (pe != null) { final Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); _implementation = (BPELImplementation) ((Component) bo).getImplementation(); _project = PlatformResourceAdapterFactory.getContainingProject(_implementation); } _updating = true; try { if (_implementation == null || _implementation.getProcess() == null) { _bpelFileText.setText(""); } else { _bpelFileText.setText(_implementation.getProcess().toString()); } } finally { _updating = false; } }
public static BPMNShape createDIShape( Shape shape, BaseElement elem, int x, int y, int w, int h, IFeatureProvider fp, Diagram diagram) { EList<EObject> businessObjects = Graphiti.getLinkService().getLinkForPictogramElement(diagram).getBusinessObjects(); BPMNShape bpmnShape = null; for (EObject eObject : businessObjects) { if (eObject instanceof BPMNDiagram) { BPMNDiagram bpmnDiagram = (BPMNDiagram) eObject; bpmnShape = BpmnDiFactory.eINSTANCE.createBPMNShape(); // bpmnShape.setId(EcoreUtil.generateUUID()); bpmnShape.setBpmnElement(elem); Bounds bounds = DcFactory.eINSTANCE.createBounds(); bounds.setX(x); bounds.setY(y); bounds.setWidth(w); bounds.setHeight(h); bpmnShape.setBounds(bounds); List<DiagramElement> elements = bpmnDiagram.getPlane().getPlaneElement(); elements.add(bpmnShape); ModelUtil.setID(shape); fp.link(shape, new Object[] {elem, bpmnShape}); break; } } return bpmnShape; }
/* (non-Javadoc) * @see org.eclipse.graphiti.features.IFeature#execute(org.eclipse.graphiti.features.context.IContext) */ @Override public void execute(IContext context) { // TODO: clean this mess up: use {@code getWorkItemEditor()) to check if the selected task // has a WID and if the WID defines a customEditor BPMN2Editor editor = (BPMN2Editor) getFeatureProvider() .getDiagramTypeProvider() .getDiagramBehavior() .getDiagramContainer(); PictogramElement pe = ((ICustomContext) context).getPictogramElements()[0]; final Task task = (Task) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); String taskName = ""; // $NON-NLS-1$ List<EStructuralFeature> features = ModelDecorator.getAnyAttributes(task); for (EStructuralFeature f : features) { if ("taskName".equals(f.getName())) { // $NON-NLS-1$ taskName = (String) task.eGet(f); break; } } IBpmn2RuntimeExtension rte = editor.getTargetRuntime().getRuntimeExtension(); WorkItemDefinition workItemDefinition = ((JBPM5RuntimeExtension) rte).getWorkItemDefinition(taskName); WorkDefinitionImpl wd = new WorkDefinitionImpl(); for (String name : workItemDefinition.getParameters().keySet()) { String type = workItemDefinition.getParameters().get(name); DataTypeFactory factory = DataTypeRegistry.getFactory(type); wd.addParameter(new ParameterDefinitionImpl(name, factory.createDataType())); } WorkImpl w = new WorkImpl(); w.setName(taskName); w.setParameterDefinitions(wd.getParameters()); for (DataInputAssociation dia : task.getDataInputAssociations()) { DataInput dataInput = (DataInput) dia.getTargetRef(); if (dataInput != null) { String name = dataInput.getName(); ItemDefinition itemDefinition = dataInput.getItemSubjectRef(); if (itemDefinition != null) { Object structureRef = itemDefinition.getStructureRef(); if (ModelUtil.isStringWrapper(structureRef)) { ParameterDefinition parameterDefinition = w.getParameterDefinition(name); try { Object value = parameterDefinition .getType() .readValue(ModelUtil.getStringWrapperTextValue(structureRef)); w.setParameter(name, value); } catch (Exception e) { } } } } } /* * Load the class defined in the WID's "eclipse:customEditor" field. * This means that the containing Project must be a JavaProject, and * the class must exist and must implement the WorkEditor interface. try { Resource res = ExtendedPropertiesAdapter.getResource(task); URI uri = res.getURI(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(uri.segment(1)); JavaProjectClassLoader cl = new JavaProjectClassLoader(project); Class c = cl.loadClass("org.bpmn2.java.Calculator"); Object o = c.newInstance(); String s = o.toString(); System.out.println(s); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } */ WorkEditor dialog = getWorkItemEditor(task); dialog.setWorkDefinition(wd); dialog.setWork(w); dialog.show(); hasChanges = dialog.getWork() != w; if (hasChanges) { w = (WorkImpl) dialog.getWork(); for (DataInputAssociation dia : task.getDataInputAssociations()) { DataInput dataInput = (DataInput) dia.getTargetRef(); if (dataInput != null) { String name = dataInput.getName(); ItemDefinition itemDefinition = dataInput.getItemSubjectRef(); // this always comes back as a String from the SampleCustomEditor dialog String value = (String) w.getParameter(name); if (value != null && !value.isEmpty()) { EObject structureRef = ModelUtil.createStringWrapper(value); if (itemDefinition == null) { itemDefinition = Bpmn2ModelerFactory.createObject(task.eResource(), ItemDefinition.class); ModelUtil.getDefinitions(task).getRootElements().add(itemDefinition); ModelUtil.setID(itemDefinition); } itemDefinition.setItemKind(ItemKind.INFORMATION); itemDefinition.setStructureRef(structureRef); dataInput.setItemSubjectRef(itemDefinition); } else if (itemDefinition != null) { // TODO: remove Item Definition if it is on longer referenced anywhere // ModelUtil.getDefinitions(task).getRootElements().remove(itemDefinition); dataInput.setItemSubjectRef(null); } } } } }
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); } }
private Link createLink(StandardNode source, StandardNode target) { if (GraphBTUtil.isAncestor(target, source)) { return null; } if (target.isLeaf()) { return null; } Edge edge = source.getEdge(); if (edge == null) { edge = GraphBTUtil.getBEFactory().createEdge(); edge.setComposition(Composition.SEQUENTIAL); source.setEdge(edge); edge.setContainer(source); } else { for (int i = 0; i < edge.getChildNode().size(); i++) { if (edge.getChildNode().get(i).getTarget() == (target)) { return null; } } if (edge.getChildNode().size() == 1) { HashMap<Integer, String> map = new HashMap<Integer, String>(); WizardDialog wizardDialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new ManageBranchWizardGraphBtFeature(map, getDiagram())); if (wizardDialog.open() != Window.OK) { return null; } edge.setBranch(Branch.get(map.get(1))); StandardNode sn = (StandardNode) edge.getChildNode().get(0).getTarget(); ContainerShape cs = null; if (sn == null) { return null; } for (PictogramElement pe : Graphiti.getLinkService().getPictogramElements(getDiagram(), sn.getParent())) { if (pe instanceof ContainerShape) { cs = (ContainerShape) pe; } } // ContainerShape cs = (ContainerShape) pe; Iterator<Shape> s = cs.getChildren().iterator(); while (s.hasNext()) { Shape n = s.next(); Object bo = Graphiti.getLinkService() .getBusinessObjectForLinkedPictogramElement((PictogramElement) n); if (bo instanceof AlternativeClass) { updatePictogramElement(n); } } } } Link l = GraphBTUtil.getBEFactory().createLink(); l.setSource(source); l.setTarget(target); edge.getChildNode().add(l); target.setParent(source); target.setLeaf(true); return l; }