CS2340 Summer 2010
Aspect Adapters: How to hook up a list/collection to a the list widget in VisualWorks:
Create the widget by selecting the list button from the painter's Palette dialog and drawing it onto the Canvas (ie called List1).
Enter an Aspect name (ie colorList) for the list which will hold the data to choose from
Click the define button on the GUI Painter Tool when the list (ie List1) is selected.
This should have defined the variable in the Dialog class, and added a getter method. If the variable was not defined properly go to Part B and then to step 5 when done.
Now the fun part, we have to hook up the aspect (ie colorList) to the data it represents. To do this, you will have add code to that runs when the Dialog is created. This can be done in a method such as model. Just make sure that model is run before Dialog is opened. Here is the code that goes in the initialization phase of the Dialog creation:
Set the list variable to a new SelectionInList: colorList := SelectionInList new.
Hook up the original data (ie a colorList variable stored in class instance called setup) to the Aspect (colorList). This is accomplished using a listHolder: colorList listHolder: ((AspectAdaptor subject: setup sendsUpdates: true) forAspect: #colorList).
(Optional) Set the initial selection using an index. To select the first element use the following code: colorList selectionIndex: 1.
To retrieve the current selection of the List simply call selection on the Aspect: colorList selection.
Whenever the data is changed, be sure to call the changed method for that variable. Example, if you were changing the colorList from the setup class, you would call: self changed: #colorList.
Part B (if the code is not auto-generated by define)
Declare the aspect as a class variable
Create a getter for the aspect (ie colorList) by using the following code:
Name the method after the aspect (ie colorList): colorList
[colorList := SelectionInList new]
Return to step 5