Subject and SubjectCopy in a Dialog

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

Subject and SubjectCopy in a Dialog

Bruno Brasesco
Hi all,


I have a Dialog with a lot of simple values (strings) and
anOrderedCollection.

I can add or remove elements from  the OrderedCollection.

The problem is when I add or remove anElement from OC, and the press #cancel
in the Dialog.

The dialog apply my operation over the model instead of cancel it. So the
element is added or removed.

The problem is in AspectBuffer that calls #copy method, so my collection is
identical (==) in subject and subjectCopy of the AspectBuffer !.

If I press #cancel after I add (or remove) anElement, the OC of my model
always change.

How Can i do to deal with this ?

I try this;

MyDialog showOn: myModel deepCopy.

But I do not know if this is correct. Because, #deepCopy is not fast.
(in this case the object to be deepCopy is small).

Best Regards
Bruno Buzzi Brasesco


Reply | Threaded
Open this post in threaded view
|

Re: Subject and SubjectCopy in a Dialog

Blair McGlashan
Bruno

You wrote in message news:a3vg3r$197oab$[hidden email]...

>...
> If I press #cancel after I add (or remove) anElement, the OC of my model
> always change.
>
> How Can i do to deal with this ?
>
> I try this;
>
> MyDialog showOn: myModel deepCopy.
>
> But I do not know if this is correct. Because, #deepCopy is not fast.
> (in this case the object to be deepCopy is small).

The general idea is to override #copy in your Model class to copy the object
down to the required depth. By default #copy is implemented as a
#shallowCopy.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Subject and SubjectCopy in a Dialog

Ian Bartholomew-6
In reply to this post by Bruno Brasesco
Bruno,

> The problem is in AspectBuffer that calls #copy method, so my collection
> is identical (==) in subject and subjectCopy of the AspectBuffer !.

Did you mean that as it reads or have I missed the point? For example (not
how you should use an AspectBuffer but just for illustration) -

c := #('aaa' 'bbb' 'ccc') asOrderedCollection.
a := AspectBuffer subject: c.

NB #value answers the contents of the subjectCopy instVar

a subject == a value "answers false"
a subject == c "answers true"
a value == c "answers false"

a subject = a value  "answers true"

Which seems correct to me, #copy for OrderedCollection does a shallow copy
and creates equal but not identical collections.

In your Dialog, which instVar are you using to add your new item to?

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: Subject and SubjectCopy in a Dialog

Bruno Brasesco
Ian,

> c := #('aaa' 'bbb' 'ccc') asOrderedCollection.
> a := AspectBuffer subject: c.
>
> NB #value answers the contents of the subjectCopy instVar
>
> a subject == a value "answers false"
> a subject == c "answers true"
> a value == c "answers false"
>
> a subject = a value  "answers true"

In my case is somethig like that:

c := #('aaa' 'bbb' 'ccc') asOrderedCollection.
array := Array with: 'Dophin' with: c.
a := AspectBuffer subject: array.

a subject last == a value last "answer true".
"so the collections are identical"

The question is when inside your model you have a collection !
(not your model is a collection like your example)

Best Regards
Bruno Buzzi Brasesco


Reply | Threaded
Open this post in threaded view
|

Re: Subject and SubjectCopy in a Dialog

Bruno Brasesco
In reply to this post by Blair McGlashan
>
> The general idea is to override #copy in your Model class to copy the
object
> down to the required depth. By default #copy is implemented as a
> #shallowCopy.


And I should override #apply in my dialog to copy the elements of the
collection !

Thanks !

Bruno Buzzi Brasesco


Reply | Threaded
Open this post in threaded view
|

Re: Subject and SubjectCopy in a Dialog

Ian Bartholomew-6
In reply to this post by Bruno Brasesco
Bruno,

> The question is when inside your model you have a collection !
> (not your model is a collection like your example)

Ah, right. I'm with you now.

Thanks for the clarification

Ian