Dialogs with lists

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dialogs with lists

Fernando Rodríguez
Hi,

I'm having a lot of trouble with something that seems to me should be
trivial.

I have a model with a ListModel in it that is presented in a Dialog.
The dialog and the model share this ListModel.

However, the dialog doesn't behave as expected, because if I change
the list in the dialog and click 'cancel', the changes to the list
aren't tossed as expected. I understand why this happens, but I'm not
sure how to solve it.

I tried several approaches, but I'm still struggling to get it to work
reliably.

What's the best way to handle this sort of situation? Ideally I'd like
the presenter to share the ListModel with the Model so the ListModel's
events handle all the communication without my intervention.

There has to be  some simple way to do this...


Reply | Threaded
Open this post in threaded view
|

Re: Dialogs with lists

Randy Coulman-2
Fernando wrote:
>
> I have a model with a ListModel in it that is presented in a Dialog.
> The dialog and the model share this ListModel.
>
> However, the dialog doesn't behave as expected, because if I change
> the list in the dialog and click 'cancel', the changes to the list
> aren't tossed as expected. I understand why this happens, but I'm not
> sure how to solve it.
>

I know I've solved this, and I seem to remember I used to do some magic
to make it work, but looking through the code just now, I can't find the
magic.  I did do some refactoring that may have made the magic
unnecessary, so I'll explain what I've got now, and maybe it'll work for
you.  If I get some time, I'll try to put together a simplified example,
but I'm not going to be able to do it tonight.

I have a model class that holds a normal collection (or sometimes a
ListModel, but not in any case where I'm adding to or deleting from the
list in the model).

I set the model of the ListPresenter (or SequenceableItemPresenter or
whatever) like this:

listPresenter model: (self model aspectValue: #listModelInModel)

And everything seems to work IIRC.  ListModel might just work fine too,
but I don't have code that tests that right now.

If you don't get it working, let me know, and when/if I get some time,
I'll try to whip up an example for you.

Randy
--
Randy Coulman
NOTE: Reply-to: address is spam-guarded.  Reassemble the following to
reply directly:
rcoulman at charter dot net


Reply | Threaded
Open this post in threaded view
|

Re: Dialogs with lists

Chris Uppal-3
In reply to this post by Fernando Rodríguez
Fernando,

> I have a model with a ListModel in it that is presented in a Dialog.
> The dialog and the model share this ListModel.
>
> However, the dialog doesn't behave as expected, because if I change
> the list in the dialog and click 'cancel', the changes to the list
> aren't tossed as expected. I understand why this happens, but I'm not
> sure how to solve it.

I'm only repeating what Hwee Boon has already said, but I rather think you
missed his point, so I'll risk saying it again in different words.

It sounds as if your model's #copy method is broken -- more specifically it
sounds as if you haven't provided a correct override of the #postCopy method.
Since your model contains a collection (it doesn't matter that it's actually a
ListModel), and since you also want #copy to work correctly (since you are
using dialogs, and perhaps for other reasons too), you /must/ provide an
implementation of #postCopy that explicitly copies the collection.  If you
don't then the model object and the new object answered by #copy will share the
same collection (which you obviously don't want to happen).

BTW, this is nothing to do with the MVP framework, or with Dialogs, really.
Its just that the framework quite legitimately expects that #copy will work
correctly, and it's /your/ responsibility to ensure that that is the case
(normally by providing a suitable override of #postCopy).

E.g.

    postCopy
        myCollection := myCollection copy.
        super postCopy.

    -- chris