org.pietschy.wizard.models
Class DynamicModel

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

public class DynamicModel
extends AbstractWizardModel

The DynamicModel is very similar to the static model, except that steps can be dynamically removed from the wizard flow.

 // create a subclass of DynamicModel
 MyDynamicModel model = new MyDynamicModel();

 // add the first step..
 model.add(new MyFirstStep());

 // add an optional step..
 model.add(new MyOptionalStep(), new Condition()
 {
    public boolean evaluate(WizardModel model)
    {
        return ((MyDynamicModel) model).isOptionalRequired();
    }
 });

 // add the last step.
 model.add(new MyLastStep());

 // now create the wizard and use it..
 Wizard wizard = new Wizard(model);
 
It is also worth noting that steps that implement Condition can be added using the basic add(WizardStep) and the model will automatically add them as an optional step.

See Also:
add(WizardStep), add(WizardStep, Condition)

Field Summary
static Condition TRUE_CONDITION
          An implementation of Condition that always returns true.
 
Constructor Summary
DynamicModel()
          Creates a new DynamicModel.
 
Method Summary
 void add(WizardStep step)
          Adds the next step to the wizard.
 void add(WizardStep step, Condition condition)
          Adds an optional step to the model.
 boolean allStepsComplete()
          Returns true if all included steps in the wizard return true from WizardStep.isComplete().
 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()
          Forces the model to re-evaluate it's current state.
 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
 

Field Detail

TRUE_CONDITION

public static final Condition TRUE_CONDITION
An implementation of Condition that always returns true.

Constructor Detail

DynamicModel

public DynamicModel()
Creates a new DynamicModel.

Method Detail

add

public void add(WizardStep step)
Adds the next step to the wizard. If the WizardStep implements Condition, then this method is equivalent to calling add(step, (Condition)step), other wise it is equivalent to calling add(step, TRUE_CONDITION).

This allows the easy use of WizardSteps that determine the condition under which they are displayed.

Parameters:
step - the step to added.

add

public void add(WizardStep step,
                Condition condition)
Adds an optional step to the model. The step will only be displayed if the specified condition is met.

Parameters:
step - the WizardStep to add.
condition - the Condition under which it should be included in the wizard.

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()
Forces the model to re-evaluate it's current state. This method will re-evalute the conditional steps by calling Condition.evaluate(org.pietschy.wizard.WizardModel).

Subclasses that override this method must be sure to invoke super.refreshModelState().

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

allStepsComplete

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

Please note that this method ignores all steps for which their Condition returns false.

Returns:
true if all the visible 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


Copyright © 2004 Andrew Pietsch.