@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();
        }
      }
    }
  }
Esempio n. 2
0
  @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);
          }
        }
      }
    }
  }
  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());
      }
    }
  }