Chapter 13: The Wizard Control, from Enterprise Curl, by Prentice Hall | 3 | WebReference

Chapter 13: The Wizard Control, from Enterprise Curl, by Prentice Hall | 3

Enterprise Curl: The Wizard Control

commit-return-message

The {commit-return-message} method is executed when the user is on the last WizardForm page and clicks the Next button, which in this state would be labeled Finish. The purpose of this method is to get all the values the user has selected on each of the WizardForm pages and return them to the calling process in a single StringBuf reference. The code for the {commit-return-message} method is shown in Figure 13–4.

We use the container loop {for} style to iterate through all the WizardForm pages contained in the self.pages variable. Because self.pages has been declared as allowing nulls, we use the {non-null} primitive to trick the complier into accepting the variable, as we know at runtime that it will contain a valid value. On each page, it executes the {commit-return-value} method, which we will see in Chapter 14 is overridden at the descendents to extract the correct value from the page and set it within a class variable. It then calls the {get-return-value} method on the WizardForm page and concatenates the value in a class variable called return-data.

FIGURE 13–4 WizardControl.commit-return-message code listing.

set-wizard-form

The {set-wizard-form} method is executed when the user clicks either the Back or Next button, or when the WizardControl is first instantiated. The purpose is to display the appropriate WizardForm page to the user. The code for the {set-wizard-form} method is shown in Figure 13–5.

FIGURE 13–5 WizardControl.set-wizard-form code listing.

The processing is based on the value contained in the self.current-page class variable, which has already been incremented or decremented, dependent on if the user is going backward or forward in the WizardForm page array. The {set-wizard-form} method then obtains the page-level layout by calling the {get-form} method on the correct WizardForm page in the self.pages array.

This layout replaces the current layout being displayed to the user within the wizard-form ScrollBox class variable by calling the {add} method with the keyword parameter replace? set to true. If the replace? parameter was not set to true, then on execution, we would see the following runtime error: Adding a child to BaseFrame that already has a child.

check-buttons

The {check-buttons} method is executed when the user clicks either on the Back or Next button. The purpose is to ensure that the button's label and enable? properties are set correctly dependent on the position of the WizardForm page in the array. The code for the {check-buttons} method is shown in Figure 13–6.

             FIGURE 13–6 WizardControl.check-buttons code listing.

The {check-buttons} method uses the current-page class variable to determine what WizardForm page is being displayed to the user, and whether the page is the last or first in the pages array. Dependent on the answers to this comparison, the following conditions will apply:

• If the current-page is not the last page then the next.label is set to Next; otherwise, if it is the last page, then it is set to Finish.

• If the current-page is the last WizardForm page in the pages array, then a Next button is inappropriate as there are no pages to move forward to. Here, the Next button should be labeled Finish. In all other cases, the Next button should be labeled Next.

• If the current-page is the first WizardForm page in the pages array, then a Back button is inappropriate as there are no pages to go back to. In all other cases, the user should be able to go to the previous page and change a selection. We do this by setting the back.enabled value to either true or false.

Created: May 2, 2003
Revised: May 2, 2003

URL: http://webreference.com/internet/enterprise/curl/chap13/2