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

📄 j2mejavacapabilityconfigurationpage.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2005 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.wizards;

import java.util.ArrayList;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;

import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.J2MEClasspathContainer;
import eclipseme.core.internal.preprocessor.PreprocessorBuilder;

/**
 * Handler for Java capability configuration.
 * <p />
 * Copyright (c) 2003-2005 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.7 $
 * <br>
 * $Date: 2006/11/12 01:10:47 $
 * <br>
 * @author Craig Setera
 */
public class J2MEJavaCapabilityConfigurationPage
	extends JavaCapabilityConfigurationPage 
{
	/**
	 * 
	 */
	public J2MEJavaCapabilityConfigurationPage(
		WizardNewProjectCreationPage newProjectPage) 
	{
		super();
	}

	/**
	 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
	 */
	public void setVisible(boolean visible) {
		if (visible) {
			updateConfiguration();
		}
		
		super.setVisible(visible);
	}

	/**
	 * Update the java configuration before
	 * making the page visible.
	 */
	void updateConfiguration() {
		// Work out the project and path information
		IProject project = getNewProjectCreatePage().getProjectHandle();
		IJavaProject javaProject = JavaCore.create(project);
		IPath projectPath = project.getFullPath();

		// Initialize the classpath entries using the source directories
		// and classpath container
		ArrayList entryList = new ArrayList();
		entryList.add(getSrcPathEntry(projectPath));
		addResourcesDirectoryIfRequested(entryList, project);
		entryList.add(JavaCore.newContainerEntry(new Path(J2MEClasspathContainer.J2ME_CONTAINER)));
		
		IClasspathEntry[] entries = 
			(IClasspathEntry[]) entryList.toArray(new IClasspathEntry[entryList.size()]);
		init(javaProject, null, entries, false);
	}

	/**
	 * Add a resources directory as a source path entry if the user
	 * preferences requested.
	 * 
	 * @param entryList
	 * @param project
	 */
	private void addResourcesDirectoryIfRequested(ArrayList entryList, IProject project) {
		Preferences prefs = EclipseMECorePlugin.getDefault().getPluginPreferences();

		if (useSourceAndBinaryFolders() &&
			prefs.getBoolean(IEclipseMECoreConstants.PREF_USE_RESOURCES_DIR)) 
		{
			// Create the resources directory if it doesn't already exist
			String resDirName = prefs.getString(IEclipseMECoreConstants.PREF_RESOURCES_DIR);
			IFolder resFolder = project.getFolder(resDirName);
			
			// Add it as a source folder to the java project
			entryList.add(JavaCore.newSourceEntry(resFolder.getFullPath()));
		}
	}

	/**
	 * Find the new project creation page in our wizard.
	 * @return
	 */
	private WizardNewProjectCreationPage getNewProjectCreatePage()
	{
		return (WizardNewProjectCreationPage) 
			getWizard().getPage(WizardNewMidletSuiteCreationPage.MAIN_PAGE_NAME);
	}
	
	/**
	 * Get the source path for the project taking into account
	 * the new project preferences that the user has specified.
	 * 
	 * 
	 * @param projectPath
	 * @return
	 */
	private IPath getSrcPath(IPath projectPath) {
		IPath srcPath = projectPath;
			
		if (useSourceAndBinaryFolders()) {
			IPreferenceStore store = 
				PreferenceConstants.getPreferenceStore();
			String srcPathName = 
				store.getString(PreferenceConstants.SRCBIN_SRCNAME);
			srcPath = projectPath.append(srcPathName);
		}
		
		return srcPath;
	}
	
	/**
	 * Return an IClasspathEntry for the source path.
	 * 
	 * @param projectPath
	 * @return
	 */
	private IClasspathEntry getSrcPathEntry(IPath projectPath) {
		IPath srcPath = getSrcPath(projectPath);
		
		// Set up exclusions for the verified and deployed directories
		// if the source and project directories are the same
		IPath[] exclusions = null;
		if (srcPath.equals(projectPath)) {
			exclusions = new IPath[3];
			exclusions[0] = new Path(EclipseMECorePlugin.getDeploymentDirectoryName() + "/");
			exclusions[1] = new Path(IEclipseMECoreConstants.TEMP_FOLDER_NAME + "/");
			exclusions[2] = new Path(PreprocessorBuilder.PROCESSED_DIRECTORY + "/");
		} else {
			exclusions = new IPath[0];
		}
		
		return JavaCore.newSourceEntry(srcPath, exclusions);		
	}
	
	/**
	 * Return a boolean indicating whether there will be separate source and
	 * binary folders in the project.
	 * 
	 * @return
	 */
	private boolean useSourceAndBinaryFolders() {
		IPreferenceStore store = PreferenceConstants.getPreferenceStore();
		return store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ);
	}
}

⌨️ 快捷键说明

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