| /******************************************************************************* |
| * Copyright (c) 2008-2018 Sonatype, Inc. and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Sonatype, Inc. - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.m2e.core.ui.internal.actions; |
| |
| import java.util.Iterator; |
| |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.IObjectActionDelegate; |
| import org.eclipse.ui.IWorkbenchPart; |
| |
| import org.eclipse.m2e.core.MavenPlugin; |
| |
| |
| public class DisableNatureAction implements IObjectActionDelegate { |
| private static final Logger log = LoggerFactory.getLogger(DisableNatureAction.class); |
| |
| public static final String ID = "org.eclipse.m2e.disableAction"; //$NON-NLS-1$ |
| |
| private ISelection selection; |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) |
| */ |
| public void run(IAction action) { |
| if(selection instanceof IStructuredSelection) { |
| IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
| for(Iterator<?> it = structuredSelection.iterator(); it.hasNext();) { |
| Object element = it.next(); |
| IProject project = null; |
| if(element instanceof IProject) { |
| project = (IProject) element; |
| } else if(element instanceof IAdaptable) { |
| project = ((IAdaptable) element).getAdapter(IProject.class); |
| } |
| if(project != null) { |
| try { |
| MavenPlugin.getProjectConfigurationManager().disableMavenNature(project, new NullProgressMonitor()); |
| |
| } catch(CoreException ex) { |
| log.error(ex.getMessage(), ex); |
| } |
| } |
| } |
| } |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, |
| * org.eclipse.jface.viewers.ISelection) |
| */ |
| public void selectionChanged(IAction action, ISelection selection) { |
| this.selection = selection; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, |
| * org.eclipse.ui.IWorkbenchPart) |
| */ |
| public void setActivePart(IAction action, IWorkbenchPart targetPart) { |
| } |
| |
| } |