[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: IWrapperItemProvider & databinding

Hi Tom,

Thanks for your response. I'd be a happier coder today if I had read your blog a bit more closely before I set out!

Rather than using the EMF Properties API, I have been using EMFEditObservables, so I would have to do a large amount of refactoring to follow your approach - too much effort at this stage, but next time I'll do things that way.

The cause of my immediate problem (losing selection) was down to some sloppy code on my part to manually handle refreshing of my TreeViewer. I have since overriden the notifyChanged() methods in my ItemProviders to handle notifications for the EStructuralFeatures that I need, so that problem is solved.

However, I still need to extract the wrapped EObject for my binding code to work. I expect that might be unnecessary if I were using the EMFProperties API. This approach is working ok, but required a hack whereby the appropriate ItemProvider wraps commands so that the DelegatingWrapperItemProvider is included in the affected objects. For this to work, the ItemProvider gets the current selection from the platform's SelectionService. Not too clean, but works for me now.

To address your questions below directly, I am using IObservableValue as the master for detail bindings (actually, a few - one for each type of object that would be in the viewer). I am also using the generated EMF edit code for setting up my TreeViewer (and most other things). However, I subclass a great deal to customise behaviour, rather than working directly with the genmodel. The reason for this is that I find I usually want different behaviours (e.g. children, labels, etc.) in different contexts in my app, so I would need to subclass my ItemProviders and AdapterFactory in any case.

Thanks again for your response,

Stephen

Tom Schindl wrote:
Stephen Egan schrieb:
Hi,

I'm having trouble with my databinding code when using EObject wrappers.
 Briefly, I am binding a custom composite with different widgits for
relevant EStrucuturalFeatures of a selected EObject instance (selection
coming from TreeViewer).  One of the EObject types in the TreeViewer is
wrapped in a DelegatingWrapperItemProvider instance.  This is because an
instance of that object will be referenced from two other
non-containment EReferences of two parent objects.  The
DelegatingWrapperItemProvider getColumnText() method is overridden to
return a different value depending on which EReference returned the
instance from a parent object.  (E.g. a single  "FloorCeiling" EObject
should be labeled "Floor XXX" or "Ceiling XXX" depending on whether the
the reference was returned from a "floors" or "ceilings" EReference in
the parent object).

The trouble I am having is with my IObservableValue that is tracking the
selection.  If I adjust that to look for and unwrap
IWrappingItemProviders, the databinding code works ok, but the selection
is lost as a result of the wrapped value being included in a Command's
affectedObjects list, rather than the wrapper.  If I do not adjust the
IObservableValue, the databinding code doesn't seem to work, resulting
in empty widgits.

Could you provide some (pseudo) code so that I understand this better? I guess you are using the IObservableValue as the master for detail bindings. You could mimic this using an ISelectionChangeListener and a WritableValue.

One final question is why you are not using the JFace-Support for
setting up your TreeViewer instead [1] which probably makes wrapping
your EObject's unnecessary (Please note I have no idea how the EMF
generated stuff work because I've never used it so my assumption might
be wrong)

Tom


[1]http://tomsondev.bestsolution.at/2009/06/08/galileo-emf-databinding-%E2%80%93-part-3/