public PictogramElement add(IAddContext context) { IAddConnectionContext addConContext = (IAddConnectionContext) context; EActionLink addedEReference = (EActionLink) context.getNewObject(); IPeCreateService peCreateService = Graphiti.getPeCreateService(); // CONNECTION WITH POLYLINE Connection connection = peCreateService.createFreeFormConnection(getDiagram()); connection.setStart(addConContext.getSourceAnchor()); connection.setEnd(addConContext.getTargetAnchor()); IGaService gaService = Graphiti.getGaService(); Polyline polyline = gaService.createPolyline(connection); polyline.setLineWidth(3); polyline.setForeground(manageColor(IColorConstant.LIGHT_ORANGE)); // create link and wire it link(connection, addedEReference); // add dynamic text decorator for the association name ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, true, 0.5, true); Text text = gaService.createText(textDecorator); // createDefaultText(textDecorator); text.setForeground(manageColor(IColorConstant.BLACK)); gaService.setLocation(text, 10, 0); text.setValue("has the action"); return connection; }
public static void updateDIShape(PictogramElement element) { PictogramLink link = element.getLink(); if (link == null) { return; } BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(element, BPMNShape.class); if (bpmnShape == null) { return; } ILocation loc = Graphiti.getLayoutService().getLocationRelativeToDiagram((Shape) element); Bounds bounds = bpmnShape.getBounds(); bounds.setX(loc.getX()); bounds.setY(loc.getY()); GraphicsAlgorithm graphicsAlgorithm = element.getGraphicsAlgorithm(); IDimension size = Graphiti.getGaService().calculateSize(graphicsAlgorithm); bounds.setHeight(size.getHeight()); bounds.setWidth(size.getWidth()); if (element instanceof ContainerShape) { EList<Shape> children = ((ContainerShape) element).getChildren(); for (Shape shape : children) { if (shape instanceof ContainerShape) { updateDIShape(shape); } } } }
@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) { final Event addedEvent = (Event) context.getNewObject(); final ContainerShape parent = context.getTargetContainer(); // CONTAINER SHAPE WITH CIRCLE final IPeCreateService peCreateService = Graphiti.getPeCreateService(); final ContainerShape containerShape = peCreateService.createContainerShape(parent, true); // check whether the context has a size (e.g. from a create feature) // otherwise define a default size for the shape final int width = context.getWidth() <= 0 ? 35 : context.getWidth(); final int height = context.getHeight() <= 0 ? 35 : context.getHeight(); final IGaService gaService = Graphiti.getGaService(); Ellipse circle; { final Ellipse invisibleCircle = gaService.createEllipse(containerShape); invisibleCircle.setFilled(false); invisibleCircle.setLineVisible(false); gaService.setLocationAndSize(invisibleCircle, context.getX(), context.getY(), width, height); // create and set visible circle inside invisible circle circle = gaService.createEllipse(invisibleCircle); circle.setParentGraphicsAlgorithm(invisibleCircle); circle.setStyle(StyleUtil.getStyleForEvent(getDiagram())); gaService.setLocationAndSize(circle, 0, 0, width, height); // create link and wire it link(containerShape, addedEvent); } { final Shape shape = peCreateService.createShape(containerShape, false); final Image image = gaService.createImage(shape, PluginImage.IMG_STARTEVENT_MESSAGE.getImageKey()); image.setWidth(20); image.setHeight(20); gaService.setLocationAndSize(image, (width - 20) / 2, (height - 20) / 2, 20, 20); } // add a chopbox anchor to the shape peCreateService.createChopboxAnchor(containerShape); if (!(addedEvent instanceof EndEvent)) { // create an additional box relative anchor at middle-right final BoxRelativeAnchor boxAnchor = peCreateService.createBoxRelativeAnchor(containerShape); boxAnchor.setRelativeWidth(1.0); boxAnchor.setRelativeHeight(0.51); boxAnchor.setReferencedGraphicsAlgorithm(circle); final Ellipse ellipse = ActivitiUiUtil.createInvisibleEllipse(boxAnchor, gaService); gaService.setLocationAndSize(ellipse, 0, 0, 0, 0); } layoutPictogramElement(containerShape); return containerShape; }
protected static void createSPPFigure( SPPRef spp, boolean refspp, ContainerShape containerShape, GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightDolor) { boolean relay = ValidationUtil.isRelay(spp); int size = refspp ? ITEM_SIZE_SMALL : ITEM_SIZE; int line = refspp ? LINE_WIDTH / 2 : LINE_WIDTH; Color bg = brightDolor; if (refspp) { bg = darkColor; } else { if (relay) bg = brightDolor; else bg = darkColor; } IGaService gaService = Graphiti.getGaService(); // TODOHRR: depicting SPPs as diamond using polygon didn't work // int s2 = size/2; // int xy[] = new int[] { s2, 0, size, s2, s2, size, 0, s2}; // Polygon rect = gaService.createPolygon(invisibleRectangle, xy); // rect.setForeground(darkColor); // rect.setBackground(bg); // rect.setLineWidth(line); // gaService.setLocation(rect, s2, s2); // Rectangle rect = gaService.createRectangle(invisibleRectangle); Ellipse rect = gaService.createEllipse(invisibleRectangle); rect.setForeground(darkColor); rect.setBackground(bg); rect.setLineWidth(line); gaService.setLocationAndSize(rect, size / 2, size / 2, size, size); if (containerShape.getAnchors().isEmpty()) { // here we place our anchor IPeCreateService peCreateService = Graphiti.getPeCreateService(); // FixPointAnchor anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[0], xy[1])); // anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[2], xy[3])); // anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[4], xy[5])); // anchor = peCreateService.createFixPointAnchor(containerShape); // anchor.setLocation(gaService.createPoint(xy[6], xy[7])); // TODOHRR: EllipseAnchor would be nice ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape); anchor.setReferencedGraphicsAlgorithm(rect); } else { // we just set the referenced GA // containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect); } }
@Override public PictogramElement createShape( Object businessObject, ContainerShape layoutParent, int width, int height, IAddContext context) { final IPeCreateService peCreateService = Graphiti.getPeCreateService(); final ContainerShape containerShape = peCreateService.createContainerShape(layoutParent, true); final IGaService gaService = Graphiti.getGaService(); Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram(); final Pool addedPool = (Pool) context.getNewObject(); // check whether the context has a size (e.g. from a create feature) // otherwise define a default size for the shape width = width <= 0 ? 500 : width; height = height <= 0 ? 150 : height; // create invisible outer rectangle expanded by // the width needed for the anchor final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape); gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height); // create and set visible rectangle inside invisible rectangle Rectangle rectangle = gaService.createRectangle(invisibleRectangle); rectangle.setParentGraphicsAlgorithm(invisibleRectangle); rectangle.setStyle(StyleUtil.getStyleForPool(diagram)); gaService.setLocationAndSize(rectangle, 0, 0, width, height); // create shape for text final Shape shape = peCreateService.createShape(containerShape, false); // create and set text graphics algorithm String name = BpmnExtensionUtil.getPoolName(addedPool, ActivitiPlugin.getDefault()); final Text text = gaService.createDefaultText(diagram, shape, name); text.setStyle(StyleUtil.getStyleForEvent(diagram)); text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); text.setVerticalAlignment(Orientation.ALIGNMENT_MIDDLE); gaService.setLocationAndSize(text, 0, 0, 20, height); text.setAngle(-90); Font font = null; if (OSUtil.getOperatingSystem() == OSEnum.Mac) { font = gaService.manageFont(diagram, text.getFont().getName(), 11, false, true); } else { font = gaService.manageDefaultFont(diagram, false, true); } text.setFont(font); // create link and wire it getFeatureProvider().link(shape, addedPool); return containerShape; }
Anchor execute(RelationConnection startConnection, EObject bo, ICustomContext context) { RelationShape relationShape = ActordiagramFactory.eINSTANCE.createRelationShape(); relationShape.setVisible(true); relationShape.setActive(true); int x = context.getX(); if (x < 0) x = 200; int y = context.getY(); if (y < 0) y = 200; GraphicsAlgorithm relationGa = Graphiti.getGaCreateService().createEllipse(relationShape); Graphiti.getGaService() .setLocationAndSize( relationGa, x - RELATION_SIZE / 2, y - RELATION_SIZE / 2, RELATION_SIZE, RELATION_SIZE); ChopboxAnchor anchor = Graphiti.getPeCreateService().createChopboxAnchor(relationShape); anchor.setReferencedGraphicsAlgorithm(relationGa); // Rectangle relationGa = // Graphiti.getGaCreateService().createInvisibleRectangle(relationShape); // int x = context.getX(); if (x < 0) x = 200; // int y = context.getY(); if (y < 0) y = 200; // Graphiti.getGaService().setLocationAndSize(relationGa, x, y, RELATION_SIZE, RELATION_SIZE); // GraphicsAlgorithm relationShapeGa = Graphiti.getGaCreateService().createEllipse(relationGa); // Graphiti.getGaService().setLocationAndSize(relationShapeGa, x, y, RELATION_SIZE, // RELATION_SIZE); // BoxRelativeAnchor anchor = // Graphiti.getPeCreateService().createBoxRelativeAnchor(relationShape); // anchor.setReferencedGraphicsAlgorithm(relationGa); // anchor.setRelativeHeight(0.5); // anchor.setRelativeWidth(0.5); // Rectangle anchorGa = Graphiti.getGaCreateService().createInvisibleRectangle(anchor); // Graphiti.getGaService().setLocationAndSize(anchorGa, -1, -1, 3, 3); relationShape.setContainer(startConnection.getParent()); RelationConnection endConnection = addRelationFeature.createRelationConnection(anchor, startConnection.getEnd()); startConnection.setEnd(anchor); // check class, in case RelationConnection does not subclass it if (startConnection instanceof FreeFormConnection) { splitBendPoints((FreeFormConnection) startConnection, endConnection, x, y); } link(relationShape, bo); link(endConnection, bo); return anchor; }
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; }
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; }
/* (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 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; }
@Override protected Task createFlowElement(ICreateContext context) { EObject target = Graphiti.getLinkService() .getBusinessObjectForLinkedPictogramElement(context.getTargetContainer()); return (Task) customTaskDescriptor.createObject(target); }
@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); }
@Override public PictogramElement createShape( Object businessObject, ContainerShape layoutParent, int width, int height, IAddContext context) { final IPeCreateService peCreateService = Graphiti.getPeCreateService(); final ContainerShape containerShape = peCreateService.createContainerShape(layoutParent, true); final IGaService gaService = Graphiti.getGaService(); Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram(); final TextAnnotation annotation = (TextAnnotation) businessObject; height = Math.max(50, height); width = Math.max(100, width); final int commentEdge = 20; final Rectangle rect = gaService.createInvisibleRectangle(containerShape); gaService.setLocationAndSize(rect, context.getX(), context.getY(), width, height); final Shape lineShape = peCreateService.createShape(containerShape, false); final Polyline line = gaService.createPolyline( lineShape, new int[] {commentEdge, 0, 0, 0, 0, height, commentEdge, height}); line.setStyle(StyleUtil.getStyleForTask(diagram)); line.setLineWidth(2); gaService.setLocationAndSize(line, 0, 0, commentEdge, height); final Shape textShape = peCreateService.createShape(containerShape, false); String annotationText = BpmnExtensionUtil.getTextAnnotationText(annotation, ActivitiPlugin.getDefault()); final MultiText text = gaService.createDefaultMultiText(diagram, textShape, annotationText); text.setStyle(StyleUtil.getStyleForTask(diagram)); text.setVerticalAlignment(Orientation.ALIGNMENT_TOP); if (OSUtil.getOperatingSystem() == OSEnum.Mac) { text.setFont(gaService.manageFont(diagram, text.getFont().getName(), 11)); } gaService.setLocationAndSize(text, 5, 5, width - 5, height - 5); getFeatureProvider().link(textShape, annotation); peCreateService.createChopboxAnchor(containerShape); return containerShape; }
@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; }
/** * 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; }
/** * 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); } }
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; }
@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); }
/** * 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 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); }
@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); } }
@Deprecated protected void moveConnectionBendpoints(FreeFormConnection connection, int deltaX, int deltaY) { List<Point> points = connection.getBendpoints(); for (int i = 0; i < points.size(); i++) { Point point = points.get(i); int oldX = point.getX(); int oldY = point.getY(); points.set(i, Graphiti.getGaCreateService().createPoint(oldX + deltaX, oldY + deltaY)); } }
/** * 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; }
// 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 protected void preMoveShape(IMoveShapeContext context) { MoveShapeContext msc = (MoveShapeContext) context; ContainerShape oldContainer = context.getSourceContainer(); ContainerShape newContainer = context.getTargetContainer(); IPeLayoutService peLayoutService = Graphiti.getPeLayoutService(); // Shape shape = context.getShape(); // ILocation loc = peService.getLocationRelativeToDiagram(shape); ILocation oldLoc = peLayoutService.getLocationRelativeToDiagram(oldContainer); ILocation newLoc = peLayoutService.getLocationRelativeToDiagram(newContainer); // System.out.println( // (oldContainer==newContainer ? "inside:\n" : "outside:\n")+ // "oldContainer:\n" + // " x="+oldLoc.getX()+"\n"+ // " y="+oldLoc.getY()+"\n"+ // "newContainer:\n" + // " x="+newLoc.getX()+"\n"+ // " y="+newLoc.getY()+"\n"+ // "shape:\n" + // " rel x="+shape.getGraphicsAlgorithm().getX()+"\n"+ // " rel y="+shape.getGraphicsAlgorithm().getY()+"\n"+ // " abs x="+loc.getX()+"\n"+ // " abs y="+loc.getY()+"\n"+ // "context:\n" + // " x="+msc.getX()+"\n"+ // " y="+msc.getY()+"\n"+ // " deltaX="+msc.getDeltaX()+"\n"+ // " deltaY="+msc.getDeltaY()+"\n"+ // "\n" // ); if (oldContainer != newContainer) { int x = newLoc.getX() + msc.getX() - oldLoc.getX(); int y = newLoc.getY() + msc.getY() - oldLoc.getY(); int deltaX = newLoc.getX() + msc.getDeltaX() - oldLoc.getX(); int deltaY = newLoc.getY() + msc.getDeltaY() - oldLoc.getY(); // System.out.println( // "new context:\n"+ // " x="+( newLoc.getX() + msc.getX() - oldLoc.getX() )+"\n"+ // " y="+msc.getY()+"\n"+ // " deltaX="+( newLoc.getX() + msc.getDeltaX() - oldLoc.getX() )+"\n"+ // " deltaY="+msc.getDeltaY()+"\n"+ // "\n" // ); // msc.setX(x); // msc.setY(y); // msc.setDeltaX(deltaX); // msc.setDeltaY(deltaY); // msc.setTargetContainer(oldContainer); } super.preMoveShape(context); }
@Override public PictogramElement add(IAddContext context) { final NamespaceDeclaration namespaceDeclaration = (NamespaceDeclaration) context.getNewObject(); final Diagram targetDiagram = (Diagram) context.getTargetContainer(); // CONTAINER SHAPE WITH ROUNDED RECTANGLE IPeCreateService peCreateService = Graphiti.getPeCreateService(); ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true); // define a default size for the shape int width = 100; int height = 50; IGaService gaService = Graphiti.getGaService(); RoundedRectangle roundedRectangle; // need to access it later // create and set graphics algorithm roundedRectangle = gaService.createRoundedRectangle(containerShape, 5, 5); roundedRectangle.setForeground(manageColor(IColorConstant.BLACK)); roundedRectangle.setBackground(manageColor(IColorConstant.WHITE)); roundedRectangle.setLineWidth(2); gaService.setLocationAndSize(roundedRectangle, context.getX(), context.getY(), width, height); // create link and wire it link(containerShape, namespaceDeclaration); // create shape for text Shape shape = peCreateService.createShape(containerShape, false); // create and set text graphics algorithm Text text = gaService.createText(shape, namespaceDeclaration.getName()); text.setForeground(manageColor(IColorConstant.BLACK)); text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); // vertical alignment has as default value "center" text.setFont(gaService.manageDefaultFont(getDiagram(), false, true)); gaService.setLocationAndSize(text, 0, 0, width, 20); // create link and wire it link(shape, namespaceDeclaration); return containerShape; }