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