Class WizardModel<T>

java.lang.Object
docking.wizard.WizardModel<T>
Type Parameters:
T - the data object for this wizard
Direct Known Subclasses:
ProjectChooseRepositoryWizardModel, ProjectWizardModel

public abstract class WizardModel<T> extends Object
This is the main class for defining the steps and GUI for a WizardDialog.

A wizard dialog is a dialog that uses multiple input Gui panels to gather all the information required before doing some complex action. Typically, a wizard dialog is used when the user input is best gathered in steps, so as to not overwhelm the user with an overly complex screen. Additionally, the information from one step may determine which follow-on steps are needed.

To create a wizard dialog, the developer needs to create the following:

  1. A class that extends this WizardModel.
  2. One or more classes that extend WizardStep
  3. A data class that holds that data being collected by this wizard.
Subclasses must at a minimum implement two methods.
  1. AddWizardSteps() - This is where the model defines the ordered list of WizardStep for this wizard.
  2. doFinish() - This is where the model should perform the main action of the wizard. This will be called when the user presses the Finish button and all the panels have had a chance to update the wizard data object.
Optionally, there are several additional methods clients may want to override.
  1. dispose() - This will be called when the wizard is completed or cancelled and this is where any cleanup, if any, should be done, including cleaning up the data object if necessary. The super of this method will call dispose on each wizard step, so that won't be necessary as long as this overridden dispose() calls super.dispose();
  2. cancel() - This will only be called if the dialog is cancelled. This is a chance to perform cleanup that should only be done when the operation is cancelled. This is in addition to any cleanup in the dispose() call. This is not normally needed. An example of where this might be useful is suppose the purpose of the wizard is to pick and open two related files. If the wizard completes successfully, then the two files are supposed to remain open after the wizard is closed. However, suppose after one step that opened the first file, the user cancels the operation. Then you would want to close the first file that was opened in this cancelled cancel() call, because you don't want to do it in the dispose() since that will be called even if the wizard completed.
  3. getPreferredSize() - By default, this will return a preferred size that is the biggest width and height of all the preferred sizes of the step panels. Override this to simply specify the preferred size of the dialog.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected T
     
    protected WizardDialog
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    WizardModel(String title, T data)
    Constructor for a wizard model without an icon.
    protected
    WizardModel(String title, T data, Icon wizardIcon)
    Constructor for a wizard model with an icon
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    This method defines the wizard step objects in the order that will be displayed.
    boolean
    Returns true if the cancel button should be enabled.
    protected void
    Subclasses should override this method if they have special cleanup that only needs to be done if the wizard is cancelled.
    boolean
    Returns true if the "Finish" button should be enabled.
    boolean
    Returns true if the "Back" button should be enabled.
    boolean
    Returns true if the "Next" button should be enabled.
    void
    Calls dispose() on all the wizard steps.
    protected abstract boolean
    This method is called when the user presses the "Finish" button and all the steps have completed their apply() methods successfully.
    final void
    Completes the wizard.
    Returns the current WizardStep.
    Returns the data object which is populated by the various wizard steps as they completed.
    Returns the icon for this wizard.
    protected Dimension
    Returns the preferred size of the panels in the wizard dialog.
    Returns the current status message for the wizard.
    Returns the title of this wizard.
    void
    Returns the wizard back to the previous step.
    void
    Advances the wizard to the next step.
    protected void
    setStatusMessage(String statusMessage)
     
    protected void
     
    boolean
    Returns true if the wizard was cancelled.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • data

      protected T data
    • wizardDialog

      protected WizardDialog wizardDialog
  • Constructor Details

    • WizardModel

      protected WizardModel(String title, T data)
      Constructor for a wizard model without an icon.
      Parameters:
      title - the title for the wizard dialog.
      data - the data object that will be used to store wizard data. This will typically be a simple data container designed specifically for this wizard.
    • WizardModel

      protected WizardModel(String title, T data, Icon wizardIcon)
      Constructor for a wizard model with an icon
      Parameters:
      title - the title for the wizard dialog.
      data - the data object that will be used to store wizard data. This will typically be a simple data container designed specifically for this wizard.
      wizardIcon - the icon to display on the wizard
  • Method Details

    • addWizardSteps

      protected abstract void addWizardSteps(List<WizardStep<T>> steps)
      This method defines the wizard step objects in the order that will be displayed.
      Parameters:
      steps - the wizard steps
    • doFinish

      protected abstract boolean doFinish()
      This method is called when the user presses the "Finish" button and all the steps have completed their apply() methods successfully.
      Returns:
      true if the model successfully completes the wizard. If false is returned, the wizard will not be closed.
    • cancel

      protected void cancel()
      Subclasses should override this method if they have special cleanup that only needs to be done if the wizard is cancelled. Otherwise, all cleanup should be done in the dispose() method which is called whether or not the dialog is cancelled.
    • getTitle

      public String getTitle()
      Returns the title of this wizard.
      Returns:
      the title of this wizard
    • getIcon

      public Icon getIcon()
      Returns the icon for this wizard.
      Returns:
      the icon for this wizard
    • getStatusMessage

      public String getStatusMessage()
      Returns the current status message for the wizard.
      Returns:
      the current status message for the wizard
    • finish

      public final void finish()
      Completes the wizard. Gives each remaining panel a chance to validate and populate the data object before calling the doFinish() method where subclasses can do the final task.
    • dispose

      public void dispose()
      Calls dispose() on all the wizard steps. Subclasses can override this to do additional cleanup if needed.
    • getData

      public T getData()
      Returns the data object which is populated by the various wizard steps as they completed.
      Returns:
      the data object
    • wasCancelled

      public boolean wasCancelled()
      Returns true if the wizard was cancelled.
      Returns:
      true if the wizard was cancelled
    • getCurrentStep

      public WizardStep<T> getCurrentStep()
      Returns the current WizardStep.
      Returns:
      the current wizard step
    • canGoBack

      public boolean canGoBack()
      Returns true if the "Back" button should be enabled.
      Returns:
      true if the "Back" button should be enabled
    • canGoNext

      public boolean canGoNext()
      Returns true if the "Next" button should be enabled.
      Returns:
      true if the "Next" button should be enabled
    • canFinish

      public boolean canFinish()
      Returns true if the "Finish" button should be enabled.
      Returns:
      true if the "Finish" button should be enabled
    • canCancel

      public boolean canCancel()
      Returns true if the cancel button should be enabled. The only time this is disabled is when the wizard is performing some expensive operation between steps.
      Returns:
      true if the cancel button should be enabled
    • goBack

      public void goBack()
      Returns the wizard back to the previous step.
    • goNext

      public void goNext()
      Advances the wizard to the next step.
    • getPreferredSize

      protected Dimension getPreferredSize()
      Returns the preferred size of the panels in the wizard dialog. By default the preferred size is the largest size of any panels that have been created at construction time (components are not required to be constructed until they are shown). Subclasses can override this method to just hard code a preferred size for the dialog.
      Returns:
      the preferred size of the panels in the wizard dialog
    • statusChanged

      protected void statusChanged(WizardStep<T> step)
    • setStatusMessage

      protected void setStatusMessage(String statusMessage)