Exemplo n.º 1
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);
  }