org.pietschy.wizard.models
Class MultiPathModel

java.lang.Object
  extended byorg.pietschy.wizard.AbstractWizardModel
      extended byorg.pietschy.wizard.models.MultiPathModel
All Implemented Interfaces:
WizardModel

public class MultiPathModel
extends AbstractWizardModel

MultiPathModels are built from a joined set of Paths that each contain one or more 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 firstPath and for whom SimplePath.getNextPath(org.pietschy.wizard.models.MultiPathModel) returns null. If no matching path is found or more than one is found the model will throw an exception.


Constructor Summary
MultiPathModel(Path firstPath)
          Creates a new MultiPathModel.
 
Method Summary
 boolean allStepsComplete()
          Returns true if all the steps in the wizard return true from WizardStep.isComplete().
 Path getFirstPath()
           
 Path getLastPath()
           
protected  Path getPathForStep(WizardStep step)
           
 boolean isLastStep(WizardStep step)
          Checks if the specified step is the last step in the wizard.
 void lastStep()
          Takes the model to the last step in the wizard and fires the appropriate property change events.
 void nextStep()
          Increments the model the the next step and fires the appropriate property change events.
 void previousStep()
          Takes the model back to the previsou step and fires the appropriate property change events.
 void refreshModelState()
          This is an empty method that is intended for subclasses to override to update their various properties based on the active step.
 void reset()
          Takes the model back to the first step and fires the appropriate property change events.
 java.util.Iterator stepIterator()
          Returns an iterator over all the steps in the model.
 
Methods inherited from class org.pietschy.wizard.AbstractWizardModel
addCompleteListener, addPropertyChangeListener, addPropertyChangeListener, getActiveStep, isLastAvailable, isLastVisible, isNextAvailable, isPreviousAvailable, removePropertyChangeListener, removePropertyChangeListener, setActiveStep, setCancelAvailable, setLastAvailable, setLastVisible, setNextAvailable, setPreviousAvailable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiPathModel

public MultiPathModel(Path firstPath)
Creates a new MultiPathModel. The paths must be full constructed and linked before the this constructor is called.

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 firstPath and for whom SimplePath.getNextPath(org.pietschy.wizard.models.MultiPathModel) returns null. If no matching path is found or more than one is found the model will throw an exception.

Parameters:
firstPath - the starting path of the model. The paths must be populated with their steps and be linked before the this constructor is called.
Method Detail

getFirstPath

public Path getFirstPath()

getLastPath

public Path getLastPath()

nextStep

public void nextStep()
Description copied from interface: WizardModel
Increments the model the the next step and fires the appropriate property change events. This method must only be called if WizardModel.isNextAvailable() returns true.


previousStep

public void previousStep()
Description copied from interface: WizardModel
Takes the model back to the previsou step and fires the appropriate property change events. This method must only be called if WizardModel.isPreviousAvailable() returns true.


lastStep

public void lastStep()
Description copied from interface: WizardModel
Takes the model to the last step in the wizard and fires the appropriate property change events. This method must only be called if WizardModel.isLastAvailable() returns true.


reset

public void reset()
Description copied from interface: WizardModel
Takes the model back to the first step and fires the appropriate property change events.


isLastStep

public boolean isLastStep(WizardStep step)
Description copied from interface: WizardModel
Checks if the specified step is the last step in the wizard.

Parameters:
step - the step to check
Returns:
true if its the final step in the wizard, false otherwise.

refreshModelState

public void refreshModelState()
Description copied from class: AbstractWizardModel
This is an empty method that is intended for subclasses to override to update their various properties based on the active step.

Specified by:
refreshModelState in interface WizardModel
Overrides:
refreshModelState in class AbstractWizardModel

allStepsComplete

public boolean allStepsComplete()
Returns true if all the steps in the wizard return true from WizardStep.isComplete(). This is primarily used to determine if the last button can be enabled.

Returns:
true if all the steps in the wizard are complete, false otherwise.

stepIterator

public java.util.Iterator stepIterator()
Description copied from interface: WizardModel
Returns an iterator over all the steps in the model. The iteration order is not guarenteed to the be the order of traversal.

Returns:
an iterator over all the steps of the model

getPathForStep

protected Path getPathForStep(WizardStep step)


Copyright © 2004 Andrew Pietsch.