Getting Started


Defining a VAGen server program

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.

Embedding a reusable visual part

You can now complete the window in Figure 101, which displays detailed customer information.

Figure 101. Customer Information Window

Figure cigui1 not displayed.

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:

  1. In the VisualAge Organizer window, Double-click on TutorialView.

    The Composition Editor opens, displaying the Customer Information window.

  2. From the Options menu, select Add Part.

    The Add Part window is displayed

Figure 102. Add Part Window

Figure addpart not displayed.

  1. In the Class Name field, type ReusableAddressBoxView and select OK.

    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.
  2. Click on the Customer Information window where you want to add the part.

    The Address box is added to the Window.

  3. Size the Address box (and the Customer Information window if necessary) until the entire Group Box fits inside the window.
  4. Select the ADDRESS Group Box with mouse button 2. From the context menu, select Connect>streetObject.

    A dotted line with a artworkat the end is displayed.

  5. Select the CUSTOMER Record part.

    The Connect attribute named: window is displayed.

  6. From the Attribute column, select CUSSTREET data and select OK.

    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.

  7. Repeat the previous steps for cityobject, stateobject, and zipobject. Connect them to CUSCITY data, CUSSTATE data, and CUSZIP data, respectively.

    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.

Adding a VAGen program to the visual part

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.

  1. Select the VAGen Parts category Figure vgcat not displayed..

    The list of parts in the VAGen Parts category is shown in the parts palette.

  2. Select the VAGen Program part Figure vagcallf not displayed. and click on the free-form surface to the right of your Window.

    The Add Part window is displayed.

  3. In the VAGen part field, type findcus and select OK.

    The FINDCUS program part is now on your free-form surface.

  4. Select the Find Push Button with mouse button 2.

    The context menu for the Find Push Button is displayed.

  5. Select Connect>clicked.

    A line with a artworkon the end is displayed.

  6. Select the FINDCUS program part.

    A context menu is displayed.

  7. From the context menu, select execute.

    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.

  8. Select the FINDCUS Program part with mouse button 2.

    A context menu is displayed

  9. Select Edit Part.

    The New Part Application window is displayed

  10. Ensure that Tutorial is selected, and select OK.

    The Program Editor opens to display FINDCUS.

Defining the VAGen server application

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:

  1. From the Define menu, select Called Parameters>Insert Parameter.

    The Insert Parameter window is displayed.

  2. Ensure that the Record radio button is selected, and from the Part Name drop-down list box, select CUSTOMER.
  3. Select OK.

    The CUSTOMER record is displayed in the program diagram under Called Parameters. Now you are ready to define the main functions for FINDCUS.

  4. From the Define menu, select Main Functions.

    The Insert Main Function window is displayed.

  5. In the Part name field, type find-customer and select OK.

    The FIND-CUSTOMER function is displayed in the structure diagram. The ? beside it means that it has not yet been defined.

  6. Double-click on FIND-CUSTOMER function icon.

    The New Part Application window is displayed.

  7. Ensure that Tutorial is selected, and select OK.

    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.

  8. From the I/O Option drop-down list box, select INQUIRY. In the I/O Object field, type custinfo.

    Your entries are displayed on the second line in the Function Editor.

  9. From the Define menu, select Properties.

    The Function Properties window is displayed.

  10. From the Error routine drop-down list box, select EZERTN and then select OK.

    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.

  11. In the Function Editor, type the statements as shown in Figure 103.

    The first statement executes before the actual database query. The other statements execute after the query takes place.

Figure 103. Sample Statements

 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
  1. From the Tools menu, select Validate and Format.

    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.

  2. From the File menu, select Save.

    A+ is displayed beside the FIND-CUSTOMER function in the Program Editor.

Defining the CUSTINFO record

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.

  1. In the Program Editor, click the + beside the FIND-CUSTOMER function.

    The CUSTINFO record is displayed.

  2. Double-click on the CUSTINFO record.

    The New Part Application window is displayed.

  3. Ensure that Tutorial is selected, and select OK.

    The Record Editor is displayed.

  4. From the record type drop-down list box, select SQL Row.
  5. Ensure that there are no items in the record. If there is an item in the record, delete it. To delete an item, select it. Then, from the Edit menu, select Delete.
  6. From the Define menu, select Properties.

    The SQL Row Properties window is displayed.

  7. On the SQL Row Properties window, select Insert.

    A row is added and the cursor appears in the Name pane.

  8. In the Name pane, type customer.
  9. Select OK.

    The SQL Row Properties window closes.

  10. From the Tools menu, select Retrieve SQL.

    The SQL table is displayed in the Record Editor.

  11. Click in the Key column of the CUSNUM data item and select the check box.

    The check box is checked. The CUSNUM item is defined as the key data item.

  12. From the File menu, select Save.
  13. Close the Record Editor.

    The fully-defined CUSTINFO record is displayed in the Program Editor.

  14. In the Program Editor, from the File menu, select Save.
  15. Close the Program Editor.

Building parameters for the program

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.

  1. In TutorialView, select the FINDCUS Program part with mouse button 2. From the context menu, select Build parameters from 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.

  2. Select the CUSTOMER part with mouse button 2. From the context menu, select Connect.

    The Start connection from window is displayed

  3. From the Attribute column, select self; then select OK.

    You now have a line with a spideron the end.

  4. Select the Push Button1,clicked> FINDCUS,execute connection and click mouse button 1.

    Select CUSTOMER from the context menu.

  5. From the Attribute column, select self; then select OK.

    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

Figure 104. TutorialView

Figure viewtut not displayed.

For more information on building visual parts, refer to the VisualAge for Smalltalk User's Guide.

Testing the view

Now test your view using the Interactive Test Facility.

  1. From the tool bar, select Test test button.

    The Customer Information window is displayed.

  2. Place the cursor in the Customer Number field. Type a customer number from the list below; then select Find. Use 111-0101 through 111-0106 and 122-0001 through 122-0003. If you type an invalid number, nothing changes.

    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.

  3. Continue entering other customer numbers. After you finish testing, in the Customer Information window, select Cancel.

    The Customer Information window closes.

  4. Close the Test Monitor window.
  5. Close the Composition Editor.

Figure 105. Customer Information Window

Figure testcust not displayed.

Summary

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.


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