isFactoryForType implementation guideline for adapter factories used by AdapterFactoryContentProvide [message #1734929] |
Mon, 13 June 2016 16:04  |
Eclipse User |
|
|
|
Hi all
I want to register adapter factories that provide adapters from EMF objects defined in multiple model packages to jface content and label providers.
Guided by http://help.eclipse.org/juno/topic/org.eclipse.emf.doc/references/overview/EMF.Edit.html I configure a TreeViewer with an AdapterFactoryContentProvider and an AdapterFactoryLabelProvider, which are initialized with a ComposedAdapterFactory.
I learned that the framework calls the isFactoryForType method for each registered AdapterFactory multiple times to decide whether the adapter factory can provide a suitable adapter or not.
The javadoc is not to clear about what is tested there, i.e. to which set of type objects the adapter is expected to conform.
For example, there are package objects being supplied as input types but it is unclear for me for what reasons.
Moreover, I learned that if multiple adapter factories conform to a specific set of calls to isFactoryForType, just the first adapter factory will be used to provide adapters.
What are the rules of how the isFactoryForType is used by the framework (specifically the ComposedAdapterFactory and the AdapterFactory[Content|Label]Provider setup)?
How are the isFactoryForType methods to be implemented if multiple adapter factories for multiple EMF models (packages) are to be registered?
Greetings
Thilo
|
|
|
Re: isFactoryForType implementation guideline for adapter factories used by AdapterFactoryContentPro [message #1735089 is a reply to message #1734929] |
Wed, 15 June 2016 09:34   |
Eclipse User |
|
|
|
Thilo,
Comments below.
On 14.06.2016 15:57, Thilo Bohr wrote:
> Hi all
>
> I want to register adapter factories that provide adapters from EMF
> objects defined in multiple model packages to jface content and label
> providers.
> Guided by
> http://help.eclipse.org/juno/topic/org.eclipse.emf.doc/references/overview/EMF.Edit.html
> I configure a TreeViewer with an AdapterFactoryContentProvider and an
> AdapterFactoryLabelProvider, which are initialized with a
> ComposedAdapterFactory.
A common idiom is to use
new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)
This way all registered item provide adapter factories will be used as
needed. You can add specialized adapter factories to this composed one
to override registered ones...
>
> I learned that the framework calls the isFactoryForType method for
> each registered AdapterFactory multiple times to decide whether the
> adapter factory can provide a suitable adapter or not.
> The javadoc is not to clear about what is tested there, i.e. to which
> set of type objects the adapter is expected to conform.
It's a rather plastic API.
> For example, there are package objects being supplied as input types
> but it is unclear for me for what reasons.
To find the specific item provider adapter factory for that package.
> Moreover, I learned that if multiple adapter factories conform to a
> specific set of calls to isFactoryForType, just the first adapter
> factory will be used to provide adapters.
Yes, the list is searched sequentially.
>
> What are the rules of how the isFactoryForType is used by the
> framework (specifically the ComposedAdapterFactory and the
> AdapterFactory[Content|Label]Provider setup)?
The most important method is
org.eclipse.emf.edit.provider.ComposedAdapterFactory.getFactoryForTypes(Collection<?>)
for selecting an adapter factory to use. And that's driven from
org.eclipse.emf.edit.provider.ComposedAdapterFactory.adapt(Notifier,
Object, boolean) which needs to create an adapter.
> How are the isFactoryForType methods to be implemented if multiple
> adapter factories for multiple EMF models (packages) are to be
> registered?
You can look at generated implementations and you can use the debugger
to answer very detailed questions. The general idea is that given an
object of some type T (and that type is from some package P) and the
desire to create an adapter of some type X, you need to find a factory
that can create adapters of type X for typed T from P so that's why you
see isFactoryForType being called with X and P (with the later being the
case because a factory is registered on a per-package basis).
> Greetings
> Thilo
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.05645 seconds