/** Clear links */
  @SuppressWarnings({"rawtypes", "unchecked"})
  private static void clearLinks() {
    Collection values =
        getDiagramEditor().getDiagramGraphicalViewer().getEditPartRegistry().values();
    Iterator iterator = values.iterator();
    CompoundCommand ccModel = new CompoundCommand();
    org.eclipse.gef.commands.CompoundCommand ccView =
        new org.eclipse.gef.commands.CompoundCommand();

    while (iterator.hasNext()) {
      Object editPart = iterator.next();
      if (editPart instanceof EsbLinkEditPart) {
        EsbLinkEditPart linkEditPart = (EsbLinkEditPart) editPart;
        /*
         * We shouldn't remove EsbLinkEditParts if the target of the link is a AbstractEndpointInputConnectorEditPart.
         * Because these kind of links will not be get regenerated again according to the current implementation.
         */
        if (linkEditPart.getTarget() instanceof AbstractEndpointInputConnectorEditPart) {
          continue;
        }
        Collection linkCollection = new ArrayList();
        linkCollection.add(((ConnectorImpl) linkEditPart.getModel()).getElement());
        org.eclipse.emf.edit.command.DeleteCommand modelDeleteCommand =
            new org.eclipse.emf.edit.command.DeleteCommand(
                getDiagramEditor().getEditingDomain(), linkCollection);
        if (modelDeleteCommand.canExecute()) {
          ccModel.append(modelDeleteCommand);
        }
        DeleteCommand viewDeleteCommand = new DeleteCommand(linkEditPart.getNotationView());
        if (viewDeleteCommand.canExecute()) {
          ccView.add(new ICommandProxy(viewDeleteCommand));
        }
      }
    }

    if (ccModel.canExecute()) {
      getDiagramEditor().getEditingDomain().getCommandStack().execute(ccModel);
    }
    if (ccView.canExecute()) {
      getDiagramEditor().getDiagramEditDomain().getDiagramCommandStack().execute(ccView);
    }
  }