Eclipse JFace的向导 [英] Eclipse JFace's Wizards

查看:117
本文介绍了Eclipse JFace的向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个向导,第二页内容取决于第一页的选择。第一页向用户询问他想要创建的过滤器的种类,第二个请求用户创建一个所选种的过滤器实例。



JFace的向导页面内容(createControl(...)方法)都是在向导打开时创建的,而不是当给定的页面显示时(这允许JFace知道向导大小我猜)??



正因为如此,我必须在向导打开之前创建我的第二页内容,但是由于第二页的内容取决于第一页选择,所以我不能。



现在,我找到的更清洁的解决方案是在向导打开之前创建所有(秒)页面(包含其内容),并在第一页的实现中覆盖getNextPage()方法。



该解决方案的主要缺点是,创建多个第二页时可能会很昂贵。



<你对这个解决方案有什么看法?你如何管理你的向导页面?有没有更清洁的解决方案我错过了?

解决方案

b
$ b


  • 与另一个完全不同的

  • 取决于之前的页面中的以前的选择



然后你可以动态添加下一页(也作为这里描述



但是,如果你只有一个动态内容的下一页,你应该可以在 onEnterPage()方法

  public void createControl(Composite parent)
{
//
//创建e复合保存小部件
//
this.composite = new Composite(parent,SWT.NONE);

//
//为此向导页创建所需的布局
//
GridLayout layout = new GridLayout();
layout.numColumns = 4;
this.composite.setLayout(layout);

//将复合作为此页面的控件设置
setControl(this.composite);
}

void onEnterPage()
{
final MacroModel model =((MacroWizard)getWizard())。
String selectedKey = model.selectedKey;
String [] attrs =(String [])model.macroMap.get(selectedKey); (int i = 0; i< attrs.length; i ++)


{
String attr = attrs [i];
标签label = new Label(this.composite,SWT.NONE);
label.setText(attr +:);

new Text(this.composite,SWT.NONE);
}
pack();
}

如eclipse角落文章创建JFace向导



我们可以通过覆盖任何向导页面的getNextPage方法来更改向导页面的顺序。在离开页面之前,我们在模型中保存用户选择的值。在我们的示例中,根据旅行的选择,用户接下来将看到带有航班的页面或乘车前往的页面。

  public IWizardPage getNextPage(){
saveDataToModel();
if(planeButton.getSelection()){
PlanePage page =((HolidayWizard)getWizard())。planePage;
page.onEnterPage();
返回页面;
}
//根据所选按钮返回下一页
if(carButton.getSelection()){
return((HolidayWizard)getWizard())。
}
返回null;
}

我们定义一个方法来为 PlanePage onEnterPage(),我们在移动到 PlanePage ,即在 getNextPage()方法的第一页


I need a wizard which second page content depends on the first page's selection. The first page asks the user the "kind" of filter he wants to create and the second one asks the user to create one filter instance of the selected "kind".

JFace's wizards pages contents (createControl(...) method) are all created when the wizard is open and not when a given page is displayed (this allow JFace to know the wizard size I guess ??).

Because of this, I have to create my second page content BEFORE the wizard is opened BUT I can't since the second page's content depends on the first page selection.

For now the cleaner solution I found consists in creating all (seconds) pages before the wizard is open (with their content) and override the getNextPage() method in the first page's implementation.

The main drawback of that solution is that it can be be expensive when there are many second pages to create.

What do you think about that solution ? How do you manage your wizard's pages ? Is there any cleaner solution I missed ?

解决方案

The approach is right if you are several other pages which are

  • completely different one with another
  • depends on the previous choices made in a previous page

Then you can add the next page dynamically (also as described here)

But if you have just a next page with a dynamic content, you should be able to create that content in the onEnterPage() method

public void createControl(Composite parent)
{
    //
    // create the composite to hold the widgets
    //
    this.composite = new Composite(parent, SWT.NONE);

    //
    // create the desired layout for this wizard page
    //
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    this.composite.setLayout(layout);

    // set the composite as the control for this page
    setControl(this.composite);
}

void onEnterPage()
{
    final MacroModel model = ((MacroWizard) getWizard()).model;
    String selectedKey = model.selectedKey;
    String[] attrs = (String[]) model.macroMap.get(selectedKey);

    for (int i = 0; i < attrs.length; i++)
    {
        String attr = attrs[i];
        Label label = new Label(this.composite, SWT.NONE);
        label.setText(attr + ":");

        new Text(this.composite, SWT.NONE);
    }
    pack();
}

As shown in the eclipse corner article Creating JFace Wizards:

We can change the order of the wizard pages by overwriting the getNextPage method of any wizard page.Before leaving the page, we save in the model the values chosen by the user. In our example, depending on the choice of travel the user will next see either the page with flights or the page for travelling by car.

public IWizardPage getNextPage(){
   saveDataToModel();       
   if (planeButton.getSelection()) {
       PlanePage page = ((HolidayWizard)getWizard()).planePage;
     page.onEnterPage();
       return page;
   }
   // Returns the next page depending on the selected button
   if (carButton.getSelection()) { 
    return ((HolidayWizard)getWizard()).carPage;
   }
   return null;
}

We define a method to do this initialization for the PlanePage, onEnterPage() and we invoke this method when moving to the PlanePage, that is in the getNextPage() method for the first page.

这篇关于Eclipse JFace的向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