18.8 Updating browsers
When the objects browsed get changed, we need the browser to update and reflect the new state.
In Glamour, there are two ways in which this is accomplished:
- explicitly, by sending #update to a presentation, or
- implicitly, by making a presentation listen to Announcements thrown by the objects.
The explicit mechanism is simple and is typically accessible by means of actions. For example, to see the list of all models registered in the root model we could use a browser as shown below.
| browser |
browser := GLMTabulator new.
browser title: 'Model list with manual update'.
browser column: #list.
browser transmit to: #list; andShow: [:a |
a list
act: [:list | list update]
icon: GLMUIThemeExtraIcons glamorousRefresh
entitled: 'Update';
format: #name ].
browser openOn: MooseModel root.
You can affect the root model by simply adding a new model:
MooseModel root add: MooseModel new.
The list does not show the new model. We can update the list by pressing the update icon.
For the Announcement-based mechanism to work, you need an object that does raise Announcements. Once you have such an object, you can use GLMPresentation>>#updateOn: anAnnouncement from: anAnnouncer
to control what announcements should trigger the update of the presentation.
Let us take an example. A MooseEntity sends several announcements when its inner structure changes. One of these Announcements is MooseEntityAdded
. However, because the MooseEntity is not an Announcer, it uses an announcer object to send the announcements. If you want to have a list of models from the root model updated every time a new model is added, you can register to the MooseEntityAdded
announcement sent by the model announcer
:
| browser |
browser := GLMTabulator new.
browser title: 'Model list with implicit update'.
browser column: #list.
browser transmit to: #list; andShow: [:a |
a list
format: #name;
updateOn: MooseEntityAdded from: [:model | model announcer ] ].
To watch the effect of an announcement, you can test it with:
MooseModel root add: MooseModel new.
validation