Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Exception when trying to observe a value for a particular key in an EMap
Exception when trying to observe a value for a particular key in an EMap [message #975544] Wed, 07 November 2012 23:55 Go to next message
William Saar is currently offline William Saar
Messages: 16
Registered: July 2009
Junior Member
Hi,
I am trying to create an observable that tracks the value of the entry with key "param1" in an EMF-model EMap to bind it to a SWT control, but I get the exception at the bottom. Is it possible to observe the value of a key in an EMF map? or is there another way?

IEMFMapProperty mapProperty = EMFEditProperties.map(editingDomain, ModelPackage.eINSTANCE.getSettings_Parameters());
IObservableMap map = mapProperty.observe(SWTObservables.getRealm(Display.getCurrent()), settings.getParameters());
context.bindValue(SWTObservables.observeSelection(param1Scale), Observables.observeMapEntry(map, "param1"));

Exception:

java.lang.ClassCastException: org.eclipse.emf.ecore.util.EcoreEMap cannot be cast to org.eclipse.emf.ecore.EObject
at org.eclipse.emf.databinding.internal.EMFMapProperty.doGetMap(EMFMapProperty.java:87)
at org.eclipse.core.databinding.property.map.MapProperty.getMap(MapProperty.java:56)
at org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap.getMap(SimplePropertyObservableMap.java:128)
at org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap.access$0(SimplePropertyObservableMap.java:127)
at org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap$3.run(SimplePropertyObservableMap.java:106)
at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:148)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
at org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap.firstListenerAdded(SimplePropertyObservableMap.java:104)
at org.eclipse.core.databinding.observable.map.AbstractObservableMap$PrivateChangeSupport.firstListenerAdded(AbstractObservableMap.java:50)
at org.eclipse.core.databinding.observable.ChangeManager.addListener(ChangeManager.java:70)
at org.eclipse.core.databinding.observable.ChangeSupport.addListener(ChangeSupport.java:30)
at org.eclipse.core.databinding.observable.map.AbstractObservableMap.addMapChangeListener(AbstractObservableMap.java:98)
at org.eclipse.core.databinding.observable.map.DecoratingObservableMap.firstListenerAdded(DecoratingObservableMap.java:82)
at org.eclipse.core.databinding.observable.ChangeManager.addListener(ChangeManager.java:70)
at org.eclipse.core.databinding.observable.map.DecoratingObservableMap.addMapChangeListener(DecoratingObservableMap.java:48)
at org.eclipse.core.internal.databinding.observable.MapEntryObservableValue.<init>(MapEntryObservableValue.java:78)
at org.eclipse.core.databinding.observable.Observables.observeMapEntry(Observables.java:591)
at org.eclipse.core.databinding.observable.Observables.observeMapEntry(Observables.java:564)


