public static void removeMessageFlow(
      TransactionalEditingDomain editingDomain,
      Message event,
      AbstractCatchMessageEvent target,
      DiagramEditPart dep) {

    EditPart ep = findEditPart(dep, target);
    CompositeCommand command = new CompositeCommand("Remove MessageFlows");

    for (Object connection : ((AbstractGraphicalEditPart) ep).getTargetConnections()) {
      if (connection instanceof MessageFlowEditPart) {
        MessageFlowEditPart connectionPart = (MessageFlowEditPart) connection;
        MessageFlow flow = (MessageFlow) connectionPart.resolveSemanticElement();
        SetCommand c =
            new SetCommand(
                editingDomain,
                flow.getTarget(),
                ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT,
                null);
        editingDomain.getCommandStack().execute(c);
        command.add(new DeleteCommand(editingDomain, connectionPart.getPrimaryView()));
        DestroyElementRequest req =
            new DestroyElementRequest(
                editingDomain, connectionPart.resolveSemanticElement(), false);
        DestroyElementCommand rmComd = new DestroyElementCommand(req);
        command.add(rmComd);
      }
    }

    dep.getDiagramEditDomain()
        .getDiagramCommandStack()
        .execute(new ICommandProxy(command.reduce()));
    dep.getDiagramEditDomain().getDiagramCommandStack().flush();
    dep.refresh();
  }
  public static void createMessageFlow(
      TransactionalEditingDomain editingDomain,
      Message event,
      ThrowMessageEvent source,
      AbstractCatchMessageEvent target,
      DiagramEditPart dep) {
    EditPart targetEP = findEditPart(dep, target);
    EditPart sourceEP = findEditPart(dep, source);

    CreateConnectionViewAndElementRequest request =
        new CreateConnectionViewAndElementRequest(
            ProcessElementTypes.MessageFlow_4002,
            ((IHintedType) ProcessElementTypes.MessageFlow_4002).getSemanticHint(),
            dep.getDiagramPreferencesHint());
    Command createMessageFlowCommand =
        CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceEP, targetEP);
    if (createMessageFlowCommand.canExecute()) {
      dep.getDiagramEditDomain().getDiagramCommandStack().execute(createMessageFlowCommand);
      dep.getDiagramEditDomain().getDiagramCommandStack().flush();
      dep.refresh();

      ConnectionViewAndElementDescriptor desc =
          (ConnectionViewAndElementDescriptor) request.getNewObject();
      MessageFlow message = (MessageFlow) desc.getElementAdapter().getAdapter(MessageFlow.class);
      SetCommand setCommand =
          new SetCommand(
              editingDomain, message, ProcessPackage.Literals.ELEMENT__NAME, event.getName());
      editingDomain.getCommandStack().execute(setCommand);
    }
  }
  public static void removeMessageFlow(
      TransactionalEditingDomain editingDomain,
      Message event,
      ThrowMessageEvent source,
      DiagramEditPart dep) {
    EditPart ep = findEditPart(dep, source);
    CompositeCommand command = new CompositeCommand("Remove MessageFlows");

    for (Object connection : ((AbstractGraphicalEditPart) ep).getSourceConnections()) {
      if (connection instanceof MessageFlowEditPart) {
        MessageFlowEditPart connectionPart = (MessageFlowEditPart) connection;
        MessageFlow flow = (MessageFlow) connectionPart.resolveSemanticElement();
        if (flow.getTarget().getEvent() == null
            || flow.getTarget().getEvent().equals(event.getName())) {
          List<Message> events = new ArrayList<Message>();
          ModelHelper.findAllEvents(source, events);
          for (Message ev : events) {
            if (ev.eContainer().equals(source) && !ev.equals(event)) {
              if (ev.getTargetProcessExpression() != null
                  && event.getTargetProcessExpression() != null
                  && ev.getTargetProcessExpression()
                      .getContent()
                      .equals(event.getTargetProcessExpression().getContent())
                  && ev.getTargetElementExpression() != null
                  && ev.getTargetElementExpression().getContent() != null
                  && event.getTargetElementExpression() != null
                  && ev.getTargetElementExpression()
                      .getContent()
                      .equals(event.getTargetElementExpression().getContent())) {
                SetCommand setCommand =
                    new SetCommand(
                        editingDomain,
                        ev,
                        ProcessPackage.Literals.MESSAGE__TARGET_PROCESS_EXPRESSION,
                        null);
                editingDomain.getCommandStack().execute(setCommand);
                setCommand =
                    new SetCommand(
                        editingDomain,
                        ev,
                        ProcessPackage.Literals.MESSAGE__TARGET_ELEMENT_EXPRESSION,
                        null);
                editingDomain.getCommandStack().execute(setCommand);
              }
            }
          }
          SetCommand c =
              new SetCommand(
                  editingDomain,
                  flow.getTarget(),
                  ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT,
                  null);
          editingDomain.getCommandStack().execute(c);
          command.add(new DeleteCommand(editingDomain, connectionPart.getPrimaryView()));
          DestroyElementRequest req =
              new DestroyElementRequest(
                  editingDomain, connectionPart.resolveSemanticElement(), false);
          DestroyElementCommand rmComd = new DestroyElementCommand(req);
          command.add(rmComd);
        }
      }
    }
    dep.getDiagramEditDomain()
        .getDiagramCommandStack()
        .execute(new ICommandProxy(command.reduce()));
    dep.getDiagramEditDomain().getDiagramCommandStack().flush();
    dep.refresh();
  }