Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » AddCommand Undo
AddCommand Undo [message #529015] Thu, 22 April 2010 16:00 Go to next message
Michael Szediwy is currently offline Michael SzediwyFriend
Messages: 23
Registered: July 2009
Junior Member
Hi,

following scenario:

I have two EClasses
- Container:
- data: 0-* reference to Data
- Data:
- container: 1 reference to Container

I generate all the stuff (Model, Edit, ...)

Then I try to do following:

Container container1= DummyFactory.eINSTANCE.createContainer();
container1.setName("Container1");
Container container2= DummyFactory.eINSTANCE.createContainer();
container2.setName("Container2");

Container container1= DummyFactory.eINSTANCE.createContainer();
container1.setName("Container1");
Container container2= DummyFactory.eINSTANCE.createContainer();
container2.setName("Container2");

Data[] data= new Data[8];
for (int i= 0; i < data.length; i++) {
data[i]= DummyFactory.eINSTANCE.createData();
}

List<Data> dataList= Arrays.asList(data);
container1.getData().addAll(dataList);

BasicCommandStack commandStack= new BasicCommandStack();
AdapterFactoryEditingDomain editingDomain= new
AdapterFactoryEditingDomain(newDummyItemProviderAdapterFacto ry(),
commandStack);

Command command=
AddCommand.create(editingDomain, container2,
DummyPackage.Literals.CONTAINER__DATA,dataList);

commandStack.execute(command);

Assert.isTrue(container1.getData().isEmpty(),
"Container1 has to contain no data!");
Assert.isTrue(container2.getData().containsAll(dataList),
"Container2 has to contain all data!");

commandStack.undo();

Assert.isTrue(container2.getData().isEmpty(),
"Container2 has to contain no data!");
Assert.isTrue(container1.getData().containsAll(dataList),
"Container1 has to contain all data!");

The last assert fails.

Shouldn't all the data objects be in the container1?

Cheers

Michael
Re: AddCommand Undo [message #529093 is a reply to message #529015] Thu, 22 April 2010 21:58 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,
have you debugged where the datas actually are?
A look in doundo() of AddCommand makes me think the undo will only
remove them from container2, but not add them into container 1. I think
it would help, if you do this
RemoveCommand
AddCommand
You could wrap both commands into one.
cheers
Jonas


Michael Szediwy wrote:
> Hi,
>
> following scenario:
>
> I have two EClasses
> - Container:
> - data: 0-* reference to Data
> - Data:
> - container: 1 reference to Container
>
> I generate all the stuff (Model, Edit, ...)
>
> Then I try to do following:
>
> Container container1= DummyFactory.eINSTANCE.createContainer();
> container1.setName("Container1");
> Container container2= DummyFactory.eINSTANCE.createContainer();
> container2.setName("Container2");
>
> Container container1= DummyFactory.eINSTANCE.createContainer();
> container1.setName("Container1");
> Container container2= DummyFactory.eINSTANCE.createContainer();
> container2.setName("Container2");
>
> Data[] data= new Data[8];
> for (int i= 0; i < data.length; i++) {
> data[i]= DummyFactory.eINSTANCE.createData();
> }
>
> List<Data> dataList= Arrays.asList(data);
> container1.getData().addAll(dataList);
>
> BasicCommandStack commandStack= new BasicCommandStack();
> AdapterFactoryEditingDomain editingDomain= new
> AdapterFactoryEditingDomain(newDummyItemProviderAdapterFacto ry(),
> commandStack);
>
> Command command=
> AddCommand.create(editingDomain, container2,
> DummyPackage.Literals.CONTAINER__DATA,dataList);
>
> commandStack.execute(command);
>
> Assert.isTrue(container1.getData().isEmpty(),
> "Container1 has to contain no data!");
> Assert.isTrue(container2.getData().containsAll(dataList),
> "Container2 has to contain all data!");
>
> commandStack.undo();
>
> Assert.isTrue(container2.getData().isEmpty(),
> "Container2 has to contain no data!");
> Assert.isTrue(container1.getData().containsAll(dataList),
> "Container1 has to contain all data!");
>
> The last assert fails.
>
> Shouldn't all the data objects be in the container1?
>
> Cheers
>
> Michael
>
Re: AddCommand Undo [message #529156 is a reply to message #529093] Fri, 23 April 2010 08:48 Go to previous messageGo to next message
Michael Szediwy is currently offline Michael SzediwyFriend
Messages: 23
Registered: July 2009
Junior Member
Hi Jonas,
thanks for your answer. Your proposal solves the problem.
But I am not sure if I can control that if internally in the
Edit Framework an AddCommand gets created?

Cheers

Michael

On 22.04.2010 23:58, Jonas wrote:
> Hi,
> have you debugged where the datas actually are?
> A look in doundo() of AddCommand makes me think the undo will only
> remove them from container2, but not add them into container 1. I think
> it would help, if you do this
> RemoveCommand
> AddCommand
> You could wrap both commands into one.
> cheers
> Jonas
>
>
> Michael Szediwy wrote:
>> Hi,
>>
>> following scenario:
>>
>> I have two EClasses
>> - Container:
>> - data: 0-* reference to Data
>> - Data:
>> - container: 1 reference to Container
>>
>> I generate all the stuff (Model, Edit, ...)
>>
>> Then I try to do following:
>>
>> Container container1= DummyFactory.eINSTANCE.createContainer();
>> container1.setName("Container1");
>> Container container2= DummyFactory.eINSTANCE.createContainer();
>> container2.setName("Container2");
>>
>> Container container1= DummyFactory.eINSTANCE.createContainer();
>> container1.setName("Container1");
>> Container container2= DummyFactory.eINSTANCE.createContainer();
>> container2.setName("Container2");
>>
>> Data[] data= new Data[8];
>> for (int i= 0; i < data.length; i++) {
>> data[i]= DummyFactory.eINSTANCE.createData();
>> }
>>
>> List<Data> dataList= Arrays.asList(data);
>> container1.getData().addAll(dataList);
>>
>> BasicCommandStack commandStack= new BasicCommandStack();
>> AdapterFactoryEditingDomain editingDomain= new
>> AdapterFactoryEditingDomain(newDummyItemProviderAdapterFacto ry(),
>> commandStack);
>>
>> Command command=
>> AddCommand.create(editingDomain, container2,
>> DummyPackage.Literals.CONTAINER__DATA,dataList);
>>
>> commandStack.execute(command);
>>
>> Assert.isTrue(container1.getData().isEmpty(),
>> "Container1 has to contain no data!");
>> Assert.isTrue(container2.getData().containsAll(dataList),
>> "Container2 has to contain all data!");
>>
>> commandStack.undo();
>>
>> Assert.isTrue(container2.getData().isEmpty(),
>> "Container2 has to contain no data!");
>> Assert.isTrue(container1.getData().containsAll(dataList),
>> "Container1 has to contain all data!");
>>
>> The last assert fails.
>>
>> Shouldn't all the data objects be in the container1?
>>
>> Cheers
>>
>> Michael
>>
Re: AddCommand Undo [message #529194 is a reply to message #529156] Fri, 23 April 2010 10:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Michael,

You need to be sure you create the RemoveCommands yourself up front, not
expect the command framework to handle them nor try to change it to do
that. You'll see the generated editor does exactly that when you do
drag and drop to move something from one parent to another...


Michael Szediwy wrote:
> Hi Jonas,
> thanks for your answer. Your proposal solves the problem.
> But I am not sure if I can control that if internally in the
> Edit Framework an AddCommand gets created?
>
> Cheers
>
> Michael
>
> On 22.04.2010 23:58, Jonas wrote:
>> Hi,
>> have you debugged where the datas actually are?
>> A look in doundo() of AddCommand makes me think the undo will only
>> remove them from container2, but not add them into container 1. I think
>> it would help, if you do this
>> RemoveCommand
>> AddCommand
>> You could wrap both commands into one.
>> cheers
>> Jonas
>>
>>
>> Michael Szediwy wrote:
>>> Hi,
>>>
>>> following scenario:
>>>
>>> I have two EClasses
>>> - Container:
>>> - data: 0-* reference to Data
>>> - Data:
>>> - container: 1 reference to Container
>>>
>>> I generate all the stuff (Model, Edit, ...)
>>>
>>> Then I try to do following:
>>>
>>> Container container1= DummyFactory.eINSTANCE.createContainer();
>>> container1.setName("Container1");
>>> Container container2= DummyFactory.eINSTANCE.createContainer();
>>> container2.setName("Container2");
>>>
>>> Container container1= DummyFactory.eINSTANCE.createContainer();
>>> container1.setName("Container1");
>>> Container container2= DummyFactory.eINSTANCE.createContainer();
>>> container2.setName("Container2");
>>>
>>> Data[] data= new Data[8];
>>> for (int i= 0; i < data.length; i++) {
>>> data[i]= DummyFactory.eINSTANCE.createData();
>>> }
>>>
>>> List<Data> dataList= Arrays.asList(data);
>>> container1.getData().addAll(dataList);
>>>
>>> BasicCommandStack commandStack= new BasicCommandStack();
>>> AdapterFactoryEditingDomain editingDomain= new
>>> AdapterFactoryEditingDomain(newDummyItemProviderAdapterFacto ry(),
>>> commandStack);
>>>
>>> Command command=
>>> AddCommand.create(editingDomain, container2,
>>> DummyPackage.Literals.CONTAINER__DATA,dataList);
>>>
>>> commandStack.execute(command);
>>>
>>> Assert.isTrue(container1.getData().isEmpty(),
>>> "Container1 has to contain no data!");
>>> Assert.isTrue(container2.getData().containsAll(dataList),
>>> "Container2 has to contain all data!");
>>>
>>> commandStack.undo();
>>>
>>> Assert.isTrue(container2.getData().isEmpty(),
>>> "Container2 has to contain no data!");
>>> Assert.isTrue(container1.getData().containsAll(dataList),
>>> "Container1 has to contain all data!");
>>>
>>> The last assert fails.
>>>
>>> Shouldn't all the data objects be in the container1?
>>>
>>> Cheers
>>>
>>> Michael
>>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: AddCommand Undo [message #1764769 is a reply to message #529015] Fri, 02 June 2017 07:47 Go to previous messageGo to next message
Kai Schreiber is currently offline Kai SchreiberFriend
Messages: 4
Registered: May 2015
Junior Member
Hi,

> You need to be sure you create the RemoveCommands yourself up front, not
> expect the command framework to handle them nor try to change it to do
> that.

What is the reason not to change the command framework, e.g. change the EditingDomain to return a special AddCommand which adds a RemoveCommand up front if a move is detected?

Thanks,
Kai
Re: AddCommand Undo [message #1764804 is a reply to message #1764769] Fri, 02 June 2017 10:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Are you asking for a historical reason? It seems clear that should we try to change that now (if that were even a good idea) it would be a disruptive change in behavior that's likely to break existing code.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: AddCommand Undo [message #1764855 is a reply to message #1764804] Fri, 02 June 2017 15:30 Go to previous messageGo to next message
Kai Schreiber is currently offline Kai SchreiberFriend
Messages: 4
Registered: May 2015
Junior Member
Thanks for the quick response. My question was unclear. What I wanted to do was to extend my EditingDomain in my application to return that extended AddCommand instead of adding a RemoveCommand in each place where a move occurs. My question is if this would be a bad idea and if there is a reason why this is not the default behavior of the AddCommand. Its clear that it is not possible to change this behavior of the framework.

Thanks,
Kai
Re: AddCommand Undo [message #1764870 is a reply to message #1764855] Fri, 02 June 2017 17:43 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Yes, that's more clear. It's probably a bad idea. I.e., when you do a drag and drop, the framework will already create a remove command and an add command, testing that they are executable (which calls the prepare method). If your logic to create an add command also does a remove, I'm not sure that will work well. I just don't understand the context in which this situation would arise. How are you adding something that is already contained somewhere else (other than with drag and drop) and why wouldn't it be better to create a compound command wherever that is happening rather having such logic elsewhere?

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] IllegalStateException when saving custom Permission
Next Topic:Where is the documentation for latest EMF release?
Goto Forum:
  


Current Time: Thu Apr 18 23:39:59 GMT 2024

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

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

Back to the top