Extending DeleteAction/Command not undoable [message #904474] |
Tue, 28 August 2012 09:42  |
Eclipse User |
|
|
|
Hi,
I have the following situation.
I have ecore model with a list of objects called MyDataObjects.
And i have a list in my model called DeletedDataObjects.
My aim is, that when I delete an object all references that are referencing it will be deleted, the object will be removed from the MyDataObjects list and added to the DeletedDataObjcts list.
I have tried this by extend the DeleteAction that is used in the MetamodelActionBarContributor and overrding the createCommand Method like this:
@Override
public Command createCommand(Collection<?> selection)
{
Command command = removeAllReferences ? DeleteCommand.create(domain, selection) : RemoveCommand.create(domain, selection);
CompoundCommand compoundCommand = new CompoundCommand();
compoundCommand.append(command);
EPA epa = EpaUtilToolboxModelAccess.getRootObject();
Iterator<?> it = selection.iterator();
if(it.hasNext()){
while(it.hasNext()){
Object o = it.next();
compoundCommand.append(AddCommand.create(domain, epa.getDeletedEpaObjects(), MetamodelPackage.eINSTANCE.getDeletedObjects_DeletedObject(), EcoreUtil.copy(eo)));
}
}
compoundCommand.setLabel("Compound " + command.getLabel());
return compoundCommand;
}
This works fine so far....the objects gehts removed from the MyDataObjects list and is put into the DeletedObjects list......
....BUT when I trigger Undo in the generated rcp client the object is not removed from the DeletedObjects list. It is restored in the MyDataObjects list but stays in the DeletedObjects list.....the appended AddCommand seems not to be undone.
There are not exceptions, not bad to see....it just does not work.
Any ideas ?
Greeting from Germany
|
|
|
Re: Extending DeleteAction/Command not undoable [message #904482 is a reply to message #904474] |
Tue, 28 August 2012 10:01   |
Eclipse User |
|
|
|
Markus,
Comments below.
On 28/08/2012 3:42 PM, Markus Jo wrote:
> Hi,
> I have the following situation.
>
> I have ecore model with a list of objects called MyDataObjects. And i
> have a list in my model called DeletedDataObjects.
>
> My aim is, that when I delete an object all references that are
> referencing it will be deleted, the object will be removed from the
> MyDataObjects list and added to the DeletedDataObjcts list.
>
> I have tried this by extend the DeleteAction that is used in the
> MetamodelActionBarContributor and overrding the createCommand Method
> like this:
I'd expect you'd to specialize the AdapterFactoryEditingDomain to create
a specialized command in createCommand.
>
>
>
> @Override
> public Command createCommand(Collection<?> selection)
> {
> Command command = removeAllReferences ?
> DeleteCommand.create(domain, selection) : RemoveCommand.create(domain,
> selection);
> CompoundCommand compoundCommand = new CompoundCommand();
> compoundCommand.append(command);
>
> EPA epa = EpaUtilToolboxModelAccess.getRootObject();
>
> Iterator<?> it = selection.iterator();
> if(it.hasNext()){
Why this guard when you have the same guard in the while loop. Why not
use a for loop?
> while(it.hasNext()){
> Object o = it.next();
> compoundCommand.append(AddCommand.create(domain,
> epa.getDeletedEpaObjects(),
> MetamodelPackage.eINSTANCE.getDeletedObjects_DeletedObject(),
> EcoreUtil.copy(eo)));
Why not create single addCommand that adds the collection?
MetamodelPackage.Literals.DELETED_OBJECTS__DELETED_OBJECT would be
slightly nicer.
> }
> }
> compoundCommand.setLabel("Compound " + command.getLabel());
> return compoundCommand;
> }
>
>
> This works fine so far....the objects gehts removed from the
> MyDataObjects list and is put into the DeletedObjects list......
Well, it puts copies in there...
>
> ...BUT when I trigger Undo in the generated rcp client the object is
> not removed from the DeletedObjects list.
What happens in AddCommand.doUndo?
> It is restored in the MyDataObjects list but stays in the
> DeletedObjects list.....the appended AddCommand seems not to be undone.
How can you tell? The IDE doesn't update or you've used the debugger
to see that the copies really aren't removed.
I don't see anything apparently wrong, so best to see what
AddCommand.doUndo is doing...
>
>
> There are not exceptions, not bad to see....it just does not work.
>
> Any ideas ?
>
> Greeting from Germany
|
|
|
|
|
|
|
|
Re: Extending DeleteAction/Command not undoable [message #904795 is a reply to message #904787] |
Wed, 29 August 2012 03:04  |
Eclipse User |
|
|
|
Markus,
Because delete is a global operation that's composed from SetCommand and
RemoveCommand that act on the individual objects and are deleted to the
item providers involved.
On 29/08/2012 8:54 AM, Markus Jo wrote:
> And antoher Question.....why there is a createRemoveCommand in the
> ItemProviderAdapter but no createDeleteCommand to overwrite ?
|
|
|
Powered by
FUDForum. Page generated in 0.29155 seconds