Today I will go into a problem with update buttons in a
WizardDialog
that I fixed today and thought maybe it would be useful to share with others.==Problem==
In my project, I need to show a
WizardDialog
that contains two WizardPages
. However, in Eclipse's architecture, a [http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/wizard/WizardDialog.html WizardDialog] object does not directly control the pages it shows. It manages the pages through the [http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/wizard/Wizard.html Wizard] object. In fact, the [http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/wizard/Wizard.html Wizard] object controls the transitions between pages and the completion of the WizardDialog
. WizardPage
objects are added to the Wizard
, not WizardDialog
.Well that is simple enough...something that you can find out with [http://help.eclipse.org/help32/index.jsp Eclipse Help], so what makes you keep reading all the nonsense?
Please be patient and let me explain
Well, my problem is, I want to add a
WizardPage
that contains two checkboxes, such that:* If checkbox A (''Apply filter for isomorphic snippet of the selected cluster'') is checked, the
Wizard
can be completed (by setting WizardPage.setPageComplete(true)
such that the Wizard
can finish up and the '''Finish''' button is enabled.* If checkbox B (''Apply statement aggregation to non-consecutive isomorphic clusters'') is checked, then, depending if checkbox A is checked also, the '''Next''' button can be enabled as well.
[[Image:Ce-screenshot1.png| AnalyzeClusterWizardPage |500px]]
The problem is, I didn't know update the buttons such that, if checkbox B is unchecked, then the '''Next''' button is disabled, but if checkbox A is unchecked, both buttons should be disabled.
==Solution==
Calls
WizardDialog.updateButtons()
to refresh the status of the dialog buttons inside a WizardPage
==Details Solution==
I always run into the problems when I started unchecking the checkboxes. For instance, if I unchecked checkbox A and then checked it again, the ''Next'' botton does not always get enabled.
I tried various methods by modifying
SelectionListener
of checkbox B but no avail:
fReaggregateCheckbox.addSelectionListener( new SelectionAdapter() {
public void widgetSelected(SelectionEvent e)
{
if ( isPageCompleted()) {
isNonconsecutiveRefactored = ((Button)e.widget).getSelection();
canFlipToNextPage();
}
}
});
...
public boolean canFlipToNextPage()
{
return super.canFlipToNextPage() && isNonconsecutiveRefactored;
}
Well the problem is, I did not know where how to enable/disable the '''Next''' button in the
WizardDialog
, and I assumed that the calling canFlipToNextPage()
will automatically enable the '''Next''' button since the first click always works.Luckily, Eclipse provides source code, so with several F3 and Ctrl-Alt-H, I discovered that
IWizardPage.canFlipToNextPage()
is usually called by WizardDialog.updateButtons()
! So WizardDialog.updateButtons()
is the master control of the buttons in the dialog!So I modifided the
SelectionListener
of the checkbox:
fReaggregateCheckbox.addSelectionListener( new SelectionAdapter() {
public void widgetSelected(SelectionEvent e)
{
isNonconsecutiveRefactored = ((Button)e.widget).getSelection();
getContainer().updateButtons();
}
});
And now everywork works perfectly :)
No comments:
Post a Comment