[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: Databinding and EFeatureMap (Re: AdapterFactoryContentProvider and notificat

Ed Merks wrote:

Ron,

I think I'd need to see a test case to track what's going wrong and to fix it. I can't quite see how it ended up in map code given you showed observing a list...

Hi, Ed!

I tried to step through the code and this is what happens:

Library library = (Library)

getEditingDomain().getResourceSet().getResources().get(0).getContents().get(0);

// A content provider that listens to an IObservableList
ObservableListContentProvider cp = new ObservableListContentProvider();
tableViewer2.setContentProvider(cp);


// Name column
maps = EMFObservables.observeMaps(cp.getKnownElements(), new EStructuralFeature[] {
ExtlibraryPackage.Literals.PERSON__LAST_NAME,
ExtlibraryPackage.Literals.PERSON__FIRST_NAME
});

Two EObjectObservableMaps are created which track cp.getKnownElements() (currently empty) as the set of keys.
// Address column
IObservableMap map = EMFObservables.observeMap(cp.getKnownElements(), ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);

Same here...

IObservableList list = EMFObservables.observeList(library, ExtlibraryPackage.Literals.LIBRARY__PEOPLE);
tableViewer2.setInput(list);

ObservableListContentProvider tries to populate cp.getKnownElements() set with the entries from library.getPeople(). As these are populated, the EObjectObservableMaps above get notified, and they try to hook themselves into the objects being added.


Normally (when the attribute is an EList containing EObjects) this works fine, but in this case the list contains FeatureMap.Entry objects.. The hook code in EObjectObservableMap assumes EObjects and so a CCE exception occurs.

 protected void hookListener(Object domainElement)
 {
 ((EObject)domainElement).eAdapters().add(elementListener);
 }

When I tried to change it to:
 protected void hookListener(Object domainElement)
 {
	  if (domainElement instanceof FeatureMap.Entry) {
		  EObject eo = (EObject) ((FeatureMap.Entry) domainElement).getValue();
		  eo.eAdapters().add(elementListener);
	  } else {
		  ((EObject)domainElement).eAdapters().add(elementListener);
	  }
 }

it works ok. (I had to change to other methods similarly, too).

I don't know if EObjectObservableMap is really supposed to handle the case of the key being a FeatureMap.Entry, or some unwrapping logic (FeatureMap.Entry#getValue()) needs to be inserted outside... (but where?) :-)

Cheers!
Ron