Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Undo/Redo using ChangeCommand
Undo/Redo using ChangeCommand [message #415006] Wed, 28 November 2007 05:47 Go to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Hello all,
We are using changeCommand for undo/redo in our emf model.

Model :

[1] Obj1 (0..n)
/ \
/ \
/ \
[0..1] obj2 obj3 (0..1)

Using the add command we are duplicating the obj1 which in turn holds
bi-directional reference to obj3.

When we do undo on add command the duplicated obj1 gets removed but the
obj3 still holds the reference to the removed obj1.
Can we known how to remove this reference on undo ? Or is there any other
solution for this problem ?

Regards
BG
Re: Undo/Redo using ChangeCommand [message #415017 is a reply to message #415006] Wed, 28 November 2007 12:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

When you created the change command, did you include obj3 as one of the
objects for which to record changes. I assume these are non-containment
references and hence recording changes for obj1 will record changes for
its entire containment tree but likely obj3 isn't in that tree


BG wrote:
> Hello all,
> We are using changeCommand for undo/redo in our emf model.
>
> Model :
>
> [1] Obj1 (0..n)
> / \
> / \ / \
> [0..1] obj2 obj3 (0..1)
>
> Using the add command we are duplicating the obj1 which in turn holds
> bi-directional reference to obj3.
>
> When we do undo on add command the duplicated obj1 gets removed but
> the obj3 still holds the reference to the removed obj1.
> Can we known how to remove this reference on undo ? Or is there any
> other solution for this problem ?
>
> Regards
> BG
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415022 is a reply to message #415017] Wed, 28 November 2007 13:17 Go to previous messageGo to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Thanks for your reply.

Your assumptions is correct it is a non-containment reference. We are
passing the obj3 for recording.

Duplication steps
1 Creating the duplicate of obj1 let the duplicate be "dupObj1'
2 we are getting the reference of obj3 from obj1
3 we are setting this reference to dupObj1. i.e obj3 will now have
reference obj1 and dupOb1

After duplicating and performing undo operation the reference of dupObj1
is not getting removed obj3.

This are problem can i know what we are doing is wrong ? Or what is the
best possible solution for this

Regards
BG
Re: Undo/Redo using ChangeCommand [message #415024 is a reply to message #415022] Wed, 28 November 2007 13:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

I just noticed the [1] in your diagram. Does this mean that obj1 will
no longer have a reference to obj3? Are you including both obj1 and
obj3 as object whose changes to record? Perhaps you need to add dupObj1
as well once you've created it...


BG wrote:
> Thanks for your reply.
>
> Your assumptions is correct it is a non-containment reference. We are
> passing the obj3 for recording.
>
> Duplication steps
> 1 Creating the duplicate of obj1 let the duplicate be "dupObj1' 2 we
> are getting the reference of obj3 from obj1
> 3 we are setting this reference to dupObj1. i.e obj3 will now have
> reference obj1 and dupOb1
>
> After duplicating and performing undo operation the reference of
> dupObj1 is not getting removed obj3.
>
> This are problem can i know what we are doing is wrong ? Or what is
> the best possible solution for this
>
> Regards
> BG
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415027 is a reply to message #415024] Wed, 28 November 2007 13:48 Go to previous messageGo to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Model :

[1] Obj1 (0..n)
/ \
/ \ / \
[0..1] obj2 obj3 (0..1)


Regarding first question abt [1] .I didn't get this point sorry ?

Regarding 2 it will have reference to obj3 from obj1...

and during duplication also it obj3 holds reference to dupObj1 i.e

|----obj1
obj3|
|----dupObj1

The dupObj1 is created and reference is added using our own command which
similar to add command.

Can i known how to pass the created dupObj1 to recorder while recording ?

Regards
BG
Re: Undo/Redo using ChangeCommand [message #415028 is a reply to message #415027] Wed, 28 November 2007 13:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

Comments below.


BG wrote:
> Model :
>
> [1] Obj1 (0..n)
> / \
> / \ / \
> [0..1] obj2 obj3 (0..1)
>
>
> Regarding first question abt [1] .I didn't get this point sorry ?
Well, I noticed it's single valued so when obj3 refers to dupObj1, obj1
is being modified, right? So are changes for it being recorded? I.e.,
are you passing obj3 and obj1 to the change command? Perhaps that's all
that's missing, so I won't worry about the other issues until this part
is clear. You might also try passing in the whole resource that
contains all these things...
>
> Regarding 2 it will have reference to obj3 from obj1...
>
> and during duplication also it obj3 holds reference to dupObj1 i.e
>
> |----obj1 obj3|
> |----dupObj1
>
> The dupObj1 is created and reference is added using our own command
> which similar to add command.
>
> Can i known how to pass the created dupObj1 to recorder while recording ?
>
> Regards
> BG
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415031 is a reply to message #415028] Wed, 28 November 2007 14:11 Go to previous messageGo to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Hello Mr Ed Marks

Regarding first question abt [1] .I didn't get this point sorry ?

Well, I noticed it's single valued so when obj3 refers to dupObj1, obj1 is
being modified, right? So are changes for it being recorded? I.e., are
you passing obj3 and obj1 to the change command?


"Yes we are passing the obj1 and obj3 seperately for recording"


Perhaps that's all that's missing, so I won't worry about the other issues
until this part is clear.

You might also try passing in the whole resource that contains all these
things... ?
"Can i known how to pass this as a resource since these are from different
resoucres (different object type they are non-containment reference) ?"


Regarding 2 it will have reference to obj3 from obj1...

and during duplication also it obj3 holds reference to dupObj1 i.e

|----obj1 obj3|
|----dupObj1

The dupObj1 is created and reference is added using our own command which
similar to add command.

Can i known how to pass the created dupObj1 to recorder while recording ?

Regards
BG
Re: Undo/Redo using ChangeCommand [message #415034 is a reply to message #415031] Wed, 28 November 2007 14:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

I just have a bad feeling I'm missing something important that's not
been stated. I certainly imagine that if changes are being recorded for
obj1 and obj3 that apply those changes will undo any changes made to
them. A running (failing) test case I can use to reproduce the problem
is likely to be better than dozens of note exchanges. To directly
answer your question, I imagine at some point you are duplicating obj1
(not sure what that means, it might just mean creating an object of the
same type as obj1, or it might mean more). I would imagine that this
duplication process, if it involves changes that affect obj1 or any
other object would itself be done as a specialized change command. But
I'd need to ask many more questions to understand exactly the complete
structure of what you are doing....

BG wrote:
>
> Hello Mr Ed Marks
>
> Regarding first question abt [1] .I didn't get this point sorry ?
>
> Well, I noticed it's single valued so when obj3 refers to dupObj1,
> obj1 is being modified, right? So are changes for it being recorded?
> I.e., are you passing obj3 and obj1 to the change command?
>
> "Yes we are passing the obj1 and obj3 seperately for recording"
>
> Perhaps that's all that's missing, so I won't worry about the other
> issues until this part is clear.
> You might also try passing in the whole resource that contains all
> these things... ?
> "Can i known how to pass this as a resource since these are from
> different resoucres (different object type they are non-containment
> reference) ?"
>
>
> Regarding 2 it will have reference to obj3 from obj1...
>
> and during duplication also it obj3 holds reference to dupObj1 i.e
>
> |----obj1 obj3|
> |----dupObj1
>
> The dupObj1 is created and reference is added using our own command
> which similar to add command.
>
> Can i known how to pass the created dupObj1 to recorder while recording ?
>
> Regards
> BG
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415045 is a reply to message #415034] Wed, 28 November 2007 16:04 Go to previous messageGo to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Hello Mr Ed marks,
Thanks for your relpy.
Regarding duplication of the obj1 to dupObj1 is just creating a copy of
obji itself and adding then obj3 is then reference to dupObj so that obj3
will have reference to the duplicates obj1 created.

My only problem during undo is the the reference added to obj3 while
duplicating not getting removed i.e even after undo (where dupObj1)
removed from tree obj3 is still holding reference to that duplicated
object.

For me i need immediate solution for this ?Or can i refer any of the
undo/redo testcase which handles this type of problems ?

Thanks
BG



Ed Merks wrote:

> BG,

> I just have a bad feeling I'm missing something important that's not
> been stated. I certainly imagine that if changes are being recorded for
> obj1 and obj3 that apply those changes will undo any changes made to
> them. A running (failing) test case I can use to reproduce the problem
> is likely to be better than dozens of note exchanges. To directly
> answer your question, I imagine at some point you are duplicating obj1
> (not sure what that means, it might just mean creating an object of the
> same type as obj1, or it might mean more). I would imagine that this
> duplication process, if it involves changes that affect obj1 or any
> other object would itself be done as a specialized change command. But
> I'd need to ask many more questions to understand exactly the complete
> structure of what you are doing....

> BG wrote:
>>
>> Hello Mr Ed Marks
>>
>> Regarding first question abt [1] .I didn't get this point sorry ?
>>
>> Well, I noticed it's single valued so when obj3 refers to dupObj1,
>> obj1 is being modified, right? So are changes for it being recorded?
>> I.e., are you passing obj3 and obj1 to the change command?
>>
>> "Yes we are passing the obj1 and obj3 seperately for recording"
>>
>> Perhaps that's all that's missing, so I won't worry about the other
>> issues until this part is clear.
>> You might also try passing in the whole resource that contains all
>> these things... ?
>> "Can i known how to pass this as a resource since these are from
>> different resoucres (different object type they are non-containment
>> reference) ?"
>>
>>
>> Regarding 2 it will have reference to obj3 from obj1...
>>
>> and during duplication also it obj3 holds reference to dupObj1 i.e
>>
>> |----obj1 obj3|
>> |----dupObj1
>>
>> The dupObj1 is created and reference is added using our own command
>> which similar to add command.
>>
>> Can i known how to pass the created dupObj1 to recorder while recording ?
>>
>> Regards
>> BG
>>
>>
Hello Mr Ed
Re: Undo/Redo using ChangeCommand [message #415050 is a reply to message #415045] Wed, 28 November 2007 16:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

Comments below.

BG wrote:
> Hello Mr Ed marks,
> Thanks for your relpy.
> Regarding duplication of the obj1 to dupObj1 is just creating a copy
> of obji itself and adding then obj3 is then reference to dupObj so
> that obj3 will have reference to the duplicates obj1 created.
If necessary, you could implement the undo right in this command that's
doing the duplication. Is this activity happening as part of the
doExecution of the change command? If so, they you do in fact has
access to the dupObj1 and you could add the changeRecorder to the
eAdapters() of that object before you start to modify it further.
>
> My only problem during undo is the the reference added to obj3 while
> duplicating not getting removed i.e even after undo (where dupObj1)
> removed from tree obj3 is still holding reference to that duplicated
> object.
I understand the problem now, but what I've not seen is a single line of
code for how you are doing it. Nor do I have a test case I could look
at to duplicate your results.
>
> For me i need immediate solution for this ?Or can i refer any of the
> undo/redo testcase which handles this type of problems ?
You could look at org.eclipse.emf.test.core.change.ChangeRecordTest.
It's part of the automated tests available with every build on the
download page.
>
> Thanks BG
>
>
>
> Ed Merks wrote:
>
>> BG,
>
>> I just have a bad feeling I'm missing something important that's not
>> been stated. I certainly imagine that if changes are being recorded
>> for obj1 and obj3 that apply those changes will undo any changes made
>> to them. A running (failing) test case I can use to reproduce the
>> problem is likely to be better than dozens of note exchanges. To
>> directly answer your question, I imagine at some point you are
>> duplicating obj1 (not sure what that means, it might just mean
>> creating an object of the same type as obj1, or it might mean more).
>> I would imagine that this duplication process, if it involves changes
>> that affect obj1 or any other object would itself be done as a
>> specialized change command. But I'd need to ask many more questions
>> to understand exactly the complete structure of what you are doing....
>
>> BG wrote:
>>>
>>> Hello Mr Ed Marks
>>>
>>> Regarding first question abt [1] .I didn't get this point sorry ?
>>>
>>> Well, I noticed it's single valued so when obj3 refers to dupObj1,
>>> obj1 is being modified, right? So are changes for it being
>>> recorded? I.e., are you passing obj3 and obj1 to the change command?
>>>
>>> "Yes we are passing the obj1 and obj3 seperately for recording"
>>>
>>> Perhaps that's all that's missing, so I won't worry about the other
>>> issues until this part is clear. You might also try passing in the
>>> whole resource that contains all these things... ?
>>> "Can i known how to pass this as a resource since these are from
>>> different resoucres (different object type they are non-containment
>>> reference) ?"
>>>
>>>
>>> Regarding 2 it will have reference to obj3 from obj1...
>>>
>>> and during duplication also it obj3 holds reference to dupObj1 i.e
>>>
>>> |----obj1 obj3|
>>> |----dupObj1
>>>
>>> The dupObj1 is created and reference is added using our own command
>>> which similar to add command.
>>>
>>> Can i known how to pass the created dupObj1 to recorder while
>>> recording ?
>>>
>>> Regards
>>> BG
>>>
>>>
> Hello Mr Ed
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415082 is a reply to message #415050] Thu, 29 November 2007 05:58 Go to previous messageGo to next message
BG is currently offline BGFriend
Messages: 45
Registered: July 2009
Member
This how my model would look

sync

data rule

The duplication of sync using command

Parameter to function is : sync1 (Type sync) which has to be duplicate

//This is to duplicate the sync
sync2 = Sync1Factory.eINSTANCE.createSync();

//This is to obtain the reference of the rule from the original sync object
Rule rule = (Rule) sync1.getConfRule();

//This is the place where the reference is added to rule
sync2.setRule(rule);

// Get position of SyncNode
Sync syncParent = sync.getSyncParent();
int syncIndex = syncParent.getSyncs().indexOf(sync1);

// Add SyncNode to the next position
syncParent.getSyncs().add(syncIndex + 1, sync2);

When execute this command and perform undo then when debug
@ rule.getSyncs() it return me the sync1 and sync2 objects

I think this snippet will give u the picture what i am doing inside the do
execute function of command.

Regards
BG
Re: Undo/Redo using ChangeCommand [message #415083 is a reply to message #415050] Thu, 29 November 2007 06:40 Go to previous messageGo to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Hello Mr Ed Marks,

I just override of the undo command in add command class

Simply just deleting the newly added obj sync2 does not yield me the result

i.e
EcoreUtil.remove(sync2);

I had to remove the reference additionally i.e
Rule rule = sync2.getRule();
rule.getSyncs().remove(sync2);

I think this part is not getting performed when say just undo from emf
command

So do you think something is wrong in my approch of duplicating of the
sync ?

Regards
BG
Re: Undo/Redo using ChangeCommand [message #415084 is a reply to message #415082] Thu, 29 November 2007 08:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

Comments below.


BG wrote:
> This how my model would look
>
> sync
>
> data rule
>
> The duplication of sync using command
>
> Parameter to function is : sync1 (Type sync) which has to be duplicate
>
> //This is to duplicate the sync
> sync2 = Sync1Factory.eINSTANCE.createSync();
>
> //This is to obtain the reference of the rule from the original sync
> object
> Rule rule = (Rule) sync1.getConfRule();
>
> //This is the place where the reference is added to rule
> sync2.setRule(rule);
So is this happening directly as part of a ChangeCommand's do execute?
>
> // Get position of SyncNode
> Sync syncParent = sync.getSyncParent();
> int syncIndex = syncParent.getSyncs().indexOf(sync1);
>
> // Add SyncNode to the next position
> syncParent.getSyncs().add(syncIndex + 1, sync2);
So parent is also being modified. Are changes being recorded for it?
Is this a containment reference?
>
> When execute this command and perform undo then when debug
> @ rule.getSyncs() it return me the sync1 and sync2 objects
>
> I think this snippet will give u the picture what i am doing inside
> the do execute function of command.
Yes, but not a great idea of which objects you're recording changes
for. It also changes my picture of which features are multi-valued
verses single valued. A test case would really cut to the chase.
>
> Regards
> BG
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415085 is a reply to message #415083] Thu, 29 November 2007 08:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

Comments below.

BG wrote:
> Hello Mr Ed Marks,
>
> I just override of the undo command in add command class
And still I don't understand the relation between the change command and
the add command.
>
> Simply just deleting the newly added obj sync2 does not yield me the
> result
Deleting it from where and at one point?
>
> i.e EcoreUtil.remove(sync2);
This works only remove it from its container.
>
> I had to remove the reference additionally i.e
> Rule rule = sync2.getRule();
> rule.getSyncs().remove(sync2);
So this must not be a containment reference.
>
> I think this part is not getting performed when say just undo from emf
> command
It's getting more vague what is not being undone, but of course I'll
continue to ask, are you recording changes for the object that's being
affected.
>
> So do you think something is wrong in my approch of duplicating of the
> sync ?
It's really not clear to me exactly what you are doing. It's even less
clear now than before...
>
> Regards
> BG
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Undo/Redo using ChangeCommand [message #415114 is a reply to message #415085] Fri, 30 November 2007 06:23 Go to previous messageGo to next message
byrebg Mising name is currently offline byrebg Mising nameFriend
Messages: 48
Registered: July 2009
Member
Thanks Mr Ed Marks,

My problem got solved in bit some other way. I regenerated the emf code
for my model.Then excecuted the undo/redo operation of the obj1 .It is
working fine.

The only difference in the newly generated and old code was this i didn't
get how this code got missed during code generation.

method
eSet(EStructuralFeature eFeature, Object newValue)

case RulePackage.RULE__SYNC:
getSync().clear();
getSync().addAll((Collection)newValue);

method
eUnset(EStructuralFeature eFeature) {

case RulePackage.RULE__SYNC:
getSyncNode().clear();
return;


Regards
BG
Re: Undo/Redo using ChangeCommand [message #415121 is a reply to message #415114] Fri, 30 November 2007 12:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
BG,

I see. I wonder how that got out of whack? Maybe at one point, this
side of the bidirectional was changeable. I suppose our rule for
consistent opposites should specify that isChangeable must be the same
for both ends. Feel free to open a bugzilla request for that. It would
have saved us both some time to have had a constraint for that...


BG wrote:
> Thanks Mr Ed Marks,
>
> My problem got solved in bit some other way. I regenerated the emf
> code for my model.Then excecuted the undo/redo operation of the obj1
> .It is working fine.
>
> The only difference in the newly generated and old code was this i
> didn't get how this code got missed during code generation.
>
> method eSet(EStructuralFeature eFeature, Object newValue)
> case RulePackage.RULE__SYNC:
> getSync().clear();
> getSync().addAll((Collection)newValue);
>
> method
> eUnset(EStructuralFeature eFeature) {
>
> case RulePackage.RULE__SYNC:
> getSyncNode().clear();
> return;
>
>
> Regards
> BG
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Mac users: Leopard Upgrade warning
Next Topic:How can I get a ecore model's SORTED elements tree view?
Goto Forum:
  


Current Time: Sat Sep 21 16:39:36 GMT 2024

Powered by FUDForum. Page generated in 0.03604 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top