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

📄 preprocessedprojectclasspathinitializer.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.core.internal.preprocessor;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;

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

/**
 * A {@link ClasspathContainerInitializer} implementation for initializing
 * the classpath container for a preprocessed project to point to another
 * project.
 * <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/12/20 02:42:19 $
 * <br>
 * @author Craig Setera
 */
public class PreprocessedProjectClasspathInitializer 
	extends ClasspathContainerInitializer 
{
	/**
	 * @see org.eclipse.jdt.core.ClasspathContainerInitializer#canUpdateClasspathContainer(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject)
	 */
	public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) {
		boolean canUpdate = false;

		try {
			canUpdate = 
				isPreprocessorContainerPath(containerPath) &&
				project.getProject().hasNature(IEclipseMECoreConstants.J2ME_PREPROCESSED_NATURE_ID);
		} catch (CoreException e) {
			EclipseMECorePlugin.log(IStatus.WARNING, e);
		}
		
		return canUpdate;
	}

	/**
	 * @see org.eclipse.jdt.core.ClasspathContainerInitializer#initialize(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject)
	 */
	public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException 
	{
		if (isPreprocessorContainerPath(containerPath)) {
			initializeContainer(containerPath, project);
		}
	}

	/**
	 * @see org.eclipse.jdt.core.ClasspathContainerInitializer#requestClasspathContainerUpdate(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathContainer)
	 */
	public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) 
		throws CoreException 
	{
		initializeContainer(containerPath, project);
	}

	/**
	 * This is our container path.  Go ahead and initialize.
	 * 
	 * @param containerPath
	 * @param project
	 * @throws JavaModelException 
	 */
	private void initializeContainer(IPath containerPath, IJavaProject project) 
		throws JavaModelException 
	{
		String referencedProjectName = containerPath.segment(1);
		IProject referencedProject = 
			ResourcesPlugin.getWorkspace().getRoot().getProject(referencedProjectName);
		
		if ((referencedProject != null) && (referencedProject.exists())) {
			IJavaProject referencedJavaProject = JavaCore.create(referencedProject);
			IClasspathContainer[] containers = new IClasspathContainer[] { 
				new PreprocessedProjectClasspathContainer(referencedJavaProject) 
			};
			
			IJavaProject[] projects = new IJavaProject[] {
				project
			};
			
			JavaCore.setClasspathContainer(containerPath, projects, containers, null);
		}
	}

	/**
	 * Return a boolean if the specified path represents a preprocessed project path.
	 * 
	 * @param path
	 * @return
	 */
	private boolean isPreprocessorContainerPath(IPath path) {
		boolean isPath = false;

		if (path.segmentCount() == 2) {
			isPath = path.segment(0).equals(IEclipseMECoreConstants.J2ME_PREPROCESSED_CONTAINER);
		}
		
		return isPath;
	}
}

⌨️ 快捷键说明

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