public void focusLost(final FocusEvent e) {
          PictogramElement pe = getSelectedPictogramElement();
          if (pe != null) {
            final Object bo = getBusinessObject(pe);
            if (bo instanceof StartEvent) {
              DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
              TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
              ActivitiUiUtil.runModelChange(
                  new Runnable() {
                    public void run() {
                      StartEvent startEvent = (StartEvent) bo;

                      String initator = initiatorText.getText();
                      if (StringUtils.isNotEmpty(initator)) {
                        startEvent.setInitiator(initator);

                      } else {
                        startEvent.setInitiator("");
                      }

                      String formKey = formKeyText.getText();
                      if (StringUtils.isNotEmpty(formKey)) {
                        startEvent.setFormKey(formKey);

                      } else {
                        startEvent.setFormKey("");
                      }
                    }
                  },
                  editingDomain,
                  "Model Update");
            }
          }
        }
  @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;
  }
  private CustomServiceTask findCustomServiceTask(ServiceTask serviceTask) {
    CustomServiceTask result = null;
    if (serviceTask.isExtended()) {

      final List<CustomServiceTask> customServiceTasks =
          ExtensionUtil.getCustomServiceTasks(
              ActivitiUiUtil.getProjectFromDiagram(getDiagramTypeProvider().getDiagram()));

      for (final CustomServiceTask customServiceTask : customServiceTasks) {
        if (serviceTask.getExtensionId().equals(customServiceTask.getId())) {
          result = customServiceTask;
          break;
        }
      }
    }
    return result;
  }
        public void focusLost(final FocusEvent e) {
          final Bpmn2MemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram()));
          if (model == null) {
            return;
          }

          PictogramElement pe = getSelectedPictogramElement();
          if (pe != null) {
            final Object bo = getBusinessObject(pe);
            if (bo instanceof BoundaryEvent) {
              DiagramEditor diagramEditor = (DiagramEditor) getDiagramEditor();
              TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
              ActivitiUiUtil.runModelChange(
                  new Runnable() {

                    public void run() {

                      if (bo instanceof BoundaryEvent) {
                        BoundaryEvent boundaryEvent = (BoundaryEvent) bo;

                        int selection = cancelActivityCombo.getSelectionIndex();
                        if (selection == 0) {
                          boundaryEvent.setCancelActivity(true);
                        } else {
                          boundaryEvent.setCancelActivity(false);
                        }

                        MessageEventDefinition messageDefinition =
                            (MessageEventDefinition) boundaryEvent.getEventDefinitions().get(0);
                        if (messageCombo.getSelectionIndex() > 0) {
                          List<Message> messageList =
                              new ArrayList<Message>(model.getBpmnModel().getMessages());
                          messageDefinition.setMessageRef(
                              messageList.get(messageCombo.getSelectionIndex() - 1).getId());
                        } else {
                          messageDefinition.setMessageRef("");
                        }
                      }
                    }
                  },
                  editingDomain,
                  "Model Update");
            }
          }
        }
  @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;
  }