Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » AddCommand seems to cause issues during undo
AddCommand seems to cause issues during undo [message #415828] Tue, 08 January 2008 21:04 Go to next message
Vasanth Velusamy is currently offline Vasanth VelusamyFriend
Messages: 31
Registered: July 2009
Member
Hi all,

I have an AddCommand that executes fine. However, on undo, it seems to
not undo the add operation. The essence of it seems to be that
BasicFeatureMap.addAll(Collection) seems to make the input parameter
collection to be empty at the end of performing addAll. This has the
effective that on undo, nothing gets undone.

Here is a sequence of what I did:

(1) Construct the AddCommand

I am trying to add a FeatureMap to an EObject using AddCommand. The code
looks something like this:

// myEObject.getAny() returns an org.eclipse.emf.ecore.util.FeatureMap
Command addCommand =
AddCommand.create(AdapterFactoryEditingDomain.getEditingDoma inFor(myEObject),
myEObject, AeMyPackage.Literals.MYEOBJECT__ANY,
myEObject.getAny());

// then I execute the command


(2) Execute the AddCommand. The control goes to
org.eclipse.emf.ecore.util.BasicFeatureMap.addAll(Collection <? extends
Entry> collection). At the beginning of this method, I see that
'collection' has the correct data in it (one 'Entry' object inside the
collection). However, when the last statement in the method executes
(which is 'return doAddAll(uniqueCollection)'), I see that 'collection'
is now an empty Collection. The single 'Entry' object that was in it
seems to be missing.

However, the AddCommand does execute properly.

(3) Perform undo (from user action). The control goes to
org.eclipse.emf.edit.command.AddCommand.doUndo(). As per the undo logic,
it removes all entries from 'collection', which is the same Collection
from step (2) above. But since the collection was somehow emptied, undo
doesn't really undo (remove) anything.


Is this a known issue?

Thanks,
Vasanth
Re: AddCommand seems to cause issues during undo [message #415829 is a reply to message #415828] Tue, 08 January 2008 21:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Vasanth,

Yes, don't use myEObject.getAny() directly since it's likely being
affected by birectional updates as the map entry representing
containment reference are moved to the new target. Use something like
new ArrayList<?>(myEObject.getAny()) to ensure you've passed in a copy
that won't change. Note also that AddCommand will generally assume that
if the things being added are being removed from somewhere else that you
will have done that prior step with a remove command, so even the above
might not do the trick. Are you really trying to move contained objects
from one container to another?



Vasanth Velusamy wrote:
> Hi all,
>
> I have an AddCommand that executes fine. However, on undo, it seems to
> not undo the add operation. The essence of it seems to be that
> BasicFeatureMap.addAll(Collection) seems to make the input parameter
> collection to be empty at the end of performing addAll. This has the
> effective that on undo, nothing gets undone.
>
> Here is a sequence of what I did:
>
> (1) Construct the AddCommand
>
> I am trying to add a FeatureMap to an EObject using AddCommand. The
> code looks something like this:
>
> // myEObject.getAny() returns an org.eclipse.emf.ecore.util.FeatureMap
> Command addCommand =
> AddCommand.create(AdapterFactoryEditingDomain.getEditingDoma inFor(myEObject),
>
> myEObject, AeMyPackage.Literals.MYEOBJECT__ANY,
> myEObject.getAny());
>
> // then I execute the command
>
>
> (2) Execute the AddCommand. The control goes to
> org.eclipse.emf.ecore.util.BasicFeatureMap.addAll(Collection <? extends
> Entry> collection). At the beginning of this method, I see that
> 'collection' has the correct data in it (one 'Entry' object inside the
> collection). However, when the last statement in the method executes
> (which is 'return doAddAll(uniqueCollection)'), I see that
> 'collection' is now an empty Collection. The single 'Entry' object
> that was in it seems to be missing.
>
> However, the AddCommand does execute properly.
>
> (3) Perform undo (from user action). The control goes to
> org.eclipse.emf.edit.command.AddCommand.doUndo(). As per the undo
> logic, it removes all entries from 'collection', which is the same
> Collection from step (2) above. But since the collection was somehow
> emptied, undo doesn't really undo (remove) anything.
>
>
> Is this a known issue?
>
> Thanks,
> Vasanth


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: AddCommand seems to cause issues during undo [message #415832 is a reply to message #415829] Tue, 08 January 2008 23:28 Go to previous messageGo to next message
Vasanth Velusamy is currently offline Vasanth VelusamyFriend
Messages: 31
Registered: July 2009
Member
Ed,

Comments inline.


Ed Merks wrote:
> Vasanth,
>
> Yes, don't use myEObject.getAny() directly since it's likely being
> affected by birectional updates as the map entry representing
> containment reference are moved to the new target. Use something like
> new ArrayList<?>(myEObject.getAny()) to ensure you've passed in a copy
> that won't change. Note also that AddCommand will generally assume that
> if the things being added are being removed from somewhere else that you
> will have done that prior step with a remove command, so even the above
> might not do the trick.

Wrapping the FeatureMap.Entry objects in a Collection seems to have done
the trick. Now the collection doesn't get affected by the add operation;
hence, undo works fine. Thanks.

> Are you really trying to move contained objects
> from one container to another?
>
Yes I am. My schema (hence the EMF model) is not strong enough at one
particular level (it is an extension point). Hence, I am dealing with
contained objects of an EObject.

Thanks,
Vasanth

>
>
> Vasanth Velusamy wrote:
>> Hi all,
>>
>> I have an AddCommand that executes fine. However, on undo, it seems to
>> not undo the add operation. The essence of it seems to be that
>> BasicFeatureMap.addAll(Collection) seems to make the input parameter
>> collection to be empty at the end of performing addAll. This has the
>> effective that on undo, nothing gets undone.
>>
>> Here is a sequence of what I did:
>>
>> (1) Construct the AddCommand
>>
>> I am trying to add a FeatureMap to an EObject using AddCommand. The
>> code looks something like this:
>>
>> // myEObject.getAny() returns an org.eclipse.emf.ecore.util.FeatureMap
>> Command addCommand =
>> AddCommand.create(AdapterFactoryEditingDomain.getEditingDoma inFor(myEObject),
>>
>> myEObject, AeMyPackage.Literals.MYEOBJECT__ANY,
>> myEObject.getAny());
>>
>> // then I execute the command
>>
>>
>> (2) Execute the AddCommand. The control goes to
>> org.eclipse.emf.ecore.util.BasicFeatureMap.addAll(Collection <? extends
>> Entry> collection). At the beginning of this method, I see that
>> 'collection' has the correct data in it (one 'Entry' object inside the
>> collection). However, when the last statement in the method executes
>> (which is 'return doAddAll(uniqueCollection)'), I see that
>> 'collection' is now an empty Collection. The single 'Entry' object
>> that was in it seems to be missing.
>>
>> However, the AddCommand does execute properly.
>>
>> (3) Perform undo (from user action). The control goes to
>> org.eclipse.emf.edit.command.AddCommand.doUndo(). As per the undo
>> logic, it removes all entries from 'collection', which is the same
>> Collection from step (2) above. But since the collection was somehow
>> emptied, undo doesn't really undo (remove) anything.
>>
>>
>> Is this a known issue?
>>
>> Thanks,
>> Vasanth
Re: AddCommand seems to cause issues during undo [message #425117 is a reply to message #415828] Fri, 14 November 2008 14:41 Go to previous messageGo to next message
Manju is currently offline ManjuFriend
Messages: 4
Registered: July 2009
Junior Member
Hello Vasanth,

i guess myEObject.getAny() returns you a Collection. When using the command, the command internally clears the target and then the new contents are added using addAll. In your case the target list and the source list are the same, the net effect is to clear the target and the source and add an empty list.

You should make a copy of the list
newList = new ArrayList(myEObject.getAny());

make modification on this newList and pass this list in your command.

Thanks,
Manju
Re: AddCommand seems to cause issues during undo [message #425118 is a reply to message #415828] Fri, 14 November 2008 14:42 Go to previous messageGo to next message
Manju is currently offline ManjuFriend
Messages: 4
Registered: July 2009
Junior Member
Hello Vasanth,

i guess myEObject.getAny() returns you a Collection. When using the command, the command internally clears the target and then the new contents are added using addAll. In your case the target list and the source list are the same, the net effect is to clear the target and the source and add an empty list.

You should make a copy of the list
newList = new ArrayList(myEObject.getAny());

make modification on this newList and pass this list in your command.

Thanks,
Manju
Re: AddCommand seems to cause issues during undo [message #425119 is a reply to message #415828] Fri, 14 November 2008 14:42 Go to previous messageGo to next message
Manju is currently offline ManjuFriend
Messages: 4
Registered: July 2009
Junior Member
Hello Vasanth,

i guess myEObject.getAny() returns you a Collection. When using the command, the command internally clears the target and then the new contents are added using addAll. In your case the target list and the source list are the same, the net effect is to clear the target and the source and add an empty list.

You should make a copy of the list
newList = new ArrayList(myEObject.getAny());

make modification on this newList and pass this list in your command.

Thanks,
Manju
Re: AddCommand seems to cause issues during undo [message #425120 is a reply to message #415828] Fri, 14 November 2008 14:43 Go to previous message
Manju is currently offline ManjuFriend
Messages: 4
Registered: July 2009
Junior Member
Hello Vasanth,

i guess myEObject.getAny() returns you a Collection. When using the command, the command internally clears the target and then the new contents are added using addAll. In your case the target list and the source list are the same, the net effect is to clear the target and the source and add an empty list.

You should make a copy of the list
newList = new ArrayList(myEObject.getAny());

make modification on this newList and pass this list in your command.

Thanks,
Manju
Previous Topic:SetCommand not working in AdapterFactoryEditingDomain
Next Topic:[EMF Transaction] About a deadlock and a monster UI thread
Goto Forum:
  


Current Time: Thu Apr 25 23:59:04 GMT 2024

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

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

Back to the top