private BPMNShape createDIShape(
      BPMNDiagram bpmnDiagram, BaseElement bpmnElement, float x, float y, boolean doImport) {

    BPMNPlane plane = bpmnDiagram.getPlane();
    BPMNShape bpmnShape = null;
    for (DiagramElement de : plane.getPlaneElement()) {
      if (de instanceof BPMNShape) {
        if (bpmnElement == ((BPMNShape) de).getBpmnElement()) {
          bpmnShape = (BPMNShape) de;
          break;
        }
      }
    }

    if (bpmnShape == null) {
      bpmnShape = BpmnDiFactory.eINSTANCE.createBPMNShape();
      bpmnShape.setBpmnElement(bpmnElement);
      Bounds bounds = DcFactory.eINSTANCE.createBounds();
      bounds.setX(x);
      bounds.setY(y);
      ShapeStyle ss = preferences.getShapeStyle(bpmnElement);
      bounds.setWidth(ss.getDefaultWidth());
      bounds.setHeight(ss.getDefaultHeight());
      bpmnShape.setBounds(bounds);
      plane.getPlaneElement().add(bpmnShape);
      preferences.applyBPMNDIDefaults(bpmnShape, null);

      ModelUtil.setID(bpmnShape);
      if (doImport) importer.importShape(bpmnShape);
    }

    return bpmnShape;
  }
  @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();
        }
      }
    }
  }
 /**
  * Get the position of the label relative to its owning figure for the given BaseElement as
  * defined in the User Preferences.
  *
  * @param element the BaseElement that is represented by the graphical figure.
  * @return a ShapeStyle LabelPosition relative location indicator.
  */
 public static LabelPosition getLabelPosition(PictogramElement pe) {
   BaseElement element = BusinessObjectUtil.getFirstBaseElement(pe);
   ShapeStyle ss = ShapeStyle.getShapeStyle(element);
   return ss.getLabelPosition();
 }