Setting up quick forms
VA Smalltalk's quick form feature gives you a fast way to build a user interface for a nonvisual part. You often use quick forms to display the results of database queries or display parameters for external function parts.
Quick forms work by creating a visual part that best matches the data type of each attribute in the nonvisual part. For example, if you used quick forms to build a user interface for the timer part, a text-entry field would be created for the length attribute (because it's a numeric value) and a toggle part would be created for the repeat attribute (because it's a Boolean value).
By default, VA Smalltalk uses Text parts to display most data types. Now that you've defined your own data types, you might want to change the visual part that matches your data type. Let's change the default for the Canadian province data type, by implementing a few methods in the MyCanadianProvince class.
Note:
In the next section, you will override methods that are not VA Smalltalk APIs. It is possible that this code will not work in future versions of VA Smalltalk.
Making quick forms available
The first step is to tell VA Smalltalk that the Canadian Province data type should have a quick form. You do that by implementing the following class method in MyCanadianProvince class:
abtAddDefaultViewForAttributeNamed: attributeName
builderSet: aLoadedBuilderSet
connectionOperations: aSetOfConnectionOperations
at: aPoint
^self abtAddDefaultViewForAttributeNamed: attributeName
label: attributeName
builderSet: aLoadedBuilderSet
connectionOperations: aSetOfConnectionOperations
at: aPoint
Move the preceding method to your edit-time application, MyEditSamplePartsApp. If you do not implement it, VA Smalltalk will not create a quick form at all for province objects.
Choosing a default visual part
Next, you tell VA Smalltalk what kind of visual part to use for the quick form. This example uses a drop-down list that contains all the province names as the quick form. The following method creates the drop-down list, sets its items attribute, and connects the province object to the drop-down list's selectedItem:
abtAddDefaultViewForAttributeNamed: attributeName
label: aString
builderSet: aLoadedBuilderSet
connectionOperations: aSetOfConnectionOperations
at: aPoint
| partBuilder defaultSize |
partBuilder := AbtDropDownListComboBox newSubpartBuilder
attributeSettingNamed: #items put: (MyCanadianProvince provinces).
defaultSize := AbtDropDownListComboBox defaultEditSize.
aLoadedBuilderSet
builderNamed: nil
put: partBuilder
boundingBox: (aPoint extent: defaultSize).
aSetOfConnectionOperations
add: ((AbtAddConnectionOperation
new: AbtAttributeToAttributeConnectionBuilder)
sourceConnectionItemName: attributeName;
targetBuilder: partBuilder;
targetConnectionItemName: #selectedItem).
^defaultSize
Move the preceding method to your edit-time application, MyEditSamplePartsApp. Notice that it needs a list of province names. To create the list, add the following class method to MyCanadianProvince:
provinces
"Answer a list of all the provinces"
^self mapping values asSortedCollection
Testing your work
Use the testing window you created earlier to test the new quick form.
1. From the Options menu, select Add Part and type MyCanadianProvince in the Class name field. Drop the part onto the free-form surface, outside the window.
2. From the province's pop-up menu, select Quick form.
3. Select the self attribute from the list that is displayed.
4. The cursor should be loaded with the quick form part, so drop it onto the Window part.
A Drop-down List part should be added to your testing window. Test the part, and check that the drop-down list contains all the province names.
Last modified date: 01/29/2015