public static boolean setHidden(PictogramElement pe, boolean hidden) { if (hidden) { pe.eSetDeliver(false); Graphiti.getPeService() .setPropertyValue(pe, GraphitiConstants.IS_HIDDEN, Boolean.TRUE.toString()); pe.setVisible(false); pe.eSetDeliver(true); } else { pe.eSetDeliver(false); Graphiti.getPeService().removeProperty(pe, GraphitiConstants.IS_HIDDEN); pe.setVisible(true); pe.eSetDeliver(true); } return false; }
@Override public PictogramElement add(IAddContext context) { PictogramElement pe = super.add(context); // make sure everyone knows that this PE is a custom task Graphiti.getPeService().setPropertyValue(pe, CUSTOM_TASK_ID, getId()); return pe; }
public static void setHorizontal(ContainerShape container, boolean isHorizontal) { Graphiti.getPeService() .setPropertyValue( container, GraphitiConstants.IS_HORIZONTAL_PROPERTY, Boolean.toString(isHorizontal)); BPMNShape bs = BusinessObjectUtil.getFirstElementOfType(container, BPMNShape.class); if (bs != null) bs.setIsHorizontal(isHorizontal); }
/** * Returns the modelObject ID string from the given Graphiti context. * * @param context * @return - ID string for this modelObject. */ public static String getId(IContext context) { Object id = null; /** * IAddContext can also mean that a file is dragged, therefore we have to check if we are really * dragging a customTask */ if (context instanceof IAddContext && ((IAddContext) context).getNewObject() instanceof EObject) { EObject object = (EObject) ((IAddContext) context).getNewObject(); TargetRuntime rt = TargetRuntime.getCurrentRuntime(); for (CustomTaskDescriptor ct : rt.getCustomTasks()) { id = ct.getFeatureContainer().getId(object); if (id != null) { context.putProperty(CUSTOM_TASK_ID, id); return (String) id; } } } if (context instanceof IPictogramElementContext) { PictogramElement pe = ((IPictogramElementContext) context).getPictogramElement(); id = Graphiti.getPeService().getPropertyValue(pe, CUSTOM_TASK_ID); } else { id = context.getProperty(CUSTOM_TASK_ID); } return (String) id; }
@Override protected ContainerShape createPictogramElement(IAddContext context, IRectangle bounds) { T addedGateway = getBusinessObject(context); IGaService gaService = Graphiti.getGaService(); IPeService peService = Graphiti.getPeService(); int x = bounds.getX(); int y = bounds.getY(); int width = bounds.getWidth(); int height = bounds.getHeight(); // Create a container for the gateway-symbol final ContainerShape newShape = peService.createContainerShape(context.getTargetContainer(), true); final Rectangle gatewayRect = gaService.createInvisibleRectangle(newShape); gaService.setLocationAndSize(gatewayRect, x, y, width, height); Shape gatewayShape = peService.createShape(newShape, false); Polygon gateway = GraphicsUtil.createGateway(gatewayShape, width, height); StyleUtil.applyStyle(gateway, addedGateway); gaService.setLocationAndSize(gateway, 0, 0, width, height); return newShape; }
@Override public PictogramElement add(IAddContext context) { IPeService peService = Graphiti.getPeService(); IGaService gaService = Graphiti.getGaService(); BaseElement element = (BaseElement) context.getNewObject(); IAddConnectionContext addConContext = (IAddConnectionContext) context; Connection connection = peService.createFreeFormConnection(getDiagram()); Object importProp = context.getProperty(DIImport.IMPORT_PROPERTY); if (importProp != null && (Boolean) importProp) { connection.setStart(addConContext.getSourceAnchor()); connection.setEnd(addConContext.getTargetAnchor()); } else { ContainerShape sourceContainer = (ContainerShape) addConContext.getSourceAnchor().eContainer(); ContainerShape targetContainer = (ContainerShape) addConContext.getTargetAnchor().eContainer(); Tuple<FixPointAnchor, FixPointAnchor> anchors = AnchorUtil.getSourceAndTargetBoundaryAnchors( sourceContainer, targetContainer, connection); connection.setStart(anchors.getFirst()); connection.setEnd(anchors.getSecond()); } if (ModelUtil.hasName(element)) { ConnectionDecorator labelDecorator = Graphiti.getPeService().createConnectionDecorator(connection, true, 0.5, true); Text text = gaService.createText(labelDecorator, ModelUtil.getName(element)); peService.setPropertyValue( labelDecorator, UpdateBaseElementNameFeature.TEXT_ELEMENT, Boolean.toString(true)); text.setStyle(StyleUtil.getStyleForText(getDiagram())); } Polyline connectionLine = gaService.createPolyline(connection); connectionLine.setForeground(manageColor(StyleUtil.CLASS_FOREGROUND)); decorateConnectionLine(connectionLine); createDIEdge(connection, element); createConnectionDecorators(connection); hook(addConContext, connection, element); return connection; }
public static GraphicsAlgorithm[] getClickArea(PictogramElement element) { Iterator<PictogramElement> iterator = Graphiti.getPeService().getPictogramElementChildren(element).iterator(); GraphicsAlgorithm[] algorithms = new GraphicsAlgorithm[2]; algorithms[0] = iterator.next().getGraphicsAlgorithm(); algorithms[1] = iterator.next().getGraphicsAlgorithm(); return algorithms; }
/** * If the given AnchorContainer has graphiti connections from / to itself, this method delete all * these connections as well the business objects (net.sf.orcc.df.Connection) linked * * @param fp The current FeatureProvider instance * @param ac An anchor container, typically an Instance or a NetworkPort shape */ public static void deleteConnections(final IFeatureProvider fp, final AnchorContainer ac) { // Make a copy of all connections, because we will delete them entirely final List<org.eclipse.graphiti.mm.pictograms.Connection> connections = Graphiti.getPeService().getAllConnections(ac); for (final org.eclipse.graphiti.mm.pictograms.Connection connection : connections) { deleteConnection(fp, connection); } }
/** * Set this modelObject's ID in the given Graphiti context. * * @param context - if this is a IPictogramElementContext, set the property in the contained * PictogramElement's list of properties; otherwise set the Context's property * @param id - ID of this Custom Task */ public static void setId(IContext context, String id) { if (context instanceof IPictogramElementContext) { PictogramElement pe = ((IPictogramElementContext) context).getPictogramElement(); Graphiti.getPeService().setPropertyValue(pe, CUSTOM_TASK_ID, id); } else { context.putProperty(CUSTOM_TASK_ID, id); } }
@Override protected void hook( Activity activity, ContainerShape container, IAddContext context, int width, int height) { super.hook(activity, container, context, width, height); Graphiti.getPeService().setPropertyValue(container, TRIGGERED_BY_EVENT, "false"); IPeService peService = Graphiti.getPeService(); IGaService gaService = Graphiti.getGaService(); Shape textShape = peService.createShape(container, false); Text text = gaService.createDefaultText(textShape, activity.getName()); gaService.setLocationAndSize(text, 5, 5, width - 10, 15); text.setStyle(StyleUtil.getStyleForText(getDiagram())); text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER); text.getFont().setBold(true); link(textShape, activity); }
@Override public IContextButtonPadData getContextButtonPad(IPictogramElementContext context) { IContextButtonPadData data = super.getContextButtonPad(context); PictogramElement pe = context.getPictogramElement(); // 1. set the generic context buttons // note, that we do not add 'remove' (just as an example) setGenericContextButtons(data, pe, CONTEXT_BUTTON_DELETE | CONTEXT_BUTTON_UPDATE); // 2. set the collapse button // simply use a dummy custom feature (senseless example) CustomContext cc = new CustomContext(new PictogramElement[] {pe}); ICustomFeature[] cf = getFeatureProvider().getCustomFeatures(cc); for (int i = 0; i < cf.length; i++) { ICustomFeature iCustomFeature = cf[i]; if (iCustomFeature instanceof AcoreCollapseDummyFeature) { IContextButtonEntry collapseButton = ContextEntryHelper.createCollapseContextButton(true, iCustomFeature, cc); data.setCollapseContextButton(collapseButton); break; } } // 3. add one domain specific context-button, which offers all // available connection-features as drag&drop features... // 3.a. create new CreateConnectionContext CreateConnectionContext ccc = new CreateConnectionContext(); ccc.setSourcePictogramElement(pe); Anchor anchor = null; if (pe instanceof Anchor) { anchor = (Anchor) pe; } else if (pe instanceof AnchorContainer) { // assume, that our shapes always have chopbox anchors anchor = Graphiti.getPeService().getChopboxAnchor((AnchorContainer) pe); } ccc.setSourceAnchor(anchor); // 3.b. create context button and add all applicable features ContextButtonEntry button = new ContextButtonEntry(null, context); button.setText("Create connection"); // $NON-NLS-1$ button.setIconId(AcoreImageProvider.IMG_EREFERENCE); ICreateConnectionFeature[] features = getFeatureProvider().getCreateConnectionFeatures(); for (ICreateConnectionFeature feature : features) { if (feature.isAvailable(ccc) && feature.canStartConnection(ccc)) { button.addDragAndDropFeature(feature); } } // 3.c. add context button, if it contains at least one feature if (button.getDragAndDropFeatures().size() > 0) { data.getDomainSpecificContextButtons().add(button); } return data; }
protected void addBusinessObjectToContainer(rootCon bo, PictogramElement pe) { final rootCon model = modelService.getModel(); final String alias = Graphiti.getPeService().getPropertyValue(pe, PROPERTY_ALIAS); if (bo.eClass() == Test3Package.Literals.NODE && alias == null) { model.getNodes().add((node) bo); } if (bo.eClass() == Test3Package.Literals.BRANCH && alias == null) { model.getChildren().add((branch) bo); } }
public static IDimension getExpandedSize(PictogramElement pe) { IDimension size = GraphicsUtil.calculateSize(pe); String property = Graphiti.getPeService().getPropertyValue(pe, GraphitiConstants.EXPANDED_SIZE); if (property != null) { int index = property.indexOf(','); int w = Integer.parseInt(property.substring(0, index)); int h = Integer.parseInt(property.substring(index + 1)); size.setWidth(w); size.setHeight(h); } return size; }
public static Shape getShape(ContainerShape container, String property, String expectedValue) { IPeService peService = Graphiti.getPeService(); Iterator<Shape> iterator = peService.getAllContainedShapes(container).iterator(); while (iterator.hasNext()) { Shape shape = iterator.next(); String value = peService.getPropertyValue(shape, property); if (value != null && value.equals(expectedValue)) { return shape; } } return null; }
@Override protected PictogramElement addGraphicalRepresentation(IAreaContext context, Object newObject) { // create a new AddContext and copy our ID into it. IAddContext addContext = new AddContext(context, newObject); setId(addContext, getId()); // create the PE and copy our ID into its properties. PictogramElement pe = getFeatureProvider().addIfPossible(addContext); Graphiti.getPeService().setPropertyValue(pe, CUSTOM_TASK_ID, id); return pe; }
public static List<ContainerShape> getParticipantBandContainerShapes( ContainerShape containerShape) { IPeService peService = Graphiti.getPeService(); List<ContainerShape> bandShapes = new ArrayList<ContainerShape>(); Collection<Shape> shapes = peService.getAllContainedShapes(containerShape); for (Shape s : shapes) { String property = peService.getPropertyValue(s, ChoreographyUtil.PARTICIPANT_BAND); if (new Boolean(property)) { bandShapes.add((ContainerShape) s); } } return bandShapes; }
// 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; }
public static boolean isHorizontal(ContainerShape container) { EObject parent = container.eContainer(); if (parent instanceof PictogramElement) { // participant bands are always "vertical" so that // the label is drawn horizontally by the LayoutFeature if (BusinessObjectUtil.getFirstElementOfType( (PictogramElement) parent, ChoreographyActivity.class) != null) return false; } String v = Graphiti.getPeService() .getPropertyValue(container, GraphitiConstants.IS_HORIZONTAL_PROPERTY); if (v == null) { BPMNShape bpmnShape = DIUtils.findBPMNShape(BusinessObjectUtil.getFirstBaseElement(container)); if (bpmnShape != null) return bpmnShape.isIsHorizontal(); return Bpmn2Preferences.getInstance(container).isHorizontalDefault(); } return Boolean.parseBoolean(v); }
@Override protected void handlePostSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getMultiPageEditor().getSite().getSelectionProvider(); // make sure the selected PictogramElement is still on the same Diagram as the // one currently being displayed - this event can happen after a page switch. Diagram currentDiagram = bpmn2Editor.getDiagramTypeProvider().getDiagram(); PictogramElement pe = BusinessObjectUtil.getPictogramElementForSelection(event.getSelection()); try { Diagram peDiagram = Graphiti.getPeService().getDiagramForPictogramElement(pe); if (currentDiagram != peDiagram) return; } catch (Exception e) { // if PictogramElements were deleted, there will be an NPE when searching for // the PEs parent diagram return; } if (parentProvider instanceof MultiPageSelectionProvider) { SelectionChangedEvent newEvent = getNewEvent(parentProvider, event); MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.firePostSelectionChanged(newEvent); } }
@Override public PictogramElement add(IAddContext context) { IPeService peService = Graphiti.getPeService(); BaseElement element = (BaseElement) context.getNewObject(); IAddConnectionContext addConContext = (IAddConnectionContext) context; Connection connection = peService.createFreeFormConnection(getDiagram()); Object importProp = context.getProperty(DIImport.IMPORT_PROPERTY); if (importProp != null && (Boolean) importProp) { connection.setStart(addConContext.getSourceAnchor()); connection.setEnd(addConContext.getTargetAnchor()); } else { ContainerShape sourceContainer = (ContainerShape) addConContext.getSourceAnchor().eContainer(); ContainerShape targetContainer = (ContainerShape) addConContext.getTargetAnchor().eContainer(); Tuple<FixPointAnchor, FixPointAnchor> anchors = AnchorUtil.getSourceAndTargetBoundaryAnchors( sourceContainer, targetContainer, connection); connection.setStart(anchors.getFirst()); connection.setEnd(anchors.getSecond()); } IGaService gaService = Graphiti.getGaService(); Polyline connectionLine = gaService.createPolyline(connection); connectionLine.setForeground(manageColor(StyleUtil.CLASS_FOREGROUND)); decorateConnectionLine(connectionLine); createDIEdge(connection, element); createConnectionDecorators(connection); hook(addConContext, connection, element); return connection; }
protected IPeService getPeService() { return Graphiti.getPeService(); }
/** * Abstract base class for Connection Routers. This is a container for common utility functions * related to routing. */ public abstract class AbstractConnectionRouter implements IConnectionRouter { /** The Constant peService. */ protected static final IPeService peService = Graphiti.getPeService(); /** The Constant gaService. */ protected static final IGaService gaService = Graphiti.getGaService(); /** The connection routing directions. */ public enum Direction { UP, DOWN, LEFT, RIGHT, NONE }; /** The Feature Provider. */ protected IFeatureProvider fp; /** * Instantiates a new abstract connection router. * * @param fp the Feature Provider */ public AbstractConnectionRouter(IFeatureProvider fp) { this.fp = fp; } /* (non-Javadoc) * @see org.eclipse.bpmn2.modeler.core.features.IConnectionRouter#route(org.eclipse.graphiti.mm.pictograms.Connection) */ @Override public abstract boolean route(Connection connection); /* (non-Javadoc) * @see org.eclipse.bpmn2.modeler.core.features.IConnectionRouter#dispose() */ @Override public abstract void dispose(); /** * Adds the routing info. * * @param connection the connection * @param info the info * @return the string */ public static String addRoutingInfo(Connection connection, String info) { Assert.isTrue(info != null && !info.isEmpty()); String newInfo = getRoutingInfo(connection); if (!newInfo.isEmpty()) newInfo += ","; // $NON-NLS-1$ newInfo += info; peService.setPropertyValue(connection, ROUTING_INFO, newInfo); return newInfo; } /** * Removes the routing info. * * @param connection the connection */ public static void removeRoutingInfo(Connection connection) { removeRoutingInfo(connection, getRoutingInfo(connection)); } /** * Removes the routing info. * * @param connection the connection * @param info the info * @return the string */ public static String removeRoutingInfo(Connection connection, String info) { String newInfo = null; if (info != null && !info.isEmpty()) { newInfo = getRoutingInfo(connection); if (newInfo != null && !newInfo.isEmpty()) { String a[] = newInfo.split(","); // $NON-NLS-1$ String b[] = info.split(","); // $NON-NLS-1$ for (int i = 0; i < a.length; ++i) { for (String sb : b) { if (a[i].startsWith(sb)) { a[i] = null; break; } } } newInfo = ""; // $NON-NLS-1$ for (int i = 0; i < a.length; ++i) { if (a[i] != null && !a[i].isEmpty()) { if (!newInfo.isEmpty()) newInfo += ","; // $NON-NLS-1$ newInfo += a[i]; } } } } if (newInfo == null || newInfo.isEmpty()) peService.removeProperty(connection, ROUTING_INFO); else peService.setPropertyValue(connection, ROUTING_INFO, newInfo); return newInfo; } /** * Gets the routing info. * * @param connection the connection * @return the routing info */ public static String getRoutingInfo(Connection connection) { String info = peService.getPropertyValue(connection, ROUTING_INFO); if (info == null || info.isEmpty()) return ""; // $NON-NLS-1$ return info; } /** * Sets the routing info. * * @param connection the connection * @param info the info * @param value the value * @return the string */ public static String setRoutingInfoInt(Connection connection, String info, int value) { removeRoutingInfo(connection, info + "="); // $NON-NLS-1$ return addRoutingInfo(connection, info + "=" + value); // $NON-NLS-1$ } /** * Gets the routing info. * * @param connection the connection * @param info the info * @return the routing info */ public static int getRoutingInfoInt(Connection connection, String info) { String oldInfo = getRoutingInfo(connection); String a[] = oldInfo.split(","); // $NON-NLS-1$ for (String s : a) { if (oldInfo.startsWith(info + "=")) { // $NON-NLS-1$ try { String b[] = s.split("="); // $NON-NLS-1$ return Integer.parseInt(b[1]); } catch (Exception e) { } } } return -1; } /** * Sets the force routing. * * @param connection the connection * @param force the force */ public static void setForceRouting(Connection connection, boolean force) { if (force) addRoutingInfo(connection, ROUTING_INFO_FORCE); else removeRoutingInfo(connection, ROUTING_INFO_FORCE); } /** * Force routing. * * @param connection the connection * @return true, if successful */ public static boolean forceRouting(Connection connection) { return getRoutingInfo(connection).contains(ROUTING_INFO_FORCE); } }
public static GraphicsAlgorithm getSelectionBorder(PictogramElement element) { Collection<PictogramElement> children = Graphiti.getPeService().getPictogramElementChildren(element); PictogramElement first = children.iterator().next(); return first.getGraphicsAlgorithm(); }
public static GraphicsAlgorithm[] getClickArea(PictogramElement element) { Collection<PictogramElement> children = Graphiti.getPeService().getPictogramElementChildren(element); PictogramElement first = children.iterator().next(); return new GraphicsAlgorithm[] {first.getGraphicsAlgorithm()}; }
/** * Checks the given PictogramElement to see if it is a Label shape. Label shapes are identified by * the LABEL_SHAPE property equal to "true". * * @param shape the shape to test * @return true if the shape is a Label */ public static boolean isLabelShape(PictogramElement shape) { if (shape == null) return false; return Graphiti.getPeService().getPropertyValue(shape, GraphitiConstants.LABEL_SHAPE) != null; }
public static boolean isHidden(PictogramElement pe) { if (Graphiti.getPeService().getPropertyValue(pe, GraphitiConstants.IS_HIDDEN) != null) return true; return false; }
private Shape draw(ContainerShape shape) { Shape conditionShape = Graphiti.getPeService().createShape(shape, false); GraphicsUtil.createEventImage(conditionShape, ImageProvider.IMG_20_CONDITION); return conditionShape; }
@Override public void resizeShape(IResizeShapeContext context) { ResizeShapeContext resizeShapeContext = (ResizeShapeContext) context; ContainerShape containerShape = (ContainerShape) context.getPictogramElement(); Activity activity = BusinessObjectUtil.getFirstElementOfType(containerShape, Activity.class); try { BPMNShape shape = (BPMNShape) ModelHandlerLocator.getModelHandler(getDiagram().eResource()).findDIElement(activity); if (shape.isIsExpanded()) { // SubProcess is expanded GraphicsAlgorithm parentGa = containerShape.getGraphicsAlgorithm(); int newWidth = resizeShapeContext.getWidth(); int newHeight = resizeShapeContext.getHeight(); SizeCalculator sizeCalc = new SizeCalculator(containerShape); int shiftX = sizeCalc.shiftX; int shiftY = sizeCalc.shiftY; int minWidth = sizeCalc.minWidth; int minHeight = sizeCalc.minHeight; if (shiftX < 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int x = childGa.getX() - shiftX + MARGIN; childGa.setX(x); } } resizeShapeContext.setX(resizeShapeContext.getX() + shiftX - MARGIN); shiftX = MARGIN; } if (shiftY < 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int y = childGa.getY() - shiftY + MARGIN; childGa.setY(y); } } resizeShapeContext.setY(resizeShapeContext.getY() + shiftY - MARGIN); shiftX = MARGIN; } if (shiftX < MARGIN) shiftX = MARGIN; if (shiftY < MARGIN) shiftY = MARGIN; minWidth += 2 * MARGIN; minHeight += 2 * MARGIN; if (newWidth < minWidth) { parentGa.setWidth(minWidth); } if (newWidth < shiftX + minWidth) { int shift = shiftX + minWidth - newWidth; if (shift > shiftX - MARGIN) { shift = shiftX - MARGIN; } if (shift > 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int x = childGa.getX() - shift; childGa.setX(x); } } } } if (newHeight < minHeight) { parentGa.setHeight(minHeight); } if (newHeight < shiftY + minHeight) { int shift = shiftY + minHeight - newHeight; if (shift > shiftY - MARGIN) { shift = shiftY - MARGIN; } if (shift > 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int y = childGa.getY() - shift; childGa.setY(y); } } } } if (resizeShapeContext.getWidth() < minWidth) resizeShapeContext.setWidth(minWidth); if (resizeShapeContext.getHeight() < minHeight) resizeShapeContext.setHeight(minHeight); } else { // SubProcess is collapsed for (PictogramElement pe : FeatureSupport.getContainerDecorators(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { childGa.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth()); childGa.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight()); } } resizeShapeContext.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth()); resizeShapeContext.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight()); } } catch (Exception e) { Activator.logError(e); } Graphiti.getPeService().sendToBack(containerShape); super.resizeShape(context); }
public static GraphicsAlgorithm getSelectionBorder(PictogramElement element) { Collection<Shape> children = Graphiti.getPeService().getAllContainedShapes((ContainerShape) element); PictogramElement first = children.iterator().next(); return first.getGraphicsAlgorithm(); }
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); } }