@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; }
@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; }