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: 7655
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: 7655
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: 33141
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.

Ed Merks
Professional Support: https://www.macromodeling.com/
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: 7655
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 messageGo to next 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! :)
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1855454 is a reply to message #1769664] Sat, 15 October 2022 09:15 Go to previous messageGo to next message
Azalea Michaels is currently offline Azalea MichaelsFriend
Messages: 1
Registered: October 2022
Junior Member
Hi, this is Azalea, and I am a Marketing Manager at NamoBOT which is a leading business name generating tool. I created my library application by following a guide, and I was successful.
However, I ran into a problem with the tree view in the "Outline" panel: the labels for the model's elements remain white, with the model's "name"-attributed elements being the only exception.

For clarity, here is a screen shot:

screen_outline_tree

Although these labels are selectable, as you can see, the entire tree in the Outline view is composed of empty ones. Only elements from the class Author (which have a "name" attribute) are displayed.

Is there an alternative to assigning each entity a unique "name" attribute to solve the issue?
Re: [EMF] Dedicated editing domain for each model element editor in RCP? [message #1855464 is a reply to message #1855454] Sun, 16 October 2022 06:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
For every class Abc there is a generated AbcItemProvider with a getText method. You can specialize it to return what you want for the text:
  /**
   * This returns the label text for the adapted class.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  @Override
  public String getText(Object object)
  {
Be sure to change the @generated to something like @generated NOT so that you don't overwrite your hand written code when you regenerate.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Generating errors in java class from an xsd file that contains special character like "µ"
Next Topic:CDO commit change procedure
Goto Forum:
  


Current Time: Thu Apr 25 16:03:58 GMT 2024

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

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

Back to the top