Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Extending DeleteAction/Command not undoable
Extending DeleteAction/Command not undoable [message #904474] Tue, 28 August 2012 09:42 Go to next message
Markus Jo is currently offline Markus Jo
Messages: 83
Registered: January 2012
Member
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25924
Registered: July 2009
Senior Member
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 #904761 is a reply to message #904482] Wed, 29 August 2012 01:43 Go to previous messageGo to next message
Markus Jo is currently offline Markus Jo
Messages: 83
Registered: January 2012
Member
Hi Ed,
specializing the AdapterFactoryEditingDomain is a better way than extending the DeleteAction ? Can you tell me why ? I have also added own Set and Add command by extending ItemProviderAdapter and overrdinging creatAddCommand and createSetCommand.....is this bad ? Why ?

Thanks for the other tips...its really an update problem of the treeviewer....undo does not properly refresh the view. But wiring an editor.getOutlineView.refresh() into the undoHandler would be not really nice, would it ?
Re: Extending DeleteAction/Command not undoable [message #904769 is a reply to message #904761] Wed, 29 August 2012 02:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25924
Registered: July 2009
Senior Member
Markus,

Comments below.

On 29/08/2012 7:43 AM, Markus Jo wrote:
> Hi Ed,
> specializing the AdapterFactoryEditingDomain is a better way than
> extending the DeleteAction ? Can you tell me why ?
Because the adapter factory editing domain acts as a factory for delete
commands
> I have also added own Set and Add command by extending
> ItemProviderAdapter and overrdinging creatAddCommand and
> createSetCommand.....is this bad ? Why ?
No, that's the normal way.
>
> Thanks for the other tips...its really an update problem of the
> treeviewer....undo does not properly refresh the view.
Does your item provider for that container produce notifications to
update the view? There's a GenFeature property for generating those.
> But wiring an editor.getOutlineView.refresh() into the undoHandler
> would be not really nice, would it ?
No, the model (the container of these copies) produces notifications
that are processed by the item provider and it decides if those should
produce viewer updates.
Re: Extending DeleteAction/Command not undoable [message #904777 is a reply to message #904769] Wed, 29 August 2012 02:23 Go to previous messageGo to next message
Markus Jo is currently offline Markus Jo
Messages: 83
Registered: January 2012
Member
So for own Set and Add commands the extended ItemProviderAdatper is the best way and for the own DeleteCommand its the own AdapterFactoryEditingDomain ?

I created the own AdapterFactoryEditingDomain in the initializeEditingDomain() of the MetamodelEditor class by doing this:

TransactionalEditingDomain domain = new TransactionalEditingDomainImpl(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)){

			@Override
			public Command createCommand(Class<? extends Command> commandClass, CommandParameter commandParameter) {
				
				if((commandClass == DeleteCommand.class)){
					
				}
				
				
				return super.createCommand(commandClass, commandParameter);
			}
			
			
			
		};
		((TransactionalEditingDomainImpl.FactoryImpl)TransactionalEditingDomain.Factory.INSTANCE).mapResourceSet(domain);




Is this ok ? Whats with the RemoveCommand ? This should have the deletedObjects logic, too. I would override it too, don´t I ?


And the question is, overriding with what ? I thought I replace the DeleteCommand with an MyDeleteCommand that extend from the deleteCommand and just chain my Add command to it. Would that be the right or or does extending of the the DeleteCommand will cause that the AdapterFactoryEditingDomain createCommand is called again and I run into a stack overflow ?

[Updated on: Wed, 29 August 2012 02:38]

Report message to a moderator

Re: Extending DeleteAction/Command not undoable [message #904785 is a reply to message #904777] Wed, 29 August 2012 02:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25924
Registered: July 2009
Senior Member
Markus,

Comments below.

On 29/08/2012 8:23 AM, Markus Jo wrote:
> So for own Set and Add commands the extended ItemProviderAdatper is
> the best way and for the own DeleteCommand its the own
> AdapterFactoryEditingDomain ?
Yes, those are the factories for the commands.
>
> I created the own AdapterFactoryEditingDomain in the
> initializeEditingDomain() of the MetamodelEditor class by doing this:
>
>
> TransactionalEditingDomain domain = new
> TransactionalEditingDomainImpl(new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)){
>
> @Override
> public Command createCommand(Class<? extends Command>
> commandClass, CommandParameter commandParameter) {
>
> if((commandClass == DeleteCommand.class)){
>
> }
>
>
> return super.createCommand(commandClass,
> commandParameter);
> }
>
>
>
> };
> ((TransactionalEditingDomainImpl.FactoryImpl)TransactionalEditingDomain.Factory.INSTANCE).mapResourceSet(domain);
>
>
>
>
> Is this ok ?
Yep.
> Whats with the RemoveCommand ?
What about it?
> This show have the deletedObjects logic, too. I would override it too,
> don´t I ?
Look and the base class (super) to see what it's doing. The
AdapterFactoryEditingDomain is only a factory for commands that can't be
delegated to a specify item provider because they act globally.
>
>
> And the question is, overriding with what ?
With what you showed in the action.
> I that I replace the DeleteCommand with an MyDeleteCommand that extend
> from the deleteCommand and just chain my Add command to it. Would that
> be the right or or does extending of the the DeleteCommand will cause
> that the AdapterFactoryEditingDomain createCommand is called again and
> I run into a stack overflow ?
The debugger is good at answering questions. What you showed before can
just be moved here.
Re: Extending DeleteAction/Command not undoable [message #904787 is a reply to message #904777] Wed, 29 August 2012 02:54 Go to previous messageGo to next message
Markus Jo is currently offline Markus Jo
Messages: 83
Registered: January 2012
Member
And antoher Question.....why there is a createRemoveCommand in the ItemProviderAdapter but no createDeleteCommand to overwrite ?

Where to overwrite the RemoveCommand ? In the AdapterFactoryEditingDomain, too ? Or by the createRemoveCommand in the ItemProviderAdapter ?


I set my own Command (which extends DeleteCommand) like this:
TransactionalEditingDomain domain = new TransactionalEditingDomainImpl(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)){

			@Override
			public Command createCommand(Class<? extends Command> commandClass, CommandParameter commandParameter) {
				
				if((commandClass == DeleteCommand.class)){
					return new MyDeleteCommand(commandParameter);
				}
				return super.createCommand(commandClass, commandParameter);
			}
		};

Is that ok ?



[Updated on: Wed, 29 August 2012 02:59]

Report message to a moderator

Re: Extending DeleteAction/Command not undoable [message #904795 is a reply to message #904787] Wed, 29 August 2012 03:04 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25924
Registered: July 2009
Senior Member
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 ?
Previous Topic:Which EMF Compare for EMF 2.4
Next Topic:Resource sync issue
Goto Forum:
  


Current Time: Mon Jul 28 06:32:08 EDT 2014

Powered by FUDForum. Page generated in 0.03060 seconds