Home » Modeling » EMF » AddCommand Undo
AddCommand Undo [message #529015] |
Thu, 22 April 2010 16:00 |
Michael Szediwy 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 |
Jonas Helming 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 |
Michael Szediwy 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 |
Ed Merks Messages: 33216 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 #1764870 is a reply to message #1764855] |
Fri, 02 June 2017 17:43 |
Ed Merks Messages: 33216 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/
|
|
|
Goto Forum:
Current Time: Fri Sep 20 13:38:50 GMT 2024
Powered by FUDForum. Page generated in 0.03397 seconds
|