MediaOrgan - media organizer for your local computer and the web using Eclipse RCP/RAP - http://mediaorgan.com
Re: Exception when trying to observe a value for a particular key in an EMap [message #975825 is a reply to message #975544] Thu, 08 November 2012 05:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26129
Registered: July 2009
Senior Member
William,

The individual Map.Entry instances in an EMap feature in a model are
also EObjects and can be observed like any other EObject, but the EMap
as a whole isn't an EObject. You shouldn't change the key feature of a
map entry; it will corrupt the map index once there is an index.

On 08/11/2012 12:55 AM, William Saar wrote:
> Hi,
> I am trying to create an observable that tracks the value of the entry
> with key "param1" in an EMF-model EMap to bind it to a SWT control,
> but I get the exception at the bottom. Is it possible to observe the
> value of a key in an EMF map? or is there another way?
>
> IEMFMapProperty mapProperty = EMFEditProperties.map(editingDomain,
> ModelPackage.eINSTANCE.getSettings_Parameters());
> IObservableMap map =
> mapProperty.observe(SWTObservables.getRealm(Display.getCurrent()),
> settings.getParameters());
> context.bindValue(SWTObservables.observeSelection(param1Scale),
> Observables.observeMapEntry(map, "param1"));
>
> Exception:
>
> java.lang.ClassCastException: org.eclipse.emf.ecore.util.EcoreEMap
> cannot be cast to org.eclipse.emf.ecore.EObject
> at
> org.eclipse.emf.databinding.internal.EMFMapProperty.doGetMap(EMFMapProperty.java:87)
> at
> org.eclipse.core.databinding.property.map.MapProperty.getMap(MapProperty.java:56)
> at
> org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap.getMap(SimplePropertyObservableMap.java:128)
> at
> org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap.access$0(SimplePropertyObservableMap.java:127)
> at
> org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap$3.run(SimplePropertyObservableMap.java:106)
> at
> org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:148)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
> at
> org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
> at org.eclipse.core.databinding.observable.Realm.exec(Realm.java:170)
> at
> org.eclipse.core.internal.databinding.property.map.SimplePropertyObservableMap.firstListenerAdded(SimplePropertyObservableMap.java:104)
> at
> org.eclipse.core.databinding.observable.map.AbstractObservableMap$PrivateChangeSupport.firstListenerAdded(AbstractObservableMap.java:50)
> at
> org.eclipse.core.databinding.observable.ChangeManager.addListener(ChangeManager.java:70)
> at
> org.eclipse.core.databinding.observable.ChangeSupport.addListener(ChangeSupport.java:30)
> at
> org.eclipse.core.databinding.observable.map.AbstractObservableMap.addMapChangeListener(AbstractObservableMap.java:98)
> at
> org.eclipse.core.databinding.observable.map.DecoratingObservableMap.firstListenerAdded(DecoratingObservableMap.java:82)
> at
> org.eclipse.core.databinding.observable.ChangeManager.addListener(ChangeManager.java:70)
> at
> org.eclipse.core.databinding.observable.map.DecoratingObservableMap.addMapChangeListener(DecoratingObservableMap.java:48)
> at
> org.eclipse.core.internal.databinding.observable.MapEntryObservableValue.<init>(MapEntryObservableValue.java:78)
> at
> org.eclipse.core.databinding.observable.Observables.observeMapEntry(Observables.java:591)
> at
> org.eclipse.core.databinding.observable.Observables.observeMapEntry(Observables.java:564)
Re: Exception when trying to observe a value for a particular key in an EMap [message #976981 is a reply to message #975825] Fri, 09 November 2012 00:50 Go to previous messageGo to next message
William Saar is currently offline William Saar
Messages: 16
Registered: July 2009
Junior Member
Ok, I don't see how I am changing the key from the public APIs I'm calling so maybe there is a problem with their implementation?

I thought I was using a map property binding mechanism implemented for this exact problem after the discussion in this thread
http://www.eclipse.org/forums/index.php/mv/msg/135844/427374/

...but I was never really certain about the outcome of that thread (the APIs don't seem to contain a method such as the EMFObservables#observeMapEntry-method that is discussed there).

Anyway, I solved it by adding the following helper method, but it would be nice for EMF-databindings to support it directly
private IObservableValue observeSettingsValue(EditingDomain editingDomain, final EMap parameters, String key, EStructuralFeature valueFeature) {
		if (parameters.indexOfKey(key) < 0) {
			parameters.put(key, null);
		}
		return EMFEditObservables.observeValue(SWTObservables.getRealm(Display.getCurrent()),
				editingDomain, 
				(EObject) parameters.get(parameters.indexOfKey(key)),
				valueFeature);				
	}


MediaOrgan - media organizer for your local computer and the web using Eclipse RCP/RAP - http://mediaorgan.com
Re: Exception when trying to observe a value for a particular key in an EMap [message #977160 is a reply to message #976981] Fri, 09 November 2012 04:23 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26129
Registered: July 2009
Senior Member
William,

Comments below.

On 09/11/2012 1:50 AM, William Saar wrote:
> Ok, I don't see how I am changing the key from the public APIs I'm
> calling so maybe there is a problem with their implementation?
No, I'm just warning you in advance of any attempts to do so.
>
> I thought I was using a map property binding mechanism implemented for
> this exact problem after the discussion in this thread
> http://www.eclipse.org/forums/index.php/mv/msg/135844/427374/
> ..but I was never really certain about the outcome of that thread (the
> APIs don't seem to contain a method such as the
> EMFObservables#observeMapEntry-method that is discussed there).
See what Tom says...
>
> Anyway, I solved it by adding the following helper method, but it
> would be nice for EMF-databindings to support it directly
We'll wait for Tom's reaction. He's the responsible committer for the
data binding APIs...
>
> private IObservableValue observeSettingsValue(EditingDomain
> editingDomain, final EMap parameters, String key, EStructuralFeature
> valueFeature) {
> if (parameters.indexOfKey(key) < 0) {
> parameters.put(key, null);
> }
> return
> EMFEditObservables.observeValue(SWTObservables.getRealm(Display.getCurrent()),
> editingDomain, (EObject)
> parameters.get(parameters.indexOfKey(key)),
> valueFeature);
> }
>
Previous Topic:[CDO] SSL Server [ERROR] BufferUnderflowException
Next Topic:[CDO] Cert management for SSL connections to CDO server
Goto Forum:
  


Current Time: Tue Oct 21 15:19:46 GMT 2014

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

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