Sundeep Ghuman

CS2340 Summer 2010

Aspect Adapters: How to hook up a list/collection to a the list widget in VisualWorks:

      1. Create the widget by selecting the list button from the painter's Palette dialog and drawing it onto the Canvas (ie called List1).

      2. Enter an Aspect name (ie colorList) for the list which will hold the data to choose from

      3. Click the define button on the GUI Painter Tool when the list (ie List1) is selected.

      4. 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.

      5. 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:

        1. Set the list variable to a new SelectionInList: colorList := SelectionInList new.

        2. 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).

        3. (Optional) Set the initial selection using an index. To select the first element use the following code: colorList selectionIndex: 1.

      6. To retrieve the current selection of the List simply call selection on the Aspect: colorList selection.

      7. 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)

          1. Declare the aspect as a class variable

          2. Create a getter for the aspect (ie colorList) by using the following code:

            1. Name the method after the aspect (ie colorList): colorList

            2. ^colorList isNil

            3. ifTrue:

            4. [colorList := SelectionInList new]

            5. ifFalse:

            6. [colorList].

          3. Return to step 5