The focus of this section is to finish developing your user interface and connect it to a server application that reads data to be displayed in the Customer Information window. The objective of this section is to familiarize you with making connections between user interfaces and nonvisual parts, such as records and server applications. In addition, you will build the server application and embed the Address box you created in the previous section. Finally, you will use the Interactive Test Facility to test how the client and server applications work together.
You can now complete the window in Figure 101, which displays detailed customer information.
Figure 101. Customer Information Window
To complete the window, add the Address box you created in Defining a reusable visual part to the Customer Information Window. To add the reusable visual part, perform the following steps:
The Composition Editor opens, displaying the Customer Information window.
The Add Part window is displayed
The mouse pointer becomes a cross hair.
Note: | Selecting Browse will open the Choose a Valid Class window, which lets you to search for available classes. |
The Address box is added to the Window.
A dotted line with a
at the end is displayed.
The Connect attribute named: window is displayed.
This creates an attribute-to-attribute connection between the Street Text part and the data item CUSSTREET in the CUSTOMER Record part.
By selecting the data attribute, you are making a connection to only the data contents of the data item. If the connection required a type description in addition to the data contents, you would have selected CUSSTREET, which represents the self attribute of the data item.
Populating Text parts on a Window, as in this example, only requires the data contents. However, when you connect to a parameter in a called parameter list for a program, the data contents and the type description are required.
This creates attribute-to-attribute connections between the fields in the Group Box and the data items in the CUSTOMER Record part. If you want to check any of the connections, select the connection and the status area will contain a description of it.
Now that all the user interface parts are in place on the Window, add a VAGen Program part to the free-form surface and connect it to one of the Push Buttons. The VAGen Program part represents a server application that you will define later in this exercise. The server application will read the customer details from the database and return the data to TutorialView to populate the fields in the Customer Information window.
The list of parts in the VAGen Parts category is shown in the parts palette.
The Add Part window is displayed.
The FINDCUS program part is now on your free-form surface.
The context menu for the Find Push Button is displayed.
A line with a
on the end is displayed.
A context menu is displayed.
A green arrow now connects the Find Push Button with the FINDCUS Program part. This connection means that when the Find Push Button is clicked, FINDCUS is called.
A context menu is displayed
The New Part Application window is displayed
The Program Editor opens to display FINDCUS.
In this section, you define the VAGen server application FINDCUS, which reads the customer information from a relational database. To retrieve the correct customer information, the record key (CUSNUM) for the database must be passed to the server application from TutorialView. To display the retrieved information, the data to populate the Customer Information window must be returned from the server application. Parameters are the mechanisms by which data is passed between applications.
To define the server application, in the Program Editor, perform the following steps:
The Insert Parameter window is displayed.
The CUSTOMER record is displayed in the program diagram under Called Parameters. Now you are ready to define the main functions for FINDCUS.
The Insert Main Function window is displayed.
The FIND-CUSTOMER function is displayed in the structure diagram. The ? beside it means that it has not yet been defined.
The New Part Application window is displayed.
The Function Editor is displayed. It contains two drop-down list boxes. The list box on the left displays I/O options, which define the type of operation a function will carry out. The list box on the right displays I/O objects, the data parts on which I/O options are performed.
Your entries are displayed on the second line in the Function Editor.
The Function Properties window is displayed.
The Function Properties window closes. The information retrieved from the database inquiry will be placed in the CUSTINFO record you will define later. The error routine EZERTN will return control to your program when an error occurs. This prevents the program from ending with system generated messages, which might confuse an application user.
The first statement executes before the actual database query. The other statements execute after the query takes place.
custinfo.cusnum = customer.cusnum; /*customer number to be retrieved ----------------------- INQUIRY CUSTINFO --------------------- if custinfo not err; /*If the query did not return an error customer = custinfo; /*Place all data from the retrieved end; /*row into the customer record
The statements have been validated and formatted. If a Validation Errors window is displayed, correct the errors listed in the window, and select Validate and Format again.
A+ is displayed beside the FIND-CUSTOMER function in the Program Editor.
In the previous section, you defined an INQUIRY function that uses the CUSTINFO record. Now, you need to define the record. This record will contain the detailed customer information after it is retrieved from the database.
The CUSTINFO record is displayed.
The New Part Application window is displayed.
The Record Editor is displayed.
The SQL Row Properties window is displayed.
A row is added and the cursor appears in the Name pane.
The SQL Row Properties window closes.
The SQL table is displayed in the Record Editor.
The check box is checked. The CUSNUM item is defined as the key data item.
The fully-defined CUSTINFO record is displayed in the Program Editor.
In this section, you build the parameters that will be passed between the client view and the FINDCUS program. You also visually connect the parameters to complete the definition.
Based on the parameter list of FINDCUS, this action creates the parameters needed for the CALL.
Selecting Build parameters from definition causes one parameter to be added to the connection context menu for the FINDCUS Program part. A statement displayed in the status line confirms that default parameters were built.
The Start connection from window is displayed
You now have a line with a
on the end.
Select CUSTOMER from the context menu.
A parameter-from-attribute connection passes the CUSTOMER record to the FINDCUS program. You selected the self attribute to pass the data contents and the type description of the record to the server program.
Your completed server application should look like Figure 104
For more information on building visual parts, refer to the VisualAge for Smalltalk User's Guide.
Now test your view using the Interactive Test Facility.
The Customer Information window is displayed.
If you want Test Monitor to have focus while it tests your VAGen parts, on the VisualAge Organizer window, select Options>VAGen Preferences. On the VAGen Test window, under options, select Break on event entry for GUI clients.
Start the Test Monitor. The Test Monitor gets focus if you have an error in a VAGen part. If you would like to see the Test Monitor window throughout your test run, move it to the right side of your screen.
If errors are encountered during the test, you can change your code without leaving the test. After you make changes and save the part, the test facility automatically repositions the test for you to test your new changes.
Otherwise, the program runs and the Customer Information window is updated with data from the database. Your application ran successfully if it looks like the one shown in Figure 105.
The Customer Information window closes.
Figure 105. Customer Information Window
Congratulations! You have completed all the steps in this tutorial, and you have experienced first-hand how easy it is to define and test applications using VisualAge Generator. As you begin working with VisualAge Generator, you can refer back to this tutorial, all the other VisualAge Generator documentation, and VisualAge Generator's extensive online help system.