Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Many-valued references in EMF
Many-valued references in EMF [message #1751069] Wed, 04 January 2017 09:48 Go to next message
Carsten Tsara is currently offline Carsten TsaraFriend
Messages: 11
Registered: March 2016
Junior Member
In a model I have an object with a reference which is multiplicity-many and is not containment. And currently I'm struggling with some operations.
First, I need to override getParent() in ItemProvider for drag and drop operations. Default implementation returns actual container of the referenced object, but what I really need is to get somehow EObject which holds the list of references.

My structure is similar to this
Container1
-- MyObject1
Container2
-- MyObject2

Item1
-- Ref MyObject1
-- Ref MyObject2
Item2
-- Ref MyObject1
Item3
-- Ref MyObject2

so I have method in Item class EList<MyObject> getMyObjects(). In the UI I display only Items and references to MyObjects. And I'm struggling to get Item object for MyObject inside getParent()
Re: Many-valued references in EMF [message #1751077 is a reply to message #1751069] Wed, 04 January 2017 10:23 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
You can override org.eclipse.emf.edit.provider.ItemProviderAdapter.isWrappingNeeded(Object) to always return true. In that case, org.eclipse.emf.edit.provider.ItemProviderAdapter.createWrapper(EObject, EStructuralFeature, Object, int) will be called and will hit:
    else if (!((EReference)feature).isContainment())
    {
      value = new DelegatingWrapperItemProvider(value, object, feature, index, adapterFactory);
    }
And that will ensure that the wrapper knows the parent, but otherwise delegates to the item provider of the value for labels, children, and properties. After all, such a referenced "child" could appear more than once in the tree, so the wrapper ensures each occurrence knows the parent under which it is being shown in the tree.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Many-valued references in EMF [message #1751140 is a reply to message #1751077] Wed, 04 January 2017 21:35 Go to previous messageGo to next message
Carsten Tsara is currently offline Carsten TsaraFriend
Messages: 11
Registered: March 2016
Junior Member
Thanks, it helped me with my problem, but another one arose as a consequence.
I have DiagnosticDecorator like this
new ColumnViewerInformationControlToolTipSupport(selectionViewer, new DiagnosticDecorator.EditingDomainLocationListener(editingDomain, selectionViewer))
and inside it I get following NPE for wrapped objects
java.lang.NullPointerException: null
	at org.eclipse.jface.resource.ImageDataImageDescriptor.<init>(ImageDataImageDescriptor.java:36) ~[na:na]
	at org.eclipse.jface.resource.ImageDescriptor.createFromImage(ImageDescriptor.java:104) ~[na:na]
	at org.eclipse.emf.common.ui.ImageURIRegistry.getImageURI(ImageURIRegistry.java:51) ~[na:na]
	at org.eclipse.emf.edit.ui.provider.DiagnosticDecorator.buildToolTipMessage(DiagnosticDecorator.java:1637) ~[na:na]
	at org.eclipse.emf.edit.ui.provider.DiagnosticDecorator.buildToolTipText(DiagnosticDecorator.java:1587) ~[na:na]
	at org.eclipse.emf.edit.ui.provider.DiagnosticDecorator.getToolTipText(DiagnosticDecorator.java:1568) ~[na:na]
	at org.eclipse.emf.edit.ui.provider.DecoratingColumLabelProvider.getToolTipText(DecoratingColumLabelProvider.java:143) ~[na:na]
	at org.eclipse.emf.common.ui.viewer.ColumnViewerInformationControlToolTipSupport.shouldCreateToolTip(ColumnViewerInformationControlToolTipSupport.java:730) ~[na:na]
	at org.eclipse.emf.common.ui.viewer.ColumnViewerInformationControlToolTipSupport$3.computeInformation(ColumnViewerInformationControlToolTipSupport.java:527) ~[na:na]
	at org.eclipse.jface.text.AbstractInformationControlManager.doShowInformation(AbstractInformationControlManager.java:1131) ~[na:na]

Could you give me a hint how to fix it?
Re: Many-valued references in EMF [message #1751154 is a reply to message #1751140] Thu, 05 January 2017 04:57 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
It seems that in org.eclipse.emf.edit.ui.provider.DiagnosticDecorator.buildToolTipMessage(StringBuilder, ILabelProvider, Object, Diagnostic, int) the label provider of your viewer returns null for one of the EObjects in the diagnostic's getData().

The cause for a NullPointerException is normally quite easy to find with the help of the debugger. See http://www.vogella.com/tutorials/EclipseDebugging/article.html on how to use it.


Re: Many-valued references in EMF [message #1751156 is a reply to message #1751154] Thu, 05 January 2017 06:29 Go to previous messageGo to next message
Carsten Tsara is currently offline Carsten TsaraFriend
Messages: 11
Registered: March 2016
Junior Member
I am able to find the cause of NPE Smile I just could not understand the reason, that's why I asked if I could missed something in customizing ItemProviders. Thank you anyway. I found the reason: I set label providers only to the columns of the tree, but label provider also should be set to the tree itself. I was confused because this exception occurs only when I use wrappers, with EObjects everything is OK.

[Updated on: Thu, 05 January 2017 06:32]

Report message to a moderator

Re: Many-valued references in EMF [message #1751826 is a reply to message #1751156] Sun, 15 January 2017 13:01 Go to previous messageGo to next message
Carsten Tsara is currently offline Carsten TsaraFriend
Messages: 11
Registered: March 2016
Junior Member
With wrappers I have an issue with live validation and DiagnosticDecorator. For wrapped children I see diagnostics that are related to the EObject itself, but not to the reference. How can I change this behavior?
Re: Many-valued references in EMF [message #1751831 is a reply to message #1751826] Sun, 15 January 2017 18:43 Go to previous message
Ed Merks is currently online Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Sorry, but I'm not sure how that relates to this thread. I assume there's no null pointer exception involved.

If there is a problem, I'll need to reproduce it. How might I reproduce the problem you're seeing?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Xcore] specifying a setter for a many-valued derived feature
Next Topic:[Xcore] control whether ecore file is generated or not
Goto Forum:
  


Current Time: Tue Apr 23 08:07:31 GMT 2024

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

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

Back to the top