Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » I create an xml element by right click to EMF editor. Default values appear but not get saved to xml(Default value appears in editor but not get saved in xml. If I set return value of generated Impl classes isSetABC function to true they get saved.)
I create an xml element by right click to EMF editor. Default values appear but not get saved to xml [message #1815222] Fri, 27 September 2019 12:48 Go to next message
ilke Muhtaroglu is currently offline ilke MuhtarogluFriend
Messages: 44
Registered: September 2015
Member
I have read that XMLResource.OPTION_KEEP_DEFAULT_CONTENT should be set to True.

But where, I have genmodel and ecore and generated classes.

Can we make that default values which appear in EMF editor get saved after generating them via right click. If I set xsd complex type's generated Impl.java classes isSetAttributeName method to return true than I get the default values appear in saved xml.

But when I regenerate from genmodel this change will be deleted. And It looks like this is not the right place to do saving the default values...

Is there a way to make emf editor save the default values it shows in properties to xml via setting a parameter in genmodel or ecore ?

If this is not possible to do in genmodel or ecore, how can we make emf editor save the default values that get initialized when we generate a xml element.
Re: I create an xml element by right click to EMF editor. Default values appear but not get saved to [message #1815224 is a reply to message #1815222] Fri, 27 September 2019 13:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
That option is implemented in org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.shouldSaveFeature(EObject, EStructuralFeature) like this
  protected boolean shouldSaveFeature(EObject o, EStructuralFeature f)
  {
    return o.eIsSet(f) || keepDefaults && f.getDefaultValueLiteral() != null;
  }
So it only saves what's explicit set as the default value of the feature. It does not save implicit defaults (and only primitives and enums have implicit defaults). You could modify your model (Ecore or XML Schema) to specify a default (the value you want to see serialized) for each EAttribute in Ecore for each simple-typed element/attribute, or specialize that method in some other way.
Re: I create an xml element by right click to EMF editor. Default values appear but not get saved to [message #1815226 is a reply to message #1815224] Fri, 27 September 2019 13:58 Go to previous messageGo to next message
ilke Muhtaroglu is currently offline ilke MuhtarogluFriend
Messages: 44
Registered: September 2015
Member
Ed thanks for your answers to emf questions. You help us a lot.

I have set an elements attribute to default value like 0.1 . I see it appears in property view in emf xml editor.

I see it is set in attributes Default Value Literal as 0.1.

But it does not appear in saved xml. Do I need to set something else?

If I make isSetAttributeName returns true, then it is saved but this is a workaround.

How can we make this default value that appears in attributes Default Value Literal as 0.1 saved in emf editors xml file ? Do I need to set something else than attributes Default Value Literal ?

Thanks for answers again.
Re: I create an xml element by right click to EMF editor. Default values appear but not get saved to [message #1815258 is a reply to message #1815226] Sat, 28 September 2019 02:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
Did you actually use the option in your generated XyzResourceFactoryImpl's createResource method? Did you set a breakpoint in shouldSaveFeature to see what's happening there? The debugger answers questions faster than I can.
Re: I create an xml element by right click to EMF editor. Default values appear but not get saved to [message #1815304 is a reply to message #1815258] Mon, 30 September 2019 07:29 Go to previous message
ilke Muhtaroglu is currently offline ilke MuhtarogluFriend
Messages: 44
Registered: September 2015
Member
Ok. I assumed setting XMLResource.OPTION_KEEP_DEFAULT_CONTENT to true is not mandatory.

I set it in XYZEditor.java classes in public void doSave method to true.

There I put

saveOptions.put( XMLResource.OPTION_KEEP_DEFAULT_CONTENT, true);

then After putting a debug point as Ed poposed I hit the debugpoint when I save the xml in editor. (Which I debugged as Eclipse Application...)

In XYZEditor.java class (The class that is generated in presentation package and that ends with ...Editor.java class name.) and at public void execute method at line :

resource.save(saveOptions); the debug method hierarchy the debug stops at shouldSaveFeature method...

Thanks for the help.

[Updated on: Mon, 30 September 2019 07:33]

Report message to a moderator

Previous Topic:Hide specific elements in tree editor
Next Topic:Too many constants, the constant pool for AlgoIQPackage would exceed 65536 entries
Goto Forum:
  


Current Time: Mon Dec 09 20:25:49 GMT 2019

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

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

Back to the top