When to use WizardPageSupport: probably never (#Eclipse #JFace)

Admitted, what Lars Vogel shows in his tutorial looks tempting: Provide neat error messages in Eclipse Wizards using data binding.  But as so often (unfortunately), the code is half-baked, and therefore barely usable.  Data Binding works fine, but Validation, as described, sucks.

In this particular case, WizardPageSupport works well if you have Widgets that can be validated individually: For instance, making sure that an Email field contains emails.  But it breaks down, as soon as the validation takes multiple Widgets into account. Consider an Address field, for instance, where City and Zip Code (and many other fields) have co-dependencies.  Setting the the Zip code should clear the error message on the City, but I have not seen a straight forward way of doing this.

So I dropped WizardPageSupport altogether, and instead added a page-specific validation method to my model.  Then I added a listener to call the validation when anything changes:

public class Page1 extends WizardPage {     public Page1() {         ...         model.addPropertyChangeListener(new PropertyChangeListener() {             @Override             public void propertyChange(PropertyChangeEvent evt) {                 IStatus status = model.validatePage1();                 setMessage(status.getMessage(), status.getSeverity());             }         });     }     ... } 

And ironically, my code got shorter and cleaner, compared to using WizardPageSupport.  Frustrating, as the idea behind this class is neat.

Similar Posts