不過還有另外一個問題沒有解決,就是如果我現在一個Wizard中有a,b兩個WizardPage,目前我停留在b WizardPage中,我現在點擊back回到a WizardPage中,然后對內容做了修改,此次我希望再回到b WizardPage的時候,里面的內容也同時跟著發生改變,但是僅僅是復寫Wizard的createPageControls()方法是無法實現,我們通過查看源代碼,發現在org.eclipse.jface.wizard.WizardDialog.updateForPage(IWizardPage page)中:
java 代碼
- private void updateForPage(IWizardPage page) {
- // ensure this page belongs to the current wizard
- if (wizard != page.getWizard()) {
- setWizard(page.getWizard());
- }
- // ensure that page control has been created
- // (this allows lazy page control creation)
- if (page.getControl() == null) {
- page.createControl(pageContainer);
- // the page is responsible for ensuring the created control is accessable
- // via getControl.
- Assert.isNotNull(page.getControl());
- // ensure the dialog is large enough for this page
- updateSize(page);
- }
- // make the new page visible
- IWizardPage oldPage = currentPage;
- currentPage = page;
- currentPage.setVisible(true);
- if (oldPage != null) {
- oldPage.setVisible(false);
- }
- // update the dialog controls
- update();
- }
也就是在調用WizardPage的createControl()方法之前要做一個判斷page.getControl() == null,因此我們只要將想辦法在調轉到某個WizardPage的時候,將其control設置為null就可以了.于是我們在a WizardPage中引起b WizardPage的內容發生改變的方法中添加如下代碼:
java 代碼
- // 對參數頁必須重繪
- IWizardPage page = getNextPage();
- if (page.getControl() != null)
- page.dispose();
然后復寫b WizardPage的dispose方法:
java 代碼
- public void dispose() {
- super.dispose();
- setControl(null);
- }
這樣我們就大功告成了.
安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢】