/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.ivyde.internal.eclipse.handlers;

import java.util.LinkedList;
import java.util.List;

import org.apache.ivyde.eclipse.IvyNatureHelper;
import org.apache.ivyde.internal.eclipse.IvyPlugin;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

public class RemoveIvyNatureHandler extends AbstractHandler {

    public static final String COMMAND_ID = "org.apache.ivyde.commands.removeivynature";

    public Object execute(ExecutionEvent event) throws ExecutionException {
        ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (!(selection instanceof IStructuredSelection)) {
            return null;
        }

        List<IProject> projects = new LinkedList<>();
        for (Object object : ((IStructuredSelection) selection).toList()) {
            if (!(object instanceof IAdaptable)) {
                return null;
            }
            IProject project = (IProject) ((IAdaptable) object).getAdapter(IProject.class);
            if (project == null) {
                return null;
            }
            if (IvyNatureHelper.hasNature(project)) {
                projects.add(project);
            }
        }

        if (projects.size() > 0) {
            Shell shell = IvyPlugin.getActiveWorkbenchShell();
            boolean doRemove = MessageDialog.openQuestion(shell,
                "Remove Ivy dependency management",
                "Do you want to remove the Ivy dependency management ?\n\n"
                        + "The configuration of the classpath containers will be lost.\n"
                        + "This operation cannot be undone.");
            if (doRemove) {
                for (IProject project : projects) {
                    IvyNatureHelper.removeNature(project);
                }
            }
        }

        return null;
    }
}

@@ -880,26 +880,19 @@
 va.util.
-LinkedList
+Map
 ;%0Aimport
@@ -902,19 +902,18 @@
 va.util.
-Lis
+Se
 t;%0A%0Aimpo
@@ -985,185 +985,91 @@
 yde.
-internal.eclipse.IvyPlugin;%0Aimport org.eclipse.core.commands.AbstractHandler;%0Aimport org.eclipse.core.commands.ExecutionEvent;%0Aimport org.eclipse.core.commands.ExecutionExceptio
+eclipse.cp.IvyClasspathContainer;%0Aimport org.apache.ivyde.internal.eclipse.IvyPlugi
 n;%0Ai
@@ -1115,52 +1115,8 @@
 ct;%0A
-import org.eclipse.core.runtime.IAdaptable;%0A
 impo
@@ -1182,168 +1182,24 @@
 pse.
-jface.viewers.ISelection;%0Aimport org.eclipse.jface.viewers.IStructuredSelection;%0Aimport org.eclipse.swt.widgets.Shell;%0Aimport org.eclipse.ui.handlers.HandlerUti
+swt.widgets.Shel
 l;%0A%0A
@@ -1250,16 +1250,21 @@
 Abstract
+IvyDE
 Handler 
@@ -1364,798 +1364,106 @@
     
-public Object execute(ExecutionEvent event) throws ExecutionException %7B%0A        ISelection selection = HandlerUtil.getCurrentSelection(event);%0A        if (!(selection instanceof IStructuredSelection)) %7B%0A            return null;%0A        %7D%0A%0A        List%3CIProject%3E projects = new LinkedList%3C%3E();%0A        for (Object object : ((IStructuredSelection) selection).toList()) %7B%0A            if (!(object instanceof IAdaptable)) %7B%0A                return null;%0A            %7D%0A            IProject project = (IProject) ((IAdaptable) object).getAdapter(IProject.class);%0A            if (project == null) %7B%0A                return null;%0A            %7D%0A            if (IvyNatureHelper.hasNature(project)) %7B%0A                projects.add(project);%0A            %7D%0A        %7D%0A%0A        if (projects.size() %3E 0) %7B%0A    
+@Override%0A    protected void handleProjects(Map%3CIProject, Set%3CIvyClasspathContainer%3E%3E projects) %7B%0A
     
@@ -1525,20 +1525,16 @@
         
-  
-  
 boolean 
@@ -1577,32 +1577,16 @@
 n(shell,
-%0A               
  %22Remove
@@ -1626,20 +1626,16 @@
         
-    
 %22Do you 
@@ -1682,28 +1682,24 @@
 ment ?%5Cn%5Cn%22%0A
-    
             
@@ -1788,28 +1788,24 @@
             
-  
-  
 + %22This oper
@@ -1839,20 +1839,16 @@
         
-    
 if (doRe
@@ -1867,20 +1867,16 @@
         
-   
- 
 for (IPr
@@ -1895,32 +1895,37 @@
 t : projects
+.keySet()
 ) %7B%0A
-    
             
@@ -1967,20 +1967,16 @@
 oject);%0A
-    
         
@@ -1993,45 +1993,9 @@
     
-    %7D%0A        %7D%0A%0A        return null;
+%7D
 %0A   

Make the action 'Remove Ivy dependency management' work on a container too