Dialog class and aspectBuffer

26 views
Skip to first unread message

vin...@gmail.com

unread,
Mar 20, 2021, 7:11:05 AMMar 20
to
I have a class Guest, which has parameters #isAttending (Boolean) and #person (Person class). Person class has the given names, family name and title.

Guest UI is a Dialog that contains #isAttending (a checkbox) and Person (a Presenter).

In Guest>>#model: I have an aspectBuffer to buffer changes. However the changes to person are always written even if I send #cancel. The change to #isAttending is always buffered.

Is there a way around this? I followed the PersonalMoney example, specifically PersonalAccountTransactionDialog>>#model: where the aspectBuffer is used.

Vince

vin...@gmail.com

unread,
Mar 23, 2021, 7:10:04 AMMar 23
to
I had to override copy. The changes in the Dialog are correctly buffered and discarded when I press 'Cancel' and written to the backing model when I press 'Save'.

The structure is as follows. The models:

Model subclass: #Guest
instanceVariableNames: 'person isAttending'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''

Model subclass: #Person
instanceVariableNames: 'title givenNames familyName dateOfBirth'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''

Guest>>#person
^ person ifNil: [ person := Person new ]

The Ui classes:

Presenter subclass: #PersonUi
instanceVariableNames: 'title givenNames familyName dateOfBirth'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''

Dialog subclass: #NppGuestView
instanceVariableNames: 'person isAttending'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''

Guest>>#model: anObject
| aspectBuffer |

super model: anObject.
aspectBuffer := self model.
self person model: (aspectBuffer aspectValue: #person).
self isAttending model: (aspectBuffer aspectValue: #isAttending)

The class comment for AspectBuffer says: "In order to be correctly used with an AspectBuffer, a subject object must be able to be sensibly duplicated using #copy."

So I implemented the following:

Guest>>#copy
^ self species new
person: self person copy;
isAttending: self isAttending copy

Vince
Reply all
Reply to author
Forward
0 new messages