@Override
 public boolean canDelete(IDeleteContext context) {
   // Participant bands in a ChoreographyTask only be "deleted" (from the model)
   // if there are no other references to the participant; but they can be "removed"
   // (from the ChoreographyTask's participantRef list) at any time.
   // @see RemoveChoreographyParticipantFeature
   PictogramElement pe = context.getPictogramElement();
   if (ChoreographyUtil.isChoreographyParticipantBand(pe)) {
     int referenceCount = 0;
     Participant participant = BusinessObjectUtil.getFirstElementOfType(pe, Participant.class);
     Definitions definitions = ModelUtil.getDefinitions(participant);
     TreeIterator<EObject> iter = definitions.eAllContents();
     while (iter.hasNext()) {
       EObject o = iter.next();
       for (EReference reference : o.eClass().getEAllReferences()) {
         if (!reference.isContainment() && !(o instanceof DiagramElement)) {
           if (reference.isMany()) {
             List list = (List) o.eGet(reference);
             for (Object referencedObject : list) {
               if (referencedObject == participant) ++referenceCount;
             }
           } else {
             Object referencedObject = o.eGet(reference);
             if (referencedObject == participant) ++referenceCount;
           }
         }
       }
     }
     return referenceCount <= 1;
   }
   return true;
 }
  @Override
  public IDeleteFeature getDeleteFeature(IDeleteContext context) {
    // Deleting a component should be handled by release
    final PictogramElement pe = context.getPictogramElement();
    if (pe instanceof ComponentShape) {
      return new ComponentReleaseFeature(this);
    }

    return super.getDeleteFeature(context);
  }
Esempio n. 3
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);
  }
 @Override
 public void delete(IDeleteContext context) {
   Participant participant =
       BusinessObjectUtil.getFirstElementOfType(context.getPictogramElement(), Participant.class);
   Definitions defs = ModelUtil.getDefinitions(participant);
   Process process = participant.getProcessRef();
   if (process != null) {
     BPMNDiagram bpmnDiagram = null;
     if (defs != null) {
       for (BPMNDiagram d : defs.getDiagrams()) {
         BPMNPlane plane = d.getPlane();
         if (plane.getBpmnElement() == process) {
           bpmnDiagram = d;
           break;
         }
       }
     }
     deleteBusinessObject(process);
     if (bpmnDiagram != null) deleteBusinessObject(bpmnDiagram);
   }
   super.delete(context);
 }