User's Guide

OS/2 - Windows Notebook events

UNIX icon
The OS/2 - Windows Notebook part is not available on UNIX and will not run on UNIX. If you are using VisualAge Smalltalk for a UNIX environment you can skip this section.

In this section we'll explore using the events for the OS/2 - Windows Notebook. Because the rationale for using particular events was covered in Portable notebook events we will move much more quickly in this section.

Writing the scripts

Begin by opening the Composition Editor on the CustomerInformationOS2Win part. When the Composition Editor opens, switch to the Script Editor.

The noteBookSwitchToMe event is convenient for doing any initialization that is unique to a notebook page. Create the following script to initialize the cash balance whenever the Account Summary page becomes visible:

noteBookSwitchToMe
    "Handle the event for the Account page.
     Convenient spot to perform page initialization."
    Transcript cr; show: 'Notebook switched to the Accounts page'.
    (self subpartNamed: 'Text1') object: '$1,000,000.00'

The noteBookSwitchFromMe event provides a convenient trigger to perform post-processing when the user has filled in a page. Create the following script which writes a message to the System Transcript window when this event occurs:

noteBookSwitchFromMe
    "Handle the event for the Account page.
     Convenient spot to perform any post-page processing.
     The page switch cannot be prevented"
    Transcript cr; show: 'Notebook switched from the Accounts page'.

Tip icon
You cannot prevent a notebook page switch with the OS/2 - Windows Notebook part. If you need to do post-processing that prevents a page change, use a PM Notebook or Windows Notebook.

The notebook's pageSelected event is triggered whenever a new notebook page is about to become visible. This event is useful for initializing the data that is common to each page. Create the following script which writes a message to the System Transcript window whenever this event is triggered:

pageSelected: aPageView
    "Handle page selected event for the notebook.
     This is a convenient spot to perform initialization for
     information that is common to each notebook page."
    Transcript cr; show: aPageView name

Making the connections

Now that the scripts are complete, let's make the event-to-script connections. Switch to the Composition Editor and make the following connections:

When you finish, the connections should look like the following:
Investment connections

Testing your work

Save the part and select Test icon to test it.

You should see $1,000,000.00 in the Cash balance field. Now, take a look at your System Transcript window. You should see the following messages there:

Notebook switched to the Accounts page
OS/2-Windows Notebook Page1

Notice that the Account Summary page's noteBookSwitchedToMe event and the notebook's pageSelected event occurs when the notebook first opens. Also notice that the page's noteBookSwitchedToMe event occurs before notebook's pageSelected event. This sequence might be important to you when you implement your own applications.

Now, try selecting each page in sequence and when you get to the last page, select the Account tab. You should see the following sequence of messages in your System Transcript window.

Notebook switched from the Accounts page
OS/2-Windows Notebook Page2
OS/2-Windows Notebook Page3
OS/2-Windows Notebook Page4
OS/2-Windows Notebook Page5
Notebook switched to the Accounts page
OS/2-Windows Notebook Page1

Notice that the notebook's pageSelected event occurs for every page in the notebook, as you would expect. Also notice that the notebook page events only occur for the Accounts Summary page because its the only page that has the appropriate event-to-script connections. To process the noteBookSwitchedToMe and noteBookSwitchedFromMe page events, you must make the appropropriate event-to-script connections for each individual page you wish to process.

Now, enter 0.00 in the Cash balance text part and select another page in the notebook. Select the Account tab. The Account Summary page will appear and the Cash balance text part will contain $1,000,000.00 because the noteBookSwitchToMe script always initializes this field whenever the page appears.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]