By the way, you can always provide an exit page, which is the only page where finish is allowed (a sort of 'Thank you, please enjoy' page).
I included a small example, there are still bugs in it, but you'll get the picture:
Code:
import org.springframework.binding.validation.ValidationListener;
import org.springframework.binding.validation.ValidationResults;
import org.springframework.binding.validation.support.RulesValidator;
import org.springframework.core.io.AbstractResource;
import org.springframework.richclient.application.setup.SetupWizard;
import org.springframework.richclient.command.ActionCommandExecutor;
import org.springframework.richclient.form.AbstractForm;
import org.springframework.richclient.form.FormModelHelper;
import org.springframework.richclient.form.builder.TableFormBuilder;
import org.springframework.richclient.wizard.AbstractWizardPage;
import org.springframework.richclient.wizard.FormBackedWizardPage;
import org.springframework.richclient.wizard.WizardDialog;
import org.springframework.richclient.dialog.DialogPage;
import org.springframework.rules.Rules;
import org.springframework.rules.factory.Constraints;
import org.springframework.rules.support.DefaultRulesSource;
import javax.swing.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.beans.PropertyChangeEvent;
public class MySetupWizard extends SetupWizard implements ActionCommandExecutor
{
private ExtraPage extraPage;
private LastPage lastPage;
private WizardDialog dialog;
public MySetupWizard()
{
extraPage = new ExtraPage(this);
lastPage = new LastPage();
addPages();
setLicenseTextLocation(new LicenseResource());
addPage(extraPage);
addPage(lastPage);
}
public boolean canFinish()
{
return dialog.getCurrentPage().getId().equals("lastPage");
}
public void execute()
{
if (dialog == null)
{
dialog = new WizardDialog(this);
}
dialog.showDialog();
}
public WizardDialog getDialog()
{
return dialog;
}
class LicenseResource extends AbstractResource
{
public String getDescription()
{
return "license";
}
public InputStream getInputStream() throws IOException
{
return new StringBufferInputStream("some license text");
}
}
class ExtraPage extends FormBackedWizardPage
{
private boolean ready;
public ExtraPage(final MySetupWizard wizard)
{
super(new ExtraForm());
getBackingForm().addValidationListener(new ValidationListener()
{
public void validationResultsChanged(ValidationResults results)
{
boolean oldReady = ready;
ready = !results.getHasErrors();
try {
wizard.getDialog().propertyChange(new PropertyChangeEvent(this, DialogPage.PAGE_COMPLETE_PROPERTY, oldReady, ready));
} catch(NullPointerException ex)
{
// could happen, ignore
}
}
});
}
public void setReady(boolean ready)
{
this.ready = ready;
}
public boolean isPageComplete()
{
return ready;
}
}
class LastPage extends AbstractWizardPage
{
protected LastPage()
{
super("lastPage");
}
protected JComponent createControl()
{
return new JLabel("Congratulations, enjoy the product!");
}
public boolean canFlipToNextPage()
{
return false;
}
}
class ExtraForm extends AbstractForm
{
public ExtraForm()
{
super(FormModelHelper.createFormModel(new ExtraObject(), "extraForm"));
DefaultRulesSource source = new DefaultRulesSource();
Rules rules = new Rules(ExtraObject.class);
Constraints c = new Constraints();
rules.add("configOne", c.required());
rules.add("configTwo", c.required());
source.addRules(rules);
getFormModel().setValidator(new RulesValidator(getFormModel(), source));
}
protected JComponent createFormControl()
{
TableFormBuilder builder = new TableFormBuilder(getBindingFactory());
builder.add("configOne");
builder.add("configTwo");
return builder.getForm();
}
}
class ExtraObject
{
private String configOne;
private String configTwo;
public String getConfigOne()
{
return configOne;
}
public void setConfigOne(String configOne)
{
this.configOne = configOne;
}
public String getConfigTwo()
{
return configTwo;
}
public void setConfigTwo(String configTwo)
{
this.configTwo = configTwo;
}
}
}
Just do
Code:
new MySetupDialog().execute();
to show the dialog.
Greetingz,
Lieven