Eclipse RCP / JFace Wizard - How to programmatically force wizardDialog to close from wizardPage

I have a WizardDialog / Wizard and the content is a WizardPage. Suppose I am doing something inside the page, and when some error occurs, I pop up with a MessageBox and after clicking OK I want to force close wizardDialog.

Wrong way:

getShell().dispose; 

because SWT throws and excludes:

 !ENTRY org.eclipse.ui 4 0 2013-08-20 14:15:13.353 !MESSAGE Unhandled event loop exception !STACK 0 org.eclipse.swt.SWTException: Widget is disposed 

Instead, when I call:

 getWizard().performCancel(); 

He does not do anything.

How to force to close the Wizard without exception SWT?

+4
source share
5 answers

You must use the close method in the wizard's dialog box. To call it from the wizard page, I suggest you make a callback interface and pass it to the page. Something like that:

 final YourWizard wizard = new YourWizard (); WizardDialog wizardDialog = new WizardDialog(shell, wizard); wizard.setErrorhandler(new YourCustomErrorHandlerInterface() { @Override public void onError() { wizardDialog.close(); } }); wizardDialog .open(); 

After creating the wizard page, you will go to it on your computer. And when an error occurs, just call the YourCustomErrorHandlerInterface # onError method, which the wizard closes.

Hope this helps.

+4
source

In my case, the only option that worked was:

 getShell().setVisible(false); 
+1
source

It worked for me.

  // fatal error situation detected on a wizard page MessageDialog.openError(getShell(), "Error", "Wizard cannot continue and will now exit."); getWizard().getContainer().getShell().close(); 
+1
source

The Wizard implementation of this IWizard method uses all page controls using DialogPage.dispose.

Subclasses should propagate this method if the wizard instance supports an additional SWT resource that must be removed.

(Javadoc)

So, when you install the dialog, the pages after the current page are not visible (I think) and load, so Wizard.close() matters (the same for Wizard.getShell().close() , I think). The executeCancel method must be implemented by MyWizard to determine what should be done after the user clicks cancel, but is not specified in the Wizard. It is called by the master after the user click is canceled. For instance:

 void close(){ dosmthng performCancel(); dispose(); } 

In fact, this is the equivalent for the performFinish () function, but with the button canceled. I hope I get it.

Maybe setVisible(false) should work.

0
source

I think you are using the cancelPressed() method in WizardDialog to close the wizard dialog

 BaseWizard baseWizard=new BaseWizard(); BaseWizardDialog baseWizardDialog=new BaseWizardDialog(getShell(),baseWizard); baseWizard.setBaseWizardDialog(baseWizardDialog); baseWizardDialog.open(); public class BaseWizard extends Wizard { private BaseWizardDialog baseWizardDialog=null; private BaseWizardPage baseWizardPage; public BaseWizard() { super(); setWindowTitle("My Wizard"); baseWizardPage=new BaseWizardPage(); } public void setBaseWizardDialog(BaseWizardDialog baseWizardDialog) { this.baseWizardDialog = baseWizardDialog; baseWizardPage.setBaseWizardDialog(this.baseWizardDialog); } public BaseWizardDialog getBaseWizardDialog() { return baseWizardDialog; } } public class BaseWizardPage extends WizardPage { public void createControl(Composite parent) { private BaseWizardDialog baseWizardDialog=null; public void setBaseWizardDialog(BaseWizardDialog baseWizardDialog) { this.baseWizardDialog = baseWizardDialog; } public BaseWizardDialog getBaseWizardDialog() { return baseWizardDialog; } 

create the first control and when you want to close the dialog just write cancel click

 if(ConditiontoClose==true) getBaseWizardDialog().cancelPressed(); } } 
0
source

Source: https://habr.com/ru/post/1497995/


All Articles