⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disablepreprocessingaction.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2006 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 */
package eclipseme.ui.internal.actions;

import java.util.ArrayList;
import java.util.Arrays;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;

import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.preprocessor.PreprocessingNature;

/**
 * An action that enables the natures, etc such that a project can have preprocessor
 * functionality.
 * <p />
 * Copyright (c) 2003-2006 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.3 $
 * <br>
 * $Date: 2006/11/20 01:47:36 $
 * <br>
 * @author Craig Setera
 */
public class DisablePreprocessingAction extends AbstractJavaProjectAction {
	/**
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action) {
		if ((selection != null) && !selection.isEmpty()) {
			IJavaProject javaProject = getJavaProject(selection.getFirstElement());
			if (javaProject != null) {
				try {
					disablePreprocessing(javaProject);
				} catch (CoreException e) {
					EclipseMECorePlugin.log(IStatus.ERROR, e);
				}
			}
		}
	}

	/**
	 * Disable preprocessing on the specified java project.
	 * 
	 * @param javaProject
	 * @throws CoreException 
	 */
	private void disablePreprocessing(IJavaProject javaProject) 
		throws CoreException 
	{
		IProject project = javaProject.getProject();
		PreprocessingNature.deconfigureBuilders(
			project, 
			new NullProgressMonitor());

		IProjectDescription projectDescription = project.getDescription();
		updateNatures(projectDescription);
		project.setDescription(projectDescription, new NullProgressMonitor());
	}

	/**
	 * Update the nature identifiers in the project.
	 * 
	 * @param projectDescription
	 */
	private void updateNatures(IProjectDescription projectDescription) {
		ArrayList natures = new ArrayList(Arrays.asList(projectDescription.getNatureIds()));
		natures.remove(IEclipseMECoreConstants.J2ME_PREPROCESSING_NATURE_ID);
		String[] natureArray = (String[]) natures.toArray(new String[natures.size()]);
		projectDescription.setNatureIds(natureArray);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -