Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Update map using EditingDomain
Update map using EditingDomain [message #1769661] Wed, 02 August 2017 13:38 Go to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
I have a model providing an EClass with a reference to a map, like described in the FAQ [1]. Now I would like to update that map using an EditingDomain.

Question 1: how do I create a new Instance of EStringToEStringMapEntry? The model factory does not provide anything here. I guess I could use an AddCommand to add the new entry to my map

Question 2: in case my map contains already an entry with the same key, will the AddCommand be the right choice?

thanks

[1] https://wiki.eclipse.org/EMF/FAQ#How_do_I_create_a_Map_in_EMF.3F
Re: Update map using EditingDomain [message #1769677 is a reply to message #1769661] Wed, 02 August 2017 15:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is how org.eclipse.emf.ecore.provider.EAnnotationItemProvider.collectNewChildDescriptors(Collection<Object>, Object) ensures that new map entry children are created for the EAnnotation.details feature:
  /**
   * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
   * that can be created under this object.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  @Override
  protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object)
  {
    // super.collectNewChildDescriptors(newChildDescriptors, object);

    newChildDescriptors.add
    (createChildParameter
      (EcorePackage.Literals.EANNOTATION__DETAILS,
       EcoreFactory.eINSTANCE.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY)));
  }
In the end, it's added with an AddCommand. The AddCommand will not ensure/validate that the keys are unique.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Update map using EditingDomain [message #1769759 is a reply to message #1769677] Thu, 03 August 2017 07:45 Go to previous messageGo to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
Thanks Ed, creation of the map entry works.
As you wrote that the add command will not ensure uniqueness of map keys I guess the correct way would be to create a compound command containing a 'remove existing' and an 'add new entry', right?
Re: Update map using EditingDomain [message #1769770 is a reply to message #1769759] Thu, 03 August 2017 09:39 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This really depends on the context. In an Ecore model you can create many EAnnotation.details entries. They all start out with a null key and a null value. If you add more than one, and the Live Validation is enabled (you can set Decoration to Live to generate an editor like that), then there will be error markers to show that the keys aren't unique. The user can fix those errors. The user can also change the value of a key so that it's no longer unique. Nothing prevents those changes, but validation will show them as problems. So I don't know the context in which you're creating the commands. If you know up front that the user wants to add an entry with a given key and value, you could create an AddCommand to add a new entry or create a SetCommand to modify the value feature of an existing entry.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Standalone Java Client - Help!
Next Topic:EAnnotation usage in ecore
Goto Forum:
  


Current Time: Thu Apr 25 02:31:48 GMT 2024

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

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

Back to the top