/*****************************************************************************
 * Copyright (c) 2009,2010 ATOS ORIGIN INTEGRATION.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Tristan FAURE (ATOS ORIGIN INTEGRATION) - Initial API and implementation
 *  Maxime AUDRAIN (CS) - API changes
 *  Sebastien GABEL (CS) - evolutions
 *
 *****************************************************************************/
package org.topcased.requirement.core.resolvers;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.topcased.modeler.commands.DeleteModelCommand;
import org.topcased.modeler.commands.EMFtoGEFCommandWrapper;
import org.topcased.requirement.core.commands.RemoveRequirementCommand;

/**
 * This Class handle specific behaviour for requirements when a <b>DeleteModelCommand</b> is executed.
 * 
 * @author <a href="tristan.faure@atosorigin.com">Tristan FAURE</a>
 * @author <a href="mailto:maxime.audrain@c-s.fr">Maxime AUDRAIN</a>
 * @author <a href="mailto:sebastien.gabel@c-s.fr">Sebastien GABEL</a>
 */
public class DeleteCommandResolver extends AdditionalCommand<DeleteModelCommand>
{

    private Map<DeleteModelCommand, EMFtoGEFCommandWrapper> commands;

    public DeleteCommandResolver()
    {
        this(DeleteModelCommand.class);
        commands = new HashMap<DeleteModelCommand, EMFtoGEFCommandWrapper>();
    }

    public DeleteCommandResolver(Class< ? super DeleteModelCommand> clazz)
    {
        super(clazz);
    }

    /**
     * @see org.topcased.requirement.core.resolvers.AdditionalCommand#pre_execute(java.util.List)
     */
    @Override
    protected void pre_execute(List<DeleteModelCommand> deleteModelCommands)
    {
        for (DeleteModelCommand deleteModelCommand : deleteModelCommands)
        {
            Collection<EObject> eObjects = deleteModelCommand.getObjectsDeleting();
            EMFtoGEFCommandWrapper deleteCmd = new EMFtoGEFCommandWrapper(new RemoveRequirementCommand(getModeler().getEditingDomain(), eObjects));
            deleteCmd.execute();
            commands.put(deleteModelCommand, deleteCmd);
        }
    }

    /**
     * @see org.topcased.requirement.core.resolvers.AdditionalCommand#pre_redo(java.util.List)
     */
    @Override
    protected void pre_redo(List<DeleteModelCommand> deleteModelCommands)
    {
        for (DeleteModelCommand deleteModelCommand : deleteModelCommands)
        {
            EMFtoGEFCommandWrapper wrap = commands.get(deleteModelCommand);
            if (wrap != null)
            {
                wrap.redo();
            }
        }
    }

    /**
     * @see org.topcased.requirement.core.resolvers.AdditionalCommand#post_undo(java.util.List)
     */
    @Override
    protected void post_undo(List<DeleteModelCommand> deleteModelCommands)
    {
        for (ListIterator<DeleteModelCommand> i = deleteModelCommands.listIterator(deleteModelCommands.size()); i.hasPrevious();)
        {
            DeleteModelCommand deleteModelCommand = i.previous();
            EMFtoGEFCommandWrapper wrap = commands.get(deleteModelCommand);
            if (wrap != null)
            {
                wrap.undo();
            }
        }
    }

    /**
     * @see org.topcased.requirement.core.resolvers.AdditionalCommand#dipose()
     */
    @Override
    public void dipose()
    {
        super.dipose();
        if (commands != null)
        {
            commands.clear();
        }
    }
}
@@ -811,16 +811,71 @@
 l.Map;%0A%0A
+import org.eclipse.emf.common.command.AbstractCommand;%0A
 import o
@@ -965,69 +965,8 @@
 nd;%0A
-import org.topcased.modeler.commands.EMFtoGEFCommandWrapper;%0A
 impo
@@ -1477,38 +1477,31 @@
 ommand, 
-EMFtoGEFCommandWrapper
+AbstractCommand
 %3E comman
@@ -1637,38 +1637,31 @@
 ommand, 
-EMFtoGEFCommandWrapper
+AbstractCommand
 %3E();%0A   
@@ -2169,70 +2169,36 @@
     
-EMFtoGEFCommandWrapper deleteCmd = new EMFtoGEFCommandWrapper(
+AbstractCommand deleteCmd = 
 new 
@@ -2264,17 +2264,16 @@
 Objects)
-)
 ;%0A      
@@ -2678,35 +2678,31 @@
     
-EMFtoGEFCommandWrapper wrap
+AbstractCommand command
  = c
@@ -2742,36 +2742,39 @@
             if (
-wrap
+command
  != null)%0A      
@@ -2797,20 +2797,23 @@
         
-wrap
+command
 .redo();
@@ -3273,35 +3273,31 @@
     
-EMFtoGEFCommandWrapper wrap
+AbstractCommand command
  = c
@@ -3345,20 +3345,23 @@
     if (
-wrap
+command
  != null
@@ -3396,12 +3396,15 @@
     
-wrap
+command
 .und

Change EMFtoGEFCommandWrapper be AbstractCommand