你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / Linux开发
使用Eclipse向导进行快速开发(8)
 

清单 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)

  推荐精品文章

·2024年12月目录 
·2024年11月目录 
·2024年10月目录 
·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089