简体   繁体   English

如何在按下后退按钮时清除jface向导中的字段

[英]how to clear the fields in a jface Wizard on pressing the back button

I have created a JFace wizard PCWizard extending Wizard and have four pages PCPageOne , PCPageTwo , PCPageThree and PCPageFour extending WizardPage . 我创建了一个JFace向导PCWizard扩展Wizard并有四页PCPageOnePCPageTwoPCPageThreePCPageFour扩展WizardPage

  1. When I reach the last page I want the back and cancel button disabled. 当我到达最后一页时,我希望后退和取消按钮被禁用。
  2. when I press the back button on other pages I want the data in the widgets of the page to get cleared and when I press next again I want the text fields to be empty so that the next button doesn't get activated . 当我按下其他页面上的后退按钮时,我希望清除页面小部件中的数据,当我再次按下时,我希望文本字段为空,以便下一个按钮不会被激活。

I have also captured the data collected in another class, if u want me to override the WizardDialog class and do the action how do I do it . 我还捕获了在另一个类中收集的数据,如果你想让我覆盖WizardDialog类并执行操作我该怎么做。 I'm new to java and SWT a more elaborate explanation would be fine.Thanx in advance 我是java和SWT的新手,更精细的解释会很好。提前做好准备

To disable the back button do the following in the last page: 要禁用后退按钮,请在最后一页中执行以下操作:

@Override
public IWizardPage getPreviousPage() {
    // prevent going back
    return null;
}

Also clearing the input in pages might be done in a IPageChangedListener : 清除页面中的输入也可以在IPageChangedListener完成:

WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
dialog.addPageChangedListener(new IPageChangedListener() {
    public void pageChanged(PageChangedEvent event) {
        // this is just a suggestion..
        IClearablePage page = (IClearablePage)event.getSelectedPage();
        page.clear();
    }
});

Where IClearablePage is your own interface with a clear() , and all your pages implement IClearablePage . 其中IClearablePage是您自己的带有clear()的接口,并且您的所有页面都实现了IClearablePage

EDIT: override setVisible as greg stated in his answer is probably more convenient. 编辑:覆盖setVisible因为greg在他的回答中说明可能更方便。

Override the WizardPage setVisible method to clear fields when the page becomes active: 当页面变为活动状态时,覆盖WizardPage setVisible方法以清除字段:

@Override
public void setVisible(final boolean visible)
{
  super.setVisible(visible);

  if (visible) {
    // TODO clear your fields
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM