package brn.gui.linktable.diagram.edit.policies;

import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.commands.DuplicateEObjectsCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;
import brn.gui.graph.model.ModelPackage;

import brn.gui.linktable.diagram.providers.ModelElementTypes;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;

import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;

import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;

import org.eclipse.gmf.runtime.notation.View;

/**
 * @generated
 */
public class GraphItemSemanticEditPolicy extends
    ModelBaseItemSemanticEditPolicy {

  /**
   * @generated
   */
  protected Command getCreateCommand(CreateElementRequest req) {
    if (ModelElementTypes.Node_1001 == req.getElementType()) {
      if (req.getContainmentFeature() == null) {
        req.setContainmentFeature(ModelPackage.eINSTANCE.getGraph_Nodes());
      }
      return getMSLWrapper(new CreateNode_1001Command(req));
    }
    return super.getCreateCommand(req);
  }

  /**
   * @generated
   */
  private static class CreateNode_1001Command extends CreateElementCommand {

    /**
     * @generated
     */
    public CreateNode_1001Command(CreateElementRequest req) {
      super(req);
    }

    /**
     * @generated
     */
    protected EClass getEClassToEdit() {
      return ModelPackage.eINSTANCE.getGraph();
    };

    /**
     * @generated
     */
    protected EObject getElementToEdit() {
      EObject container = ((CreateElementRequest) getRequest()).getContainer();
      if (container instanceof View) {
        container = ((View) container).getElement();
      }
      return container;
    }
  }

  /**
   * @generated
   */
  protected Command getDuplicateCommand(DuplicateElementsRequest req) {
    TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
        .getEditingDomain();
    return getMSLWrapper(new DuplicateAnythingCommand(editingDomain, req));
  }

  /**
   * @generated
   */
  private static class DuplicateAnythingCommand extends
      DuplicateEObjectsCommand {

    /**
     * @generated
     */
    public DuplicateAnythingCommand(TransactionalEditingDomain editingDomain,
        DuplicateElementsRequest req) {
      super(editingDomain, req.getLabel(), req.getElementsToBeDuplicated(), req
          .getAllDuplicatedElementsMap());
    }
  }
}
