| MultiPathModels are built from a joined set of
Path Paths that each contain one or more
WizardStep WizardSteps . Two types of
Path are available,
SimplePath and
BranchingPath . The paths must be fully constructed before the model is instantiated.
// Construct each of the paths involved in the wizard.
BranchingPath firstPath = new BranchingPath();
SimplePath optionalPath = new SimplePath();
SimplePath lastPath = new SimplePath();
firstPath.addStep(stepOne);
firstPath.addStep(stepTwo);
optionalPath.addStep(optionalStepOne);
optionalPath.addStep(optionalStepTwo);
optionalPath.addStep(optionalStepThree);
lastPath.addStep(lastStep);
// Now bind all the paths together, first the branching path then the optional path.
// add the optional path and the condition that determines when it should be followed
firstPath.addBranch(optionalPath, new Condition() {
public boolean evaluate(WizardModel model) {
return ((MyModel)model).includeOptional();
}
});
// add the end path and the condition that determines when it should be followed
firstPath.addBranch(lastPath, new Condition() {
public boolean evaluate(WizardModel model) {
return !((MyModel)model).includeOptional();
}
});
// the optional path proceeds directly to the lastPath
optionalPath.setNextPath(lastPath);
// Now create the model and wizard.
MultiPathModel model = new MultiPathModel(firstPath);
Wizard wizard = new Wizard(model);
During the initialization the wizard will scan all the paths to determine the ending path. The
end path is an instance of
SimplePath that is reachable from the
MultiPathModel.getFirstPath firstPath and for whom
SimplePath.getNextPath returns null. If no
matching path is found or more than one is found the model will throw an exception.
|