清单 16. NewSiteProjectWizard 类import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.net.URI; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; public class NewSiteProjectWizard extends Wizard implements INewWizard, IExecutableExtension { /* * Use the WizardNewProjectCreationPage, which is provided by the Eclipse * framework. */ private WizardNewProjectCreationPage wizardPage; private IConfigurationElement config; private IWorkbench workbench; private IStructuredSelection selection; private IProject project; /** * Constructor */ public NewSiteProjectWizard() { super(); } public void addPages() { // snipped... } @Override public boolean performFinish() { // snipped... } /** * This creates the project in the workspace. * * @param description * @param projectHandle * @param monitor * @throws CoreException * @throws OperationCanceledException */ void createProject(IProjectDescription description, IProject proj, IProgressMonitor monitor) throws CoreException, OperationCanceledException { // snipped... } /* * (non-Javadoc) * * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, * org.eclipse.jface.viewers.IStructuredSelection) */ public void init(IWorkbench workbench, IStructuredSelection selection) { // snipped... } /** * Sets the initialization data for the wizard. */ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { // snipped... } /** * Adds a new file to the project. * * @param container * @param path * @param contentStream * @param monitor * @throws CoreException */ private void addFileToProject(IContainer container, Path path, InputStream contentStream, IProgressMonitor monitor) throws CoreException { // snipped } }
修改 plugin.xml
在添加新类之后在 Eclipse 中将其作为向导执行之前,需要对位于项目库中的 plugin.xml 文件进行一些更改。
清单 17. plugin.xml 文件<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> <extension point="org.eclipse.ui.newWizards"> <category name="Example.com Enterprise Templates" id="ExampleWizard"> </category> <wizard name="Example.com Static Web Page" icon="icons/sample.gif" category="ExampleWizard" class="com.example.eclipse.wizards.NewXHTMLFileWizard" id="com.example.eclipse.wizards.NewXHTMLFileWizard"> </wizard> <wizard category="ExampleWizard" class="com.example.eclipse.wizards.NewSiteProjectWizard" icon="icons/sample.gif" id="com.example.eclipse.wizards.NewSiteProjectWizard" name="Example.com Static Web Site" project="true"> </wizard> </extension> </plugin>
(编辑:aniston)
|