Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » DeleteCommand on a resource(How to properly delete an EMF resource in a transaction)
DeleteCommand on a resource [message #1841292] Tue, 11 May 2021 10:10 Go to next message
Wernke zur Borg is currently offline Wernke zur BorgFriend
Messages: 42
Registered: December 2011
Member
Hi all,

I am trying to "properly" delete a loaded EMF Resource in our application within a transaction. The deletion is supposed to (in whatever order):

  • Unload the resource
  • Delete all references to contained objects from the rest of the model
  • Physically delete the resource file

The most obvious way to do it would be the usage of a DeleteCommand with the Resource object as value. But this does not work because the ResourceSetItemProvider cannot create a RemoveCommand for the resource. I found an ancient post in this context: DeleteCommand on top level resource contents but I am still not sure what to do. Does it mean I have to override createCommand() in a subclass of ResourceSetItemProvider and do all the above steps in a custom RemoveCommand? Does anybody have an example of that? It seems to me like a common use case but I can't find anything usable, and I feel like reinventing the wheel.

Remark 1: The deletion of all incoming references is already nicely supported by the DeleteCommand, and I can subclass it to use the ECrossReferenceAdapter for finding the usages in a performant way. The problem is one step before, in the deletion of the resource.

Remark 2: There is no strict requirement in that the deletion shall be undoable; the user can be warned.

Thanks for all hints.
Wernke

[Updated on: Tue, 11 May 2021 10:19]

Report message to a moderator

Re: DeleteCommand on a resource [message #1841318 is a reply to message #1841292] Wed, 12 May 2021 06:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32027
Registered: July 2009
Senior Member
Yes, you need a subclass of ResourceSetItemProvider and specialize it for the commands you want it to support either by specializing createCommand or factorRemoveCommand.

If I were to implement this, I'd probably try to find a way to make it undoable. So not unload the resource and not physically delete the resource until a save is done in the editor; note that Resource.delete is available and that could be used during save for resources marked for deletion; you can always store additional state on the resource set or on a resource via an adapter; or make the resource set item provider itself stateful. The initial remove of a resource from a resource set could delete the top resource contents, could remove these objects from the resource itself and the resource from the resource set (both using org.eclipse.emf.edit.command.RemoveCommand.RemoveCommand(EditingDomain, EList<?>, Object)). You could record such "removed/deleted resources" such that in *Editor.doSave you could call Resource.delete for them (instead of saving an empty resource). Even an undo after the save would be possible because the undo would put the resource back in the resource set, put the root objects back in the resource, and restore all the removed links to the objects in the resource such that a save would restore this original state


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteCommand on a resource [message #1841321 is a reply to message #1841318] Wed, 12 May 2021 08:20 Go to previous message
Wernke zur Borg is currently offline Wernke zur BorgFriend
Messages: 42
Registered: December 2011
Member
Thanks a lot again Ed, that sounds very promising, and it should get me going for now.
Previous Topic:Scoping in EMF generated Editor
Next Topic:[CDO] Updates to model objects creates new table entry instead of incrementing the revision?
Goto Forum:
  


Current Time: Sun Sep 26 16:54:21 GMT 2021

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

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

Back to the top