/**
  * Returns command to reorient EClass based link. New link target or source should be the domain
  * model element associated with this node.
  *
  * @generated
  */
 protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
   switch (getVisualID(req)) {
     case ComponentRealizationEditPart.VISUAL_ID:
     case InterfaceRealizationEditPart.VISUAL_ID:
     case SubstitutionEditPart.VISUAL_ID:
     case RealizationEditPart.VISUAL_ID:
     case ManifestationEditPart.VISUAL_ID:
     case AbstractionEditPart.VISUAL_ID:
     case UsageEditPart.VISUAL_ID:
     case DeploymentEditPart.VISUAL_ID:
     case DependencyEditPart.VISUAL_ID:
     case InformationFlowEditPart.VISUAL_ID:
       IElementEditService provider =
           ElementEditServiceUtils.getCommandProvider(req.getRelationship());
       if (provider == null) {
         return UnexecutableCommand.INSTANCE;
       }
       // Retrieve re-orient command from the Element Edit service
       ICommand reorientCommand = provider.getEditCommand(req);
       if (reorientCommand == null) {
         return UnexecutableCommand.INSTANCE;
       }
       return getGEFWrapper(reorientCommand.reduce());
     case RoleBindingEditPart.VISUAL_ID:
       return getGEFWrapper(new RoleBindingReorientCommand(req));
   }
   return super.getReorientRelationshipCommand(req);
 }
  /** @generated */
  protected Command getDestroyElementCommand(DestroyElementRequest req) {
    EObject selectedEObject = req.getElementToDestroy();
    IElementEditService provider = ElementEditServiceUtils.getCommandProvider(selectedEObject);
    if (provider != null) {
      // Retrieve delete command from the Element Edit service
      ICommand deleteCommand = provider.getEditCommand(req);

      if (deleteCommand != null) {
        return new ICommandProxy(deleteCommand);
      }
    }
    return UnexecutableCommand.INSTANCE;
  }
 /** {@inheritDoc} */
 @Override
 protected void buildNewTypeCreateCommand() {
   // The new element is expected to be a NamedElement.
   IElementEditService commandService =
       ElementEditServiceUtils.getCommandProvider(newTypeContainer);
   if (commandService != null) {
     CreateElementRequest createTypeRequest =
         new CreateElementRequest(newTypeContainer, newTypeKind);
     createTypeRequest.setParameter(
         IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID,
         new ConfigureFeatureCommandFactory(
             UMLPackage.eINSTANCE.getNamedElement_Name(), newTypeNameText.getText()));
     newTypeCreateCommand = commandService.getEditCommand(createTypeRequest);
   }
 }
  /**
   * get the list of command to put an eobject into another EObject, if the parameter eref is
   * null,It will look for the good role of the child eobject
   *
   * @param domain the Transactional Domain , cannot be null
   * @param targetOwner the eobject that will contain the drop object, cannot be null
   * @param childElement that we want to move, cannot be null
   * @param the EREFERENCE for the role of the child element, can be null
   * @return the list of commands to to the drop
   */
  protected List<Command> getDropIntoCommand(
      TransactionalEditingDomain domain,
      EObject targetOwner,
      EObject childElement,
      EReference eref) {
    ArrayList<Command> commandList = new ArrayList<Command>();
    MoveRequest moveRequest = new MoveRequest(targetOwner, childElement);
    IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner);
    if (provider != null) {
      // Retrieve delete command from the Element Edit service
      ICommand command = provider.getEditCommand(moveRequest);

      if (command != null) {
        commandList.add(new GMFtoEMFCommandWrapper(command));
      }
    }
    return commandList;
  }
 /**
  * Returns command to reorient EClass based link. New link target or source should be the domain
  * model element associated with this node.
  *
  * @generated
  */
 protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
   switch (getVisualID(req)) {
     case GeneralizationEditPart.VISUAL_ID:
       IElementEditService provider =
           ElementEditServiceUtils.getCommandProvider(req.getRelationship());
       if (provider == null) {
         return UnexecutableCommand.INSTANCE;
       }
       // Retrieve re-orient command from the Element Edit service
       ICommand reorientCommand = provider.getEditCommand(req);
       if (reorientCommand == null) {
         return UnexecutableCommand.INSTANCE;
       }
       return getGEFWrapper(reorientCommand.reduce());
     case AssociationClassLinkEditPart.VISUAL_ID:
       return getGEFWrapper(new AssociationClassLinkReorientCommand(req));
     case AssociationEditPart.VISUAL_ID:
       return getGEFWrapper(new AssociationReorientCommand(req));
     case AssociationBranchEditPart.VISUAL_ID:
       return getGEFWrapper(new AssociationBranchReorientCommand(req));
     case SubstitutionEditPart.VISUAL_ID:
       return getGEFWrapper(new SubstitutionReorientCommand(req));
     case RealizationEditPart.VISUAL_ID:
       return getGEFWrapper(new RealizationReorientCommand(req));
     case AbstractionEditPart.VISUAL_ID:
       return getGEFWrapper(new AbstractionReorientCommand(req));
     case UsageEditPart.VISUAL_ID:
       return getGEFWrapper(new UsageReorientCommand(req));
     case DependencyEditPart.VISUAL_ID:
       return getGEFWrapper(new DependencyReorientCommand(req));
     case DependencyBranchEditPart.VISUAL_ID:
       return getGEFWrapper(new Dependency2ReorientCommand(req));
     case ElementImportEditPart.VISUAL_ID:
       return getGEFWrapper(new ElementImportReorientCommand(req));
     case PackageImportEditPart.VISUAL_ID:
       return getGEFWrapper(new PackageImportReorientCommand(req));
     case TemplateBindingEditPart.VISUAL_ID:
       return getGEFWrapper(new TemplateBindingReorientCommand(req));
   }
   return super.getReorientRelationshipCommand(req);
 }
  /**
   * get the list of command to put an eobject before or after another EObject It will look for the
   * good role of the child eobject
   *
   * @param domain the Transactional Domain, cannot be null
   * @param targetOwner the eobject that will contain the drop object , cannot be null
   * @param objectLocation the object where we want to drop the object
   * @param newElement that we want to move, cannot be null
   * @return the list of commands to to the drop
   */
  protected List<Command> getOrderChangeCommand(
      TransactionalEditingDomain domain,
      EObject targetOwner,
      EObject objectLocation,
      EObject newElement,
      boolean before) {
    ArrayList<Command> commandList = new ArrayList<Command>();
    ArrayList<EStructuralFeature> possibleEFeatures = new ArrayList<EStructuralFeature>();
    EList<EStructuralFeature> featureList = targetOwner.eClass().getEAllStructuralFeatures();

    // Abort when trying to change order moving the element in one of its children
    if (EcoreUtil.isAncestor(newElement, targetOwner)) {
      return Collections.emptyList();
    }

    // find the feature between childreen and owner
    Iterator<EStructuralFeature> iterator = featureList.iterator();
    while (iterator.hasNext()) {
      EStructuralFeature eStructuralFeature = (EStructuralFeature) iterator.next();

      if (eStructuralFeature instanceof EReference) {
        EReference ref = (EReference) eStructuralFeature;

        if (ref.isContainment()) {

          if (isSubClass(ref.getEType(), newElement.eClass())) {
            possibleEFeatures.add(eStructuralFeature);
          }
        }
      }
    }

    // create the command
    Iterator<EStructuralFeature> iteratorFeature = possibleEFeatures.iterator();
    while (iteratorFeature.hasNext()) {
      EStructuralFeature eStructuralFeature = (EStructuralFeature) iteratorFeature.next();
      ArrayList<EObject> tmp = new ArrayList<EObject>();
      if (targetOwner.eGet(eStructuralFeature) instanceof Collection<?>) {
        // get all element of this efeature
        tmp.addAll((Collection<EObject>) targetOwner.eGet(eStructuralFeature));

        if (!newElement.equals(objectLocation)) {
          tmp.remove(newElement);
          // normally tmp.indexOf(objectLocation)!= -1
          // if this the case objectlocation=new element and
          // it has been removed
          int indexObject = tmp.indexOf(objectLocation);
          if (before && indexObject != -1) {
            tmp.add(tmp.indexOf(objectLocation), newElement);
          } else if (!before && indexObject != -1) {
            tmp.add(tmp.indexOf(objectLocation) + 1, newElement);
          }
        }
      } else {
        tmp.add(newElement);
      }

      SetRequest setRequest = new SetRequest(targetOwner, eStructuralFeature, tmp);
      IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner);
      if (provider != null) {
        // Retrieve delete command from the Element Edit service
        ICommand command = provider.getEditCommand(setRequest);

        if (command != null) {
          commandList.add(new GMFtoEMFCommandWrapper(command));
        }
      }
    }
    return commandList;
  }