Search code examples
javaeclipsercp

Update buttons of org.eclipse.jface.wizard.WizardDialog


I know I could use createButtonsForButtonBar() to add/remove the new buttons for WizardDialog when invoking the dialog. However, I would like the buttons of dialog could change according to the current displayed WizardPage.

For example, for page1, I have one new button called "edit". For page2, I have one new button called "move". "edit" should not be displayed when page2 is shown and "move" should be not be displayed when page1 is shown. Any hints about how could I achieve this? Thank you.


Solution

  • createButtonsForButtonBar uses GridLayout to layout the buttons with GridData set for each button. So should be able to use the GridData.exclude flag to exclude buttons for the layout.

    To stop displaying a button use something like:

    Button button = getButton(button id);
    GridData data = (GridData)button.getLayoutData();
    data.exclude = true;
    button.setVisible(false);
    

    You will then have to call layout(true) on the button bar composite. You may also have to adjust the numColumns field of the GridLayout for the button bar composite.

    You could do this in the setVisible method of the wizard pages.