private void calculate() {
      int minX = Integer.MAX_VALUE;
      int minY = Integer.MAX_VALUE;
      minWidth = 0;
      minHeight = 0;

      for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
        GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
        if (ga != null) {
          int x = ga.getX();
          int y = ga.getY();
          if (x < minX) minX = x;
          if (y < minY) minY = y;
        }
      }

      shiftX = minX;
      shiftY = minY;

      for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
        GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
        if (ga != null) {
          int w = ga.getX() - minX + ga.getWidth();
          int h = ga.getY() - minY + ga.getHeight();
          if (w > minWidth) minWidth = w;
          if (h > minHeight) minHeight = h;
        }
      }
      if (minWidth <= 0) minWidth = GraphicsUtil.TASK_DEFAULT_WIDTH;
      if (minHeight <= 0) minHeight = GraphicsUtil.TASK_DEFAULT_HEIGHT;
    }
  public static void setContainerChildrenVisible(
      IFeatureProvider fp, ContainerShape container, boolean visible) {
    List<PictogramElement> list = new ArrayList<PictogramElement>();
    list.addAll(container.getChildren());
    for (PictogramElement pe : list) {
      if (ShapeDecoratorUtil.isActivityBorder(pe)) continue;

      if (ShapeDecoratorUtil.isEventSubProcessDecorator(pe)) {
        pe.setVisible(!visible);
      } else pe.setVisible(visible);

      if (visible) FeatureSupport.updateLabel(fp, pe, null);
      if (pe instanceof AnchorContainer) {
        AnchorContainer ac = (AnchorContainer) pe;
        for (Anchor a : ac.getAnchors()) {
          for (Connection c : a.getOutgoingConnections()) {
            c.setVisible(visible);
            if (visible) FeatureSupport.updateLabel(fp, c, null);
            for (ConnectionDecorator decorator : c.getConnectionDecorators()) {
              decorator.setVisible(visible);
            }
          }
        }
      }
    }
  }
  @Override
  public void execute(ICustomContext context) {
    PictogramElement[] pes = context.getPictogramElements();
    if (pes != null && pes.length == 1) {
      PictogramElement pe0 = pes[0];
      Object bo = getBusinessObjectForPictogramElement(pe0);
      if (pe0 instanceof ContainerShape && bo instanceof FlowNode) {
        ContainerShape containerShape = (ContainerShape) pe0;
        FlowNode flowNode = (FlowNode) bo;
        try {
          BPMNShape bpmnShape = DIUtils.findBPMNShape(flowNode);
          if (bpmnShape.isIsExpanded()) {
            Bpmn2Preferences preferences = Bpmn2Preferences.getInstance(getDiagram());
            ShapeStyle ss = preferences.getShapeStyle("TASKS");

            // SubProcess is expanded - resize to standard Task size
            // NOTE: children tasks will be set not-visible in LayoutExpandableActivityFeature

            bpmnShape.setIsExpanded(false);

            GraphicsAlgorithm ga = containerShape.getGraphicsAlgorithm();
            ResizeShapeContext resizeContext = new ResizeShapeContext(containerShape);
            IResizeShapeFeature resizeFeature =
                getFeatureProvider().getResizeShapeFeature(resizeContext);
            IDimension oldSize = FeatureSupport.getCollapsedSize(containerShape);
            int oldWidth = ga.getWidth();
            int oldHeight = ga.getHeight();
            FeatureSupport.setExpandedSize(containerShape, oldWidth, oldHeight);

            int newWidth = ss.getDefaultWidth();
            int newHeight = ss.getDefaultHeight();
            if (newWidth < oldSize.getWidth()) oldSize.setWidth(newWidth);
            if (newHeight < oldSize.getHeight()) oldSize.setHeight(newHeight);
            newWidth = oldSize.getWidth();
            newHeight = oldSize.getHeight();
            resizeContext.setX(ga.getX() + oldWidth / 2 - newWidth / 2);
            resizeContext.setY(ga.getY() + oldHeight / 2 - newHeight / 2);
            resizeContext.setWidth(newWidth);
            resizeContext.setHeight(newHeight);
            resizeFeature.resizeShape(resizeContext);

            UpdateContext updateContext = new UpdateContext(containerShape);
            IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(updateContext);
            if (updateFeature.updateNeeded(updateContext).toBoolean())
              updateFeature.update(updateContext);

            getDiagramEditor().selectPictogramElements(new PictogramElement[] {});
          }

        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
  public static boolean updateConnection(IFeatureProvider fp, Connection connection) {
    boolean layoutChanged = false;

    LayoutContext layoutContext = new LayoutContext(connection);
    ILayoutFeature layoutFeature = fp.getLayoutFeature(layoutContext);
    if (layoutFeature != null) {
      layoutFeature.layout(layoutContext);
      layoutChanged = layoutFeature.hasDoneChanges();
    }

    boolean updateChanged = false;
    UpdateContext updateContext = new UpdateContext(connection);
    IUpdateFeature updateFeature = fp.getUpdateFeature(updateContext);
    if (updateFeature != null && updateFeature.updateNeeded(updateContext).toBoolean()) {
      updateFeature.update(updateContext);
      updateChanged = updateFeature.hasDoneChanges();
    }

    if (layoutChanged) FeatureSupport.updateLabel(fp, connection, null);

    // also update any Connections that are connected to this Connection
    //		for (Shape shape : AnchorUtil.getConnectionPoints(connection)) {
    //			updateConnections(fp, shape);
    //		}
    return layoutChanged || updateChanged;
  }
 @Override
 public boolean canExecute(ICustomContext context) {
   PictogramElement[] pes = context.getPictogramElements();
   if (pes != null && pes.length == 1) {
     BaseElement be = BusinessObjectUtil.getFirstBaseElement(pes[0]);
     return FeatureSupport.isElementExpanded(be);
   }
   return false;
 }
  @Override
  public void delete(IDeleteContext context) {
    ContainerShape laneContainerShape = (ContainerShape) context.getPictogramElement();
    ContainerShape parentContainerShape = laneContainerShape.getContainer();

    if (parentContainerShape != null) {
      boolean before = false;
      ContainerShape neighborContainerShape = FeatureSupport.getLaneAfter(laneContainerShape);
      if (neighborContainerShape == null) {
        neighborContainerShape = FeatureSupport.getLaneBefore(laneContainerShape);
        if (neighborContainerShape == null) {
          super.delete(context);
          return;
        } else {
          before = true;
        }
      }
      boolean isHorizontal = FeatureSupport.isHorizontal(laneContainerShape);
      GraphicsAlgorithm ga = laneContainerShape.getGraphicsAlgorithm();
      GraphicsAlgorithm neighborGA = neighborContainerShape.getGraphicsAlgorithm();
      ResizeShapeContext newContext = new ResizeShapeContext(neighborContainerShape);
      if (!before) {
        Graphiti.getGaService().setLocation(neighborGA, ga.getX(), ga.getY());
      }
      newContext.setLocation(neighborGA.getX(), neighborGA.getY());
      if (isHorizontal) {
        newContext.setHeight(neighborGA.getHeight() + ga.getHeight());
        newContext.setWidth(neighborGA.getWidth());
      } else {
        newContext.setHeight(neighborGA.getHeight());
        newContext.setWidth(neighborGA.getWidth() + ga.getWidth());
      }

      IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(newContext);
      if (resizeFeature.canResizeShape(newContext)) {
        super.delete(context);
        resizeFeature.resizeShape(newContext);
        return;
      }
    }
    super.delete(context);
  }
  private void resizeLaneWidth(IResizeShapeContext context) {
    ContainerShape participantShape = (ContainerShape) context.getShape();
    GraphicsAlgorithm ga = participantShape.getGraphicsAlgorithm();

    int dHeight = context.getHeight() - ga.getHeight();
    int dWidth = context.getWidth() - ga.getWidth();

    if ((dWidth != 0 && FeatureSupport.isHorizontal(participantShape))
        || (dHeight != 0 && !FeatureSupport.isHorizontal(participantShape))) {
      List<PictogramElement> childrenShapes =
          FeatureSupport.getChildsOfBusinessObjectType(participantShape, Lane.class);
      for (PictogramElement currentPicElem : childrenShapes) {
        if (currentPicElem instanceof ContainerShape) {
          ContainerShape currentContainerShape = (ContainerShape) currentPicElem;
          GraphicsAlgorithm laneGA = currentContainerShape.getGraphicsAlgorithm();

          ResizeShapeContext newContext = new ResizeShapeContext(currentContainerShape);

          newContext.setLocation(laneGA.getX(), laneGA.getY());
          if (FeatureSupport.isHorizontal(participantShape)) {
            newContext.setWidth(laneGA.getWidth() + dWidth);
            newContext.setHeight(laneGA.getHeight());
          } else {
            newContext.setHeight(laneGA.getHeight() + dHeight);
            newContext.setWidth(laneGA.getWidth());
          }

          newContext.putProperty(POOL_RESIZE_PROPERTY, true);

          IResizeShapeFeature resizeFeature =
              getFeatureProvider().getResizeShapeFeature(newContext);
          if (resizeFeature.canResizeShape(newContext)) {
            resizeFeature.resizeShape(newContext);
          }
        }
      }
    }
  }
 /**
  * Gets the owner {@link PictogramElement} of a Label from a given IContext object. Label shapes
  * are added by Feature Containers using a {@link
  * org.eclipse.bpmn2.modeler.core.features.MultiAddFeature} - the first Add Feature in the Multi
  * Add creates the graphical element that represents the shape or connection, and a subsequent Add
  * Feature contributes the Label.
  *
  * <p>A Label and its owning PictogramElement are ultimately linked to each other by way of the
  * PictogramElement link list; the owner has a link to the ContainerShape of the Label and the
  * Label has a link to the owning shape or connection.
  *
  * @param context a Graphiti context object
  * @return the PictogramElement that owns a Label if it has one, or null.
  */
 public static PictogramElement getLabelOwner(IContext context) {
   List<PictogramElement> pes =
       (List<PictogramElement>) context.getProperty(GraphitiConstants.PICTOGRAM_ELEMENTS);
   if (pes != null && pes.size() > 0) {
     return getLabelOwner(pes.get(pes.size() - 1));
   }
   PictogramElement pe =
       (PictogramElement) context.getProperty(GraphitiConstants.PICTOGRAM_ELEMENT);
   if (pe != null) return pe;
   if (context instanceof IPictogramElementContext)
     return FeatureSupport.getLabelOwner(
         ((IPictogramElementContext) context).getPictogramElement());
   return null;
 }
  public static void updateCategoryValues(IFeatureProvider fp, PictogramElement pe) {

    Resource resource = ObjectPropertyProvider.getResource(pe);
    if (Bpmn2Preferences.getInstance(resource).getPropagateGroupCategories()) {
      // only do this if User Preference is enabled: assign the Group's CategoryValue
      // to the FlowElement represented by the given PictogramElement
      Diagram diagram = fp.getDiagramTypeProvider().getDiagram();
      FlowElement flowElement = BusinessObjectUtil.getFirstElementOfType(pe, FlowElement.class);
      if (flowElement == null) return;
      // remove any previous Category Values from this FlowElement
      flowElement.getCategoryValueRef().clear();

      // find all Groups in this Resource and check if it contains the given FlowElement
      if (pe instanceof ContainerShape) {
        for (Group group : ModelUtil.getAllObjectsOfType(resource, Group.class)) {
          CategoryValue cv = group.getCategoryValueRef();
          if (cv == null) continue;

          for (PictogramElement groupShape :
              Graphiti.getLinkService().getPictogramElements(diagram, group)) {
            if (groupShape instanceof ContainerShape) {
              for (ContainerShape flowElementShape :
                  FeatureSupport.findGroupedShapes((ContainerShape) groupShape)) {
                FlowElement fe =
                    BusinessObjectUtil.getFirstElementOfType(flowElementShape, FlowElement.class);
                if (fe == flowElement) {
                  fe.getCategoryValueRef().add(cv);
                  break;
                }
              }
            }
          }
        }
      } else if (pe instanceof Connection && flowElement instanceof SequenceFlow) {
        SequenceFlow sf = (SequenceFlow) flowElement;
        FlowNode source = sf.getSourceRef();
        FlowNode target = sf.getTargetRef();

        sf.getCategoryValueRef().clear();
        sf.getCategoryValueRef().addAll(source.getCategoryValueRef());
        sf.getCategoryValueRef().addAll(target.getCategoryValueRef());
      }
    }
  }
    @Override
    public Object[] create(ICreateContext context) {
      String state = Selectstate(BPMNToolBehaviorProvider.id_v);
      if (state.compareTo("Working") == 0) {
        SubProcess element = createBusinessObject(context);
        // if (element instanceof Task)
        // System.out.println("selectTaskId()"+selectTaskId());
        String id = selectTaskId();
        element.setId("VA" + id + "-1");
        UpdateTaskId(id);
        if (element != null) {
          changesDone = true;
          try {
            ModelHandler handler = ModelHandler.getInstance(getDiagram());
            if (FeatureSupport.isTargetLane(context) && element instanceof FlowNode) {
              ((FlowNode) element)
                  .getLanes()
                  .add((Lane) getBusinessObjectForPictogramElement(context.getTargetContainer()));
            }
            handler.addFlowElement(
                getBusinessObjectForPictogramElement(context.getTargetContainer()), element);
          } catch (IOException e) {
            Activator.logError(e);
          }
          PictogramElement pe = null;
          pe = addGraphicalRepresentation(context, element);
          return new Object[] {element, pe};
        } else changesDone = false;
        return new Object[] {null};
      } else {
        System.out.println("01102015tttttttttttt");
        JOptionPane.showMessageDialog(
            null,
            "Operation is not allowed because the version of process "
                + BPMNToolBehaviorProvider.id_v
                + " is Stable",
            "Error",
            JOptionPane.ERROR_MESSAGE);

        return new Object[] {null};
      }
    }
  /**
   * Gets the owner {@link PictogramElement} of a Label from a given PictogramElement. The given PE
   * may already be the owner of the Label, in which case the given value is returned. See also
   * {@link FeatureSupport#getLabelOwner(IContext)}
   *
   * @param pe a PictogramElement that represents the Label shape. This may be either the Label
   *     shape or its owner.
   * @return the PictogramElement that is the owner of a Label shape.
   */
  public static PictogramElement getLabelOwner(PictogramElement pe) {
    DiagramElement de = BusinessObjectUtil.getFirstElementOfType(pe, DiagramElement.class);
    if (de != null) return pe;
    ContainerShape cs = BusinessObjectUtil.getFirstElementOfType(pe, ContainerShape.class);
    de = BusinessObjectUtil.getFirstElementOfType(cs, DiagramElement.class);
    if (de != null) return cs;

    // Messages attached to MessageFlows do not have a BPMNShape element, their
    // visibility is controlled by a setting on the BPMNEdge for the MessageFlow
    Message msg = BusinessObjectUtil.getFirstElementOfType(cs, Message.class);
    if (msg != null) return cs;
    // If this is the ContainerShape of the MessageFlow Message, then it is the label owner.
    if (pe instanceof ContainerShape) {
      Shape labelShape = BusinessObjectUtil.getFirstElementOfType(pe, Shape.class);
      if (FeatureSupport.isLabelShape(labelShape)) return pe;
    }

    Connection c = BusinessObjectUtil.getFirstElementOfType(pe, Connection.class);
    de = BusinessObjectUtil.getFirstElementOfType(c, DiagramElement.class);
    if (de != null) return c;
    return null;
  }
  private void resizeLaneHeight(IResizeShapeContext context) {
    ContainerShape participantShape = (ContainerShape) context.getShape();
    GraphicsAlgorithm ga = participantShape.getGraphicsAlgorithm();

    ContainerShape laneToResize = null;
    GraphicsAlgorithm laneToResizeGA = null;
    int width = 0;
    int height = 0;
    int x = 0;
    int y = 0;
    boolean resizeFirstLane = false;
    boolean resize = false;
    if (FeatureSupport.isHorizontal(participantShape)) {
      int dHeight = context.getHeight() - ga.getHeight();
      if (dHeight != 0) {
        resize = true;
        if (context.getY() != ga.getY()) {
          laneToResize = (ContainerShape) FeatureSupport.getFirstLaneInContainer(participantShape);
          resizeFirstLane = true;
        } else {
          laneToResize = (ContainerShape) FeatureSupport.getLastLaneInContainer(participantShape);
        }
        laneToResizeGA = laneToResize.getGraphicsAlgorithm();
        width = laneToResizeGA.getWidth();
        height = laneToResizeGA.getHeight() + dHeight;
        x = laneToResizeGA.getX();
        y = laneToResizeGA.getY();
      }
    } else {
      int dWidth = context.getWidth() - ga.getWidth();
      if (dWidth != 0) {
        resize = true;
        if (context.getX() != ga.getX()) {
          laneToResize = (ContainerShape) FeatureSupport.getFirstLaneInContainer(participantShape);
          resizeFirstLane = true;
        } else {
          laneToResize = (ContainerShape) FeatureSupport.getLastLaneInContainer(participantShape);
        }
        laneToResizeGA = laneToResize.getGraphicsAlgorithm();
        width = laneToResizeGA.getWidth() + dWidth;
        height = laneToResizeGA.getHeight();
        x = laneToResizeGA.getX();
        y = laneToResizeGA.getY();
      }
    }
    if (resize) {
      ResizeShapeContext newContext = new ResizeShapeContext(laneToResize);

      newContext.setLocation(x, y);
      newContext.setHeight(height);
      newContext.setWidth(width);

      newContext.putProperty(POOL_RESIZE_PROPERTY, true);
      newContext.putProperty(RESIZE_FIRST_LANE, resizeFirstLane);

      IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(newContext);
      if (resizeFeature.canResizeShape(newContext)) {
        resizeFeature.resizeShape(newContext);
      }
      if (FeatureSupport.isHorizontal(participantShape)) {
        ((ResizeShapeContext) context).setHeight(ga.getHeight());
      } else {
        ((ResizeShapeContext) context).setWidth(ga.getWidth());
      }
    }
  }
    private void updateConnectionIfNeeded(DataAssociation association, ItemAwareElement value) {
      DiagramEditor diagramEditor = ModelUtil.getDiagramEditor(association);
      if (diagramEditor == null) return;
      boolean hasDoneChanges = false;
      Diagram diagram = diagramEditor.getDiagramTypeProvider().getDiagram();
      IFeatureProvider fp = diagramEditor.getDiagramTypeProvider().getFeatureProvider();
      Shape taskShape = null;
      EObject container = association.eContainer();
      if (container instanceof Activity || container instanceof Event) {
        for (PictogramElement pe :
            Graphiti.getLinkService().getPictogramElements(diagram, container)) {
          if (pe instanceof Shape
              && BusinessObjectUtil.getFirstElementOfType(pe, BPMNShape.class) != null) {
            taskShape = (Shape) pe;
            break;
          }
        }
      }

      Shape dataShape = null;
      if (value instanceof DataObject
          || value instanceof DataObjectReference
          || value instanceof DataStore
          || value instanceof DataStoreReference
          || value instanceof DataInput
          || value instanceof DataOutput) {
        List<PictogramElement> pes =
            Graphiti.getLinkService().getPictogramElements(diagram, (EObject) value);
        for (PictogramElement p : pes) {
          if (BusinessObjectUtil.getFirstElementOfType(p, BPMNShape.class) != null) {
            dataShape = (Shape) p;
            break;
          }
        }
      }

      Connection connection =
          DataAssociationFeatureContainer.findDataAssociation(diagram, association);
      if (connection != null) {
        // There's an existing DataAssociation connection which needs to
        // either be reconnected or deleted, depending on what the combobox
        // selection is.
        if (dataShape != null) {
          // need to reconnect the DataAssociation
          ReconnectionContext rc = null;
          if (association instanceof DataInputAssociation) {
            Point p = GraphicsUtil.createPoint(connection.getStart());
            Anchor a = AnchorUtil.createAnchor((AnchorContainer) dataShape, p);
            rc = new ReconnectionContext(connection, connection.getStart(), a, null);
            rc.setTargetPictogramElement(dataShape);
            rc.setTargetLocation(Graphiti.getPeService().getLocationRelativeToDiagram(a));
            rc.setReconnectType(ReconnectionContext.RECONNECT_SOURCE);
          } else {
            Point p = GraphicsUtil.createPoint(connection.getEnd());
            Anchor a = AnchorUtil.createAnchor(dataShape, p);
            rc = new ReconnectionContext(connection, a, connection.getEnd(), null);
            rc.setTargetPictogramElement(dataShape);
            rc.setTargetLocation(Graphiti.getPeService().getLocationRelativeToDiagram(a));
            rc.setReconnectType(ReconnectionContext.RECONNECT_TARGET);
          }
          IReconnectionFeature rf = fp.getReconnectionFeature(rc);
          if (rf.canReconnect(rc)) {
            rf.reconnect(rc);
            hasDoneChanges = true;
          }
        } else {
          // need to delete the DataAssociation connection
          DeleteContext dc = new DeleteContext(connection);
          connection.getLink().getBusinessObjects().remove(0);
          IDeleteFeature df = fp.getDeleteFeature(dc);
          df.delete(dc);
        }
      } else if (dataShape != null) {
        // There is no existing DataAssociation connection, but the newly selected source or target
        // is some kind of data object shape, so we need to create a connection between the Activity
        // (or Throw/Catch Event) that owns the DataAssociation, and the new data object shape.
        Point p = GraphicsUtil.createPoint((AnchorContainer) dataShape);
        Anchor ownerAnchor = AnchorUtil.createAnchor(taskShape, p);
        p = GraphicsUtil.createPoint(taskShape);
        Anchor peAnchor = AnchorUtil.createAnchor((AnchorContainer) dataShape, p);
        AddConnectionContext ac = null;
        if (association instanceof DataOutputAssociation) {
          ac = new AddConnectionContext(ownerAnchor, peAnchor);
        } else {
          ac = new AddConnectionContext(peAnchor, ownerAnchor);
        }
        ac.putProperty(GraphitiConstants.BUSINESS_OBJECT, association);
        ac.setNewObject(association);
        IAddFeature af = fp.getAddFeature(ac);
        if (af.canAdd(ac)) {
          PictogramElement pe = af.add(ac);
          if (pe instanceof Connection) {
            connection = (Connection) pe;
            hasDoneChanges = true;
          }
        }
      }
      if (hasDoneChanges) {
        FeatureSupport.updateConnection(
            diagramEditor.getDiagramTypeProvider().getFeatureProvider(), connection);
      }
    }
 /**
  * Returns a list of all Shapes and any Connections attached to them, that are children or
  * descendants of the given Lane or Pool container. Only Shapes that are NOT Lanes are returned.
  *
  * @param containerShape the Lane or Pool container shape.
  */
 public static List<PictogramElement> getPoolAndLaneDescendants(ContainerShape containerShape) {
   List<PictogramElement> children = new ArrayList<PictogramElement>();
   FeatureSupport.collectChildren(containerShape, children, false);
   return children;
 }
 @Override
 protected void internalMove(IMoveShapeContext context) {
   modifyModelStructure(context);
   FeatureSupport.redraw(context.getSourceContainer());
 }
  @Override
  public void resizeShape(IResizeShapeContext context) {

    ResizeShapeContext resizeShapeContext = (ResizeShapeContext) context;

    ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
    Activity activity = BusinessObjectUtil.getFirstElementOfType(containerShape, Activity.class);
    try {
      BPMNShape shape =
          (BPMNShape)
              ModelHandlerLocator.getModelHandler(getDiagram().eResource()).findDIElement(activity);

      if (shape.isIsExpanded()) {

        // SubProcess is expanded

        GraphicsAlgorithm parentGa = containerShape.getGraphicsAlgorithm();
        int newWidth = resizeShapeContext.getWidth();
        int newHeight = resizeShapeContext.getHeight();
        SizeCalculator sizeCalc = new SizeCalculator(containerShape);
        int shiftX = sizeCalc.shiftX;
        int shiftY = sizeCalc.shiftY;
        int minWidth = sizeCalc.minWidth;
        int minHeight = sizeCalc.minHeight;

        if (shiftX < 0) {
          for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
            GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
            if (childGa != null) {
              int x = childGa.getX() - shiftX + MARGIN;
              childGa.setX(x);
            }
          }
          resizeShapeContext.setX(resizeShapeContext.getX() + shiftX - MARGIN);
          shiftX = MARGIN;
        }

        if (shiftY < 0) {
          for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
            GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
            if (childGa != null) {
              int y = childGa.getY() - shiftY + MARGIN;
              childGa.setY(y);
            }
          }
          resizeShapeContext.setY(resizeShapeContext.getY() + shiftY - MARGIN);
          shiftX = MARGIN;
        }

        if (shiftX < MARGIN) shiftX = MARGIN;
        if (shiftY < MARGIN) shiftY = MARGIN;
        minWidth += 2 * MARGIN;
        minHeight += 2 * MARGIN;

        if (newWidth < minWidth) {
          parentGa.setWidth(minWidth);
        }
        if (newWidth < shiftX + minWidth) {
          int shift = shiftX + minWidth - newWidth;
          if (shift > shiftX - MARGIN) {
            shift = shiftX - MARGIN;
          }
          if (shift > 0) {
            for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
              GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
              if (childGa != null) {
                int x = childGa.getX() - shift;
                childGa.setX(x);
              }
            }
          }
        }
        if (newHeight < minHeight) {
          parentGa.setHeight(minHeight);
        }
        if (newHeight < shiftY + minHeight) {
          int shift = shiftY + minHeight - newHeight;
          if (shift > shiftY - MARGIN) {
            shift = shiftY - MARGIN;
          }
          if (shift > 0) {
            for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
              GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
              if (childGa != null) {
                int y = childGa.getY() - shift;
                childGa.setY(y);
              }
            }
          }
        }

        if (resizeShapeContext.getWidth() < minWidth) resizeShapeContext.setWidth(minWidth);
        if (resizeShapeContext.getHeight() < minHeight) resizeShapeContext.setHeight(minHeight);
      } else {

        // SubProcess is collapsed

        for (PictogramElement pe : FeatureSupport.getContainerDecorators(containerShape)) {
          GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
          if (childGa != null) {
            childGa.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth());
            childGa.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight());
          }
        }

        resizeShapeContext.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth());
        resizeShapeContext.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight());
      }

    } catch (Exception e) {
      Activator.logError(e);
    }
    Graphiti.getPeService().sendToBack(containerShape);

    super.resizeShape(context);
  }
 public static void updateCollapsedSize(PictogramElement pe) {
   IDimension size = GraphicsUtil.calculateSize(pe);
   FeatureSupport.setCollapsedSize(pe, size);
 }