简体   繁体   中英

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 .

  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 . I'm new to java and SWT a more elaborate explanation would be fine.Thanx in advance

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 :

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 .

EDIT: override setVisible as greg stated in his answer is probably more convenient.

Override the WizardPage setVisible method to clear fields when the page becomes active:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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