View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

How to use Lists in GUIs in SmallTalk

How to use Lists in GUIs in Smalltalk

using lists in Smalltalk can be very tedious if not done correctly and one must first experience a lot of errors before finally making them work. Hopefully, this guide can help to shorten the process of proper implementaion.

If we already have a Group class with a GUI class called GroupGUI, we must have an instance of Group in GroupGUI as the model.
We must also say that Group has a userList variable that we are trying to show in the GUI list called userListGUI.

having these assumptions, first we need to pass in a model
model: aGroup
model := aGroup "this gives us a value to work with. if you write the code below before you pass in the object you want to show info from, this will not work"

The following code creates the aspect adapter and set it to show the info from model userList variable.
The last line tells the gui that the variable list has been updated so it displays the current info in that variable.

userListGUI := SelectionInList new.
userListGUI listHolder: ((AspectAdaptor subject: model sendsUpdates: true) forAspect: #userList).
model changed: #userList.

This is enough to have the gui show the list, but if we try to update anything mid program, the GUI list will not update unless we reopen the window or click on the part that we have edited.

In order to have the gui auto- update every time, we must place the line model changed: #userList anywhere where we make changes to the variable userList.
If this is in another class, we ust reference the same instance of Group properly. It might be called a different name.

Ex. group changed: #userList. (group in the System class refers to the same group as model in the code above)

So, make sure you tell the list it has been changed any time you do any changes. You have to send it that message in the same methhod, directly following the change.

Links to this Page