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;
  }
    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 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;
  }
  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;
  }
  @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;
  }
Exemple #7
0
  /**
   * Create a resource from the given URI and append a new Diagram instance to its contents. The
   * resourceSet used must be authorized to write on the disk. This means that the default
   * EditingDomain's resourceSet must be used in a write transaction (for example). If it is not
   * possible, do not provide a resourceSet, the default one will be used.
   *
   * @param resourceSet
   * @param uri
   * @return The Diagram created
   * @throws IOException
   */
  public static Diagram createDiagramResource(final ResourceSet resourceSet, final URI uri)
      throws IOException {
    // Compute the new diagram name
    final String name = uri.trimFileExtension().lastSegment();

    // Create the diagram
    final Diagram diagram =
        Graphiti.getPeCreateService().createDiagram(Activator.DIAGRAM_TYPE, name, true);

    // Create the resource
    Resource res = resourceSet.createResource(uri);
    res.getContents().add(diagram);
    res.setTrackingModification(true);
    res.save(Collections.EMPTY_MAP);

    return diagram;
  }
  @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;
  }
  public PictogramElement add(IAddContext context) {
    Object newObject = context.getNewObject();
    Shape shape = Graphiti.getPeCreateService().createShape(context.getTargetContainer(), true);

    IGaService gaService = Graphiti.getGaService();
    Rectangle r = gaService.createRectangle(shape);
    gaService.setLocationAndSize(r, context.getX(), context.getY(), 400, 100);
    r.setBackground(gaService.manageColor(getDiagram(), IColorConstant.WHITE));

    String text = newObject.getClass().getName() + " - " + newObject.toString();
    Text textGa = gaService.createDefaultText(getDiagram(), r, text);
    gaService.setLocationAndSize(textGa, 0, 0, 400, 100);
    textGa.setRotation(-1d);

    // Create an italic font to use it later in the rich tooltip
    gaService.manageFont(
        getDiagram(), IGaService.DEFAULT_FONT, IGaService.DEFAULT_FONT_SIZE, true, false);

    return shape;
  }
  @Override
  public PictogramElement add(IAddContext context) {

    IAddConnectionContext addConContext = (IAddConnectionContext) context;
    IPeCreateService peCreateService = Graphiti.getPeCreateService();
    IGaService gaService = Graphiti.getGaService();

    Connection connection = peCreateService.createFreeFormConnection(getDiagram());
    connection.setStart(addConContext.getSourceAnchor());
    connection.setEnd(addConContext.getTargetAnchor());

    Polyline polyline = gaService.createPlainPolyline(connection);
    polyline.setForeground(manageColor(IColorConstant.BLACK));

    // TODO: enable the link to the domain object
    // Object addedDomainObjectConnection = context.getNewObject();
    // link(connection, addedDomainObjectConnection);

    return connection;
  }
  @Override
  public PictogramElement add(IAddContext context) {
    // TODO Auto-generated method stub
    IAddConnectionContext addConContext = (IAddConnectionContext) context;
    AdviceEdge edge = (AdviceEdge) context.getNewObject();
    IPeCreateService peCreateService = Graphiti.getPeCreateService();

    Connection connection = peCreateService.createFreeFormConnection(getDiagram());
    connection.setStart(addConContext.getSourceAnchor());
    connection.setEnd(addConContext.getTargetAnchor());

    IGaService gaService = Graphiti.getGaService();
    Polyline polyline = gaService.createPlainPolyline(connection);
    polyline.setStyle(StyleUtil.getStyleForElement(getDiagram()));
    polyline.setLineStyle(LineStyle.DOT);

    link(connection, edge);

    // add dynamic text decorator for the reference name
    ConnectionDecorator textDecorator =
        peCreateService.createConnectionDecorator(connection, true, 0.5, true);
    Text text = gaService.createPlainText(textDecorator);
    text.setStyle(StyleUtil.getStyleForTextDecorator((getDiagram())));
    gaService.setLocation(text, 10, 0);

    text.setValue(edge.getAdvicetype().toString());

    ConnectionDecorator cd;
    cd = peCreateService.createConnectionDecorator(connection, false, 1.0, true);
    int[] xy = {getPointCutR() * 2, 0, 0, -getPointCutR() * 2, 0, 0, 0, getPointCutR() * 2};
    Polygon polygon = Graphiti.getGaCreateService().createPolygon(cd, xy);
    polygon.setStyle(StyleUtil.getStyleForElement(getDiagram()));
    polygon.setLineStyle(LineStyle.DOT);

    return connection;
  }
  // Adds a User Application figure to the target object
  @Override
  public PictogramElement add(final IAddContext context) {

    TDeploymentArtifact addedClass = (TDeploymentArtifact) context.getNewObject();

    ContainerShape targetDiagram = (ContainerShape) context.getTargetContainer();
    Object[] targetDiagrams = targetDiagram.getChildren().toArray();
    int ySD = 0;
    int interdist = 0;
    for (int i = 0; i < targetDiagrams.length; i++) {
      Object o = getBusinessObjectForPictogramElement((Shape) targetDiagrams[i]);
      if (o instanceof UserApplication) interdist = 3;
    }
    for (int i = 0; i < targetDiagrams.length; i++) {
      Object o = getBusinessObjectForPictogramElement((Shape) targetDiagrams[i]);
      if (((Shape) targetDiagrams[i]).getGraphicsAlgorithm() instanceof Rectangle
          || (o instanceof SoftwareDependency)) {
        if (((Shape) targetDiagrams[i]).getGraphicsAlgorithm() instanceof Rectangle) {
          ySD = ((Shape) targetDiagrams[i]).getGraphicsAlgorithm().getY();
        }
        ((Shape) targetDiagrams[i])
            .getGraphicsAlgorithm()
            .setY(((Shape) targetDiagrams[i]).getGraphicsAlgorithm().getY() + 20 + interdist);
      }
    }
    // CONTAINER SHAPE WITH ROUNDED RECTANGLE
    IPeCreateService peCreateService = Graphiti.getPeCreateService();
    ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);
    final int width = StyleUtil.SOFT_DEPENDENCY_WIDTH;
    final int height = 20;
    IGaService gaService = Graphiti.getGaService();
    RoundedRectangle roundedRectangle;
    {
      // create and set graphics algorithm
      int x = (StyleUtil.APP_COMPONENT_WIDTH - width) / 2;
      roundedRectangle = gaService.createRoundedRectangle(containerShape, 5, 5);
      roundedRectangle.setForeground(manageColor(E_CLASS_FOREGROUND));
      roundedRectangle.setBackground(manageColor(E_CLASS_BACKGROUND));
      roundedRectangle.setLineWidth(2);
      gaService.setLocationAndSize(roundedRectangle, x, ySD - 10 + interdist, width, height);
      if (addedClass.eResource() == null) {
        getDiagram().eResource().getContents().add(addedClass);
      }
      // create link and wire it
      link(containerShape, addedClass);
    }
    // SHAPE WITH LINE
    {
      // create shape for line
      Shape shape = peCreateService.createShape(containerShape, false);
      // create and set graphics algorithm
      Polyline polyline = gaService.createPolyline(shape, new int[] {0, 20, width, 20});
      polyline.setForeground(manageColor(E_CLASS_FOREGROUND));
      polyline.setLineWidth(2);
    }
    // SHAPE WITH TEXT
    {
      // create shape for text
      Shape shape = peCreateService.createShape(containerShape, false);
      // create and set text graphics algorithm
      Text text = gaService.createText(shape, addedClass.getName());
      text.setForeground(manageColor(E_CLASS_TEXT_FOREGROUND));
      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, addedClass);
    }
    return containerShape;
  }
  @Override
  public PictogramElement add(IAddContext context) {
    final Task addedTask = (Task) context.getNewObject();
    final ContainerShape parent = context.getTargetContainer();

    // CONTAINER SHAPE WITH ROUNDED RECTANGLE
    final IPeCreateService peCreateService = Graphiti.getPeCreateService();
    final ContainerShape containerShape = peCreateService.createContainerShape(parent, true);
    final IGaService gaService = Graphiti.getGaService();

    DiagramBaseShape baseShape = DiagramBaseShape.ACTIVITY;

    if (ExtensionUtil.isCustomServiceTask(addedTask)) {
      final ServiceTask serviceTask = (ServiceTask) addedTask;
      final List<CustomServiceTask> customServiceTasks =
          ExtensionUtil.getCustomServiceTasks(ActivitiUiUtil.getProjectFromDiagram(getDiagram()));

      CustomServiceTask targetTask = null;

      for (final CustomServiceTask customServiceTask : customServiceTasks) {
        if (customServiceTask.getId().equals(ExtensionUtil.getCustomServiceTaskId(serviceTask))) {
          targetTask = customServiceTask;
          break;
        }
      }

      if (!DiagramBaseShape.ACTIVITY.equals(targetTask.getDiagramBaseShape())) {
        baseShape = targetTask.getDiagramBaseShape();
      }
    }

    int width = 0;
    int height = 0;
    GraphicsAlgorithm algorithm = null;

    switch (baseShape) {
      case ACTIVITY:
        // check whether the context has a size (e.g. from a create feature)
        // otherwise define a default size for the shape
        width = context.getWidth() <= 0 ? 105 : context.getWidth();
        height = context.getHeight() <= 0 ? 55 : context.getHeight();

        RoundedRectangle roundedRectangle; // need to access it later
        {
          // 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
          roundedRectangle = gaService.createRoundedRectangle(invisibleRectangle, 20, 20);
          algorithm = roundedRectangle;
          roundedRectangle.setParentGraphicsAlgorithm(invisibleRectangle);
          roundedRectangle.setStyle(StyleUtil.getStyleForTask(getDiagram()));
          gaService.setLocationAndSize(roundedRectangle, 0, 0, width, height);

          // create link and wire it
          link(containerShape, addedTask);
        }
        break;
      case GATEWAY:
        // check whether the context has a size (e.g. from a create feature)
        // otherwise define a default size for the shape
        width = context.getWidth() <= 0 ? 60 : context.getWidth();
        height = context.getHeight() <= 0 ? 60 : context.getHeight();

        Polygon polygon;
        {
          int xy[] = new int[] {0, 30, 30, 0, 60, 30, 30, 60, 0, 30};

          final Polygon invisiblePolygon = gaService.createPolygon(containerShape, xy);
          invisiblePolygon.setFilled(false);
          invisiblePolygon.setLineVisible(false);
          gaService.setLocationAndSize(
              invisiblePolygon, context.getX(), context.getY(), width, height);

          // create and set visible circle inside invisible circle
          polygon = gaService.createPolygon(invisiblePolygon, xy);
          algorithm = polygon;
          polygon.setParentGraphicsAlgorithm(invisiblePolygon);
          polygon.setStyle(StyleUtil.getStyleForTask(getDiagram()));
          gaService.setLocationAndSize(polygon, 0, 0, width, height);

          // create link and wire it
          link(containerShape, addedTask);
        }
        break;
      case EVENT:
        // check whether the context has a size (e.g. from a create feature)
        // otherwise define a default size for the shape
        width = context.getWidth() <= 0 ? 55 : context.getWidth();
        height = context.getHeight() <= 0 ? 55 : context.getHeight();

        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.getStyleForTask(getDiagram()));
          gaService.setLocationAndSize(circle, 0, 0, width, height);

          // create link and wire it
          link(containerShape, addedTask);
        }
        break;
    }

    // SHAPE WITH TEXT
    {
      // create shape for text
      final Shape shape = peCreateService.createShape(containerShape, false);

      // create and set text graphics algorithm
      final MultiText text =
          gaService.createDefaultMultiText(getDiagram(), shape, addedTask.getName());
      text.setStyle(StyleUtil.getStyleForTask(getDiagram()));
      text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
      text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
      if (OSUtil.getOperatingSystem() == OSEnum.Mac) {
        text.setFont(gaService.manageFont(getDiagram(), text.getFont().getName(), 11));
      }

      switch (baseShape) {
        case ACTIVITY:
          gaService.setLocationAndSize(text, 0, 20, width, height - 25);
          break;
        case GATEWAY:
          gaService.setLocationAndSize(text, 0, height + 5, width, 40);
          break;
        case EVENT:
          gaService.setLocationAndSize(text, 0, height + 5, width, 40);
          break;
      }

      // create link and wire it
      link(shape, addedTask);

      // provide information to support direct-editing directly
      // after object creation (must be activated additionally)
      final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
      // set container shape for direct editing after object creation
      directEditingInfo.setMainPictogramElement(containerShape);
      // set shape and graphics algorithm where the editor for
      // direct editing shall be opened after object creation
      directEditingInfo.setPictogramElement(shape);
      directEditingInfo.setGraphicsAlgorithm(text);
    }

    {
      final Shape shape = peCreateService.createShape(containerShape, false);
      final Image image = gaService.createImage(shape, getIcon(addedTask));

      switch (baseShape) {
        case ACTIVITY:
          gaService.setLocationAndSize(image, 5, 5, IMAGE_SIZE, IMAGE_SIZE);
          break;
        case GATEWAY:
          gaService.setLocationAndSize(
              image, (width - IMAGE_SIZE) / 2, (height - IMAGE_SIZE) / 2, IMAGE_SIZE, IMAGE_SIZE);
          break;
        case EVENT:
          gaService.setLocationAndSize(
              image, (width - IMAGE_SIZE) / 2, (height - IMAGE_SIZE) / 2, IMAGE_SIZE, IMAGE_SIZE);
          break;
      }
    }

    // add a chopbox anchor to the shape
    peCreateService.createChopboxAnchor(containerShape);

    // 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(algorithm);
    final Ellipse ellipse = ActivitiUiUtil.createInvisibleEllipse(boxAnchor, gaService);
    gaService.setLocationAndSize(ellipse, 0, 0, 0, 0);
    layoutPictogramElement(containerShape);

    return containerShape;
  }