使用Eclipse向导进行快速开发

豆豆网   技术应用频道   2007年08月18日  【字号: 收藏本文

内容摘要:Eclipse 框架和集成开发环境 (IDE) 的最优秀特性之一是可扩展性。在本文中,您将了解如何快速构建用于自动完成添加新文件过程的向导。由于可以预定义文件的内容,因此向导通过提供一致性和自动化使您可以更好地进行开发。

  addPages() 方法

  addPages() 方法将把页面添加到向导中。清单 2 中所示的方法将把单个页面添加到向导 NewXHTMLFileWizardPage 中。

  清单 2. addPages() 方法将把页面添加到向导中  /**
   * Adding the page to the wizard.
   */
  public void addPages() {
    page = new NewXHTMLFileWizardPage(selection);
    // You can add more pages here...
    addPage(page);
  }

  NewXHTMLFileWizardPage 类包含为用户提供指定页面名称功能的控件。您可以稍后把控件添加到页面中,使最终用户可以输入更多信息。

  performFinish() 方法

  当用户单击向导中的 Finish 按钮时将调用 performFinish() 方法。在执行一些检查之后,它将使用 IRunnableWithProgress 接口调用 doFinish() 方法。使用此接口意味着在执行 doFinish() 方法时(在本例中需要花很长时间运行)不必编写显示进度条的所有 UI 元素。下面完整地列出了该方法。

  清单 3. performFinish() 方法  /**
   * This method is called when 'Finish' button is pressed in
   * the wizard. We will create an operation and run it
   * using wizard as execution context.
   */
  public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String fileName = page.getFileName();
    IRunnableWithProgress op = new IRunnableWithProgress() {
      public void run(IProgressMonitor monitor) throws InvocationTargetException {
        try {
          doFinish(containerName, fileName, monitor);
        } catch (CoreException e) {
          throw new InvocationTargetException(e);
        } finally {
          monitor.done();
        }
      }
    };
    try {
      getContainer().run(true, false, op);
    } catch (InterruptedException e) {
      return false;
    } catch (InvocationTargetException e) {
      Throwable realException = e.getTargetException();
      MessageDialog.openError(getShell(), "Error", realException.getMessage());
      return false;
    }
    return true;
  }

来源:ibm    作者:Nathan A. Good    责编:豆豆技术应用

正在加载评论...