使用Eclipse向导进行快速开发

http://tech.ddvip.com   2007年08月18日    社区交流

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

  必须先在文件的顶部声明新控件和其他控件,然后才可以将新控件添加到此方法中。

  清单 9. 声明新控件public class NewXHTMLFileWizardPage extends WizardPage {
/* Newly added for the page title */
  private Text titleText;
  // the rest of the class...  
}

  现在添加文本的 getter。NewXHTMLFileWizard 类将在构建新文件时使用此 getter。getTitle() 方法如下所示:

  清单 10. getTitle() 方法  /**
   * Gets the HTML title for the new file
   */
  public String getTitle() {
    return titleText.getText();
  }

  修改 createControl() 方法以添加标题的新输入控件和标签。新代码如下所示:

  清单 11. 修改后的 createControl() 方法  /**
   * @see IDialogPage#createControl(Composite)
   */
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 3;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText("&Container:");
    containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    containerText.setLayoutData(gd);
    containerText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        dialogChanged();
      }
    });
    Button button = new Button(container, SWT.PUSH);
    button.setText("Browse...");
    button.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        handleBrowse();
      }
    });
    label = new Label(container, SWT.NULL);
    label.setText("&File name:");
    fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fileText.setLayoutData(gd);
    fileText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        dialogChanged();
      }
    });
   
      
    /* Need to add empty label so the next two controls
     * are pushed to the next line in the grid. */
    label = new Label(container, SWT.NULL);
    label.setText("");
    
    /* Adding the custom control here */
    
    label = new Label(container, SWT.NULL);
    label.setText("&Title:");
    
    titleText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    titleText.setLayoutData(gd);
    titleText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        dialogChanged();
      }
    });
        
    /* Finished adding the custom control */
    
    initialize();
    dialogChanged();
    setControl(container);
  }

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

正在加载评论...