You have the option of viewing the settings either through the generic
properties or through custom settings. It is sometimes necessary to
provide a custom settings view. Let's build one for the timer part
that looks like the following:
Return to the VisualAge Organizer window and select MyRunSamplePartsApp. From the full Parts menu select New. Type MyTimerSettingsView as the name of your visual part, and select OK. The Composition Editor opens on the MyTimerSettingsView part class.
First, add parts to make the window look like the one pictured above, with a Text part to set the length attribute, and a Toggle Button part to set the repeat attribute.
Change the converter property in the Text part's settings so that the part accepts an integer value only. Add an OK and Cancel push button. Don't make any connections yet.
Because the settings view must work with any timer part, it uses a special kind of variable to hold the timer part.
The window should look like the following:
Select Promote and then OK to add the updateOperation variable to the settings view's public interface. VisualAge will use this update operation variable to connect an actual timer part to the settings view. Close the Promote features window.
To get the settings view to work, let's make the connections.
You are probably wondering where the unlisted actions execute and cancel are defined. They are special predefined actions that were added to your part when you gave it the special name updateOperation. Ordinarily, an attribute-to-attribute connection like those in the timer part's settings view causes an immediate change in an attribute's value. The technique used here prevents an update of the timer part's attributes until the user selects the OK push button. When the user selects the Cancel push button the changes to the timer part's attributes are discarded. This technique of using an updateOperation with a Variable part is called a deferred update and can be useful in many situations.
Your Composition Editor looks like the following:
Save your work.
Now that the settings view is finished, you must tell VisualAge to use it whenever settings are requested for a timer part. You do this by implementing a customSettingsView class method in the MyTimer class. Here is a method you can use:
customSettingsView "Answer my settings view" ^MyTimerSettingsView new
The preceding method tells VisualAge to use the settings view that you created for all timer parts, but it will work only when you have set preferences to custom.
To test your work, open the test view that you created earlier. Double-click on the timer part to open its settings view. Change the settings, and run your test view. To test the changes to the custom settings view, ensure that you have selected custom settings as your settings choice.