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 |
Vasanth Velusamy 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 |
Ed Merks 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 |
Vasanth Velusamy 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
|
|
| | | | |
Goto Forum:
Current Time: Thu Apr 25 23:59:04 GMT 2024
Powered by FUDForum. Page generated in 0.03864 seconds
|