Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Forms, load persisted model problem(need help to load a saved model)
EMF Forms, load persisted model problem [message #1752017] Tue, 17 January 2017 21:01 Go to next message
Javier Alfonso is currently offline Javier AlfonsoFriend
Messages: 6
Registered: January 2017
Junior Member
I have a model, i created successfully my user interface with EMF Forms. I'm persisting my model with XMI, everything ok. the problem occurs when i load the saved model. The model is loaded successfully, i can walk through my model from code and everything ok. When i go to my app, the interface is rendered, but when i try to add, or edit any of my loaded objects, i get a null pointer exception, it's like my model is no more connected to my view.
Any suggestions?
Re: EMF Forms, load persisted model problem [message #1752083 is a reply to message #1752017] Wed, 18 January 2017 16:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I see you posted on the emf-dev mailing list as well. EMF Forums used the EMFT forum and prefer to have [EMF Forums] as a prefix in the subject line. Please include a stack trace in your post.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms, load persisted model problem [message #1752098 is a reply to message #1752083] Wed, 18 January 2017 18:09 Go to previous messageGo to next message
Javier Alfonso is currently offline Javier AlfonsoFriend
Messages: 6
Registered: January 2017
Junior Member
My load and save XMI code is based on Vogellas tutorial, maybe the problem is in the way i assign the loaded objects to the rendered object?
The code i'm using is:
C c = null;
c = (C) resource.getContents().get(0);
and then i render c using the SWT renderer.

The difference to a non saved object is that i use the factory.create method

the stack trace:
java.lang.NullPointerException
at org.eclipse.emf.ecp.internal.edit.ECPControlHelper.addModelElementInReference(ECPControlHelper.java:44)
at org.eclipse.emf.ecp.ui.view.swt.DefaultReferenceService.addNewModelElements(DefaultReferenceService.java:120)
at org.eclipse.emf.ecp.view.internal.control.multireference.MultiReferenceSWTRenderer.handleAddNew(MultiReferenceSWTRenderer.java:606)
at org.eclipse.emf.ecp.view.internal.control.multireference.MultiReferenceSWTRenderer$2.widgetSelected(MultiReferenceSWTRenderer.java:356)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1313)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3706)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:161)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
Re: EMF Forms, load persisted model problem [message #1752120 is a reply to message #1752098] Thu, 19 January 2017 03:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
They might see your post here and they might not. Perhaps post to the EMFT forum as I suggested.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms, load persisted model problem [message #1752145 is a reply to message #1752120] Thu, 19 January 2017 08:53 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 111
Registered: September 2016
Senior Member
Hi,

we saw it, but still as Ed suggested, kindly post EMF Forms related questions on the EMFT forum.

About your issue: The NPE occurs, because the DefaultReferenceService tries to retrieve an AdapterFactoryEditingDomain from the EObject. I assume the EObject has not been added to any resource? If so, you either need to do that before modifying it or implement a custom reference service, which behaves differently on adding new elements.

Best regards

Jonas

--
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/


--
Jonas Helming
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: EMF Forms, load persisted model problem [message #1752183 is a reply to message #1752145] Thu, 19 January 2017 13:48 Go to previous messageGo to next message
Javier Alfonso is currently offline Javier AlfonsoFriend
Messages: 6
Registered: January 2017
Junior Member
Thanks for the reply, how can i add the object to the resource?
Re: EMF Forms, load persisted model problem [message #1752195 is a reply to message #1752183] Thu, 19 January 2017 16:02 Go to previous messageGo to next message
Javier Alfonso is currently offline Javier AlfonsoFriend
Messages: 6
Registered: January 2017
Junior Member
The real problem with my code is that I'm still learning. After some digging on Jonas reply I found out that I should be using commands to modify my objects. The correct way is something like
"In EMF you deal a lot with model objects. Almost any UI selection operation hands over a model object to you. It is so easy to fall into the trap of changing the state of the model objects directly once you have access to it, either using the generated model API or using reflective methods. Problems due to such model updates are detected only later, mostly when Undo/Redo operations stops working as expected.
Use EMF Commands! Modify your model objects only using commands. Either directly using EMF commands, extending them or creating your own commands. When you need to club many operations as a single command use CompoundCommands. Use ChangeCommand when you are up to making a lot of model changes in a transactional way."
Re: EMF Forms, load persisted model problem [message #1752443 is a reply to message #1752195] Mon, 23 January 2017 19:35 Go to previous messageGo to next message
Javier Alfonso is currently offline Javier AlfonsoFriend
Messages: 6
Registered: January 2017
Junior Member
The final answer is:
With my original code, the Editing Domain after loading the model, was null, so the solution is to create an Editing Domain.
The solution is at http://eclipsesource.com/blogs/tutorials/emf-tutorial/
Re: EMF Forms, load persisted model problem [message #1752818 is a reply to message #1752443] Fri, 27 January 2017 16:20 Go to previous messageGo to next message
Javier Alfonso is currently offline Javier AlfonsoFriend
Messages: 6
Registered: January 2017
Junior Member
Even with my previous posted answer, i still get inconsistency in the model, probably because EMFForms is creating an extra Editing Domain, any suggestions?
Re: EMF Forms, load persisted model problem [message #1752820 is a reply to message #1752818] Fri, 27 January 2017 16:42 Go to previous message
Maximilian Koegel is currently offline Maximilian KoegelFriend
Messages: 11
Registered: January 2017
Junior Member
Hi,

please post your questions concerning EMF Forms to the EMFT forum. As pointed out multiple times earlier this is the WRONG forum.
Also please use "[EMF Forms]" as a subject prefix when posting on EMFT.
Finally double posting to the mailing-list and the forum is a discouraged behavior.

Thanks!

Cheers,
Maximilian

--
Get professional Eclipse developer support from EclipseSource


--
get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:Xcore Code Generator
Next Topic:Java to Ecore using annotation
Goto Forum:
  


Current Time: Fri Mar 29 14:05:01 GMT 2024

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

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

Back to the top