Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Dedicated editing domain for each model element editor in RCP?
[EMF] Dedicated editing domain for each model element editor in RCP? [message #1769386] Mon, 31 July 2017 09:20 Go to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
Hey @ll,

We are developing a "classic" RCP e4 application for editing different model objects in different editor tabs.
Initial, we had one global editing domain with an assigned command stack shared by all editor tabs. This worked with some flaws. The main problem is that we want to undo only the commands issued in one editor, when the user decides not to save the changes he made in the particular editor. Detecting the dirty state of the editor correctly is also hard as we not always we able to decide if a change on the command stack originated in the tab the user expected it.

To solve the problems, our main idea was to assign a dedicated editing domain to each model element per editor tab and remove it, when closing the editor. If the user decided to save his changes, all commands would have been added to the global command stack or would have been undone when closing the tab without saving. This works good when there is only one editor open at a time.

The editing domain is assigned like this:

modelElement.eResource().eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));


We are using EMFForms for the UI, which uses AdapterFactoryEditingDomain.getEditingDomainFor(modelElement); internally to retrieve the assigned editing domain.

Debugging the code we saw that with each opened editor a new IEditingDomainProvider is added to the ressource's adapter list leading to retrieve unexpected editing domains using AdapterFactoryEditingDomain.getEditingDomainFor(modelElement);.

We can't seem to get our head around how this is intended to work correctly. Is this the right approach for an e4 RCP application with multiple editing tabs or is there another recommended one? How can we be sure the editing domain assigned to a model element is the one we assigned to it and no other one to correctly undo all commands when not saving? Did we miss something important?

Any hint or help is highly appreciated! If you need some more information, I'm glad to provide it!

Thanks in advance,
Roman
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769396 is a reply to message #1769386] Mon, 31 July 2017 10:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

I've not exploited EditingDomains very positively myself, but your description conflicts with everything I expect.

If you have two tabs/pages/views/editors and you want a change in one to affect the other immediately, you should use a shared EditingDomain.

If you have two tabs/pages/views/editors and you want a change in one to have no effect the other until you invoke some form of probably save/load-based synchronization, you should use distinct EditingDomains.

Some tools listen effectively to the file system so that a save from one tool automatically updates another, but even when this is attempted, the user often has to respond correctly to a confusing file system changed message and understand which of the left hand or right hand work must be trashed in order to synchronize and continue editing.

I strongly suspect that you want the shared EditingDomain scenario.

Regards

Ed Willink
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769398 is a reply to message #1769396] Mon, 31 July 2017 10:36 Go to previous messageGo to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
Thanks for your input, Ed!

The shared EditingDomain scenario is an obvious choice and quite easy to implement, it works more or less out-of-the-box. From the end user's perspective, we think a distinct EditingDomain scenario feels like a better fit for our application. It avoids the flaws mentioned above and behaves similar to the Eclipse IDE, were changes, saving and redo/undo is managed per tab and not globally.

When editing an object in a tab, we don't want all other tabs to become dirty, too. And closing one tab without saving, we want the object to be like it was before opening, thus undoing the "right" commands is essential. This seems to to lead to the distinct EditingDomains scenario approach. But how to assign an editing domain to an model element such that AdapterFactoryEditingDomain.getEditingDomainFor(modelElement); returns the correct one? It seems that all editing domains are shared to all model elements through it's eRessource()...
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769400 is a reply to message #1769398] Mon, 31 July 2017 10:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

The 'dirty' problem is pushing you in the wrong direction. You 'just' need to override the dirty computation so that only those tabs/... that are logically dirty are marked as dirty.

Regards

Ed Willink
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769406 is a reply to message #1769400] Mon, 31 July 2017 11:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29545
Registered: July 2009
Senior Member
I wonder if there are multiple resources involved. Typically the editing domain provider is associated with the resource set, but org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(EObject) will look first for the IEditingDomainProvider on the containing resource, so if each tab is editing a separate resource and commands definitely do not ever result in changes to another resource, one could maintain separate editing domains with separate command stacks while still sharing a common resource set. It's just not clear how the separate tabs operate on separate model objects such there is no (need for) interaction between the separate editing domains.
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769407 is a reply to message #1769400] Mon, 31 July 2017 11:09 Go to previous messageGo to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
Ah, I see. We already use an adapter to determine changes on the model object itself, which works good for "normal" model elements. We also have model elements, were we want some contained objects to be edited in the same editor. We should add the dirty-adapter to the contained objects, too, I suppose...

But for the undoing case when not saving the editor changes on close, I don't see how this could work. Maybe looking at each unsaved command and determine, if it somehow affects the model element, which was opened in the editor before!?
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769409 is a reply to message #1769407] Mon, 31 July 2017 11:24 Go to previous messageGo to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
To be honest, the resource (set) concept for me still has it's secret. I do get that I had a misunderstanding how everything works together.

There should be only one ResourceSet involved at the moment for the whole domain model, so our idea was adding a editing domain to the resource of a particular model element to get all commands and listen for changes.

Say, we have an ecore model with the class Person and an RCP application to edit different model instances (Bob and Alice) in tabs. I still don't get, why editing Bob in a tab should affect Alice? And how can I easily undo all unsaved changes to Bob without looking at each and every command if I've a shared editing domain and command stack?

Thanks for your patience :)
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769410 is a reply to message #1769409] Mon, 31 July 2017 11:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

If Bob is Alice's father then deleting Bob has rather serious consequences for Alice ....

Having multiple Undo streams for each editing interface to a single logical model may seem nice, but it is very challenging to ensure coherence.

Regards

Ed Willink

Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1769664 is a reply to message #1769410] Wed, 02 August 2017 13:50 Go to previous message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
After more thinking about your feedback, we came to the conclusion that a global, i.e. shared, editing domain and dirty state is the only feasible solution. I changed our architecture accordingly and we have now achieved a working, consistent and correct user experience. Besides, the code has reduced a lot and is now easier to understand as we don't need to handle so many exceptional cases that we had, because there are always some dependencies between model elements we had to manage individual.

So, long story short: Thanks again for your valuable input that pushed me in the right direction! :)
Previous Topic:[CDO] Standalone Java Client - Help!
Next Topic:Update map using EditingDomain
Goto Forum:
  


Current Time: Sat Sep 22 03:37:59 GMT 2018

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

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

Back to the top