Skip to main content



      Home
Home » Modeling » EMF » Many-valued references in EMF
Many-valued references in EMF [message #1751069] Wed, 04 January 2017 04:48 Go to next message
Eclipse UserFriend
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 05:23 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Many-valued references in EMF [message #1751140 is a reply to message #1751077] Wed, 04 January 2017 16:35 Go to previous messageGo to next message
Eclipse UserFriend
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] Wed, 04 January 2017 23:57 Go to previous messageGo to next message
Eclipse UserFriend
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 01:29 Go to previous messageGo to next message
Eclipse UserFriend
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 01:32] by Moderator

Re: Many-valued references in EMF [message #1751826 is a reply to message #1751156] Sun, 15 January 2017 08:01 Go to previous messageGo to next message
Eclipse UserFriend
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 13:43 Go to previous message
Eclipse UserFriend
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?
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 Jul 08 05:28:36 EDT 2025

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

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

Back to the top