|
Re: Why not register an adapterfactory with Platform? [message #495571 is a reply to message #495563] |
Thu, 05 November 2009 11:30 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Christophe,
Comments below.
Christophe Bouhier wrote:
> Hi,
>
> The eclipse adapter framework allows adapter factories to be
> registered, so adaptations of an object can be done on the object
> itself, (Versus dragging around an adapterfactory).
Yes, I always considered that a rather poor design feature because it
only allows a single implementation for the entire application.
>
> In EMF, I find myself doing this a lot: (Editor needs to be in the
> loop all the time).
No, only the adapter factory needs to be known, not any particular editor.
>
> Adapter what = editor.getAdapterFactory().adapt(object,
> IItemPropertySource.class);
Why do you need to do this directly?
>
>
> Would it be possible to register a (composed) adapterfactory like this?
>
> IAdapterManager aManager = Platform.getAdapterManager();
>
>
> ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>
> adapterFactory
> .addAdapterFactory(new
> ResourceItemProviderAdapterFactory());
> adapterFactory
> .addAdapterFactory(new
> MyModelItemProviderAdapterFactory());
> adapterFactory
> .addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
>
>
>
> aManager.registerAdapters(adapterFactory, IMyModelClass1.class);
I'm not sure.
>
>
>
> So with this I could then call:
>
>
> IItemPropertySource src =
> ((IAdaptable)object).getAdapter(IItemPropertySource.class);
But your objects don't implement IAdaptable do they?.
>
>
> object being of type IMyModelClass1
I doubt registering your local factories globally will be a good thing.
I expect they will result in massive leaks.
>
>
> Cheers Christophe
>
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Why not register an adapterfactory with Platform? [message #495573 is a reply to message #495571] |
Thu, 05 November 2009 11:44 |
Christophe Bouhier Messages: 937 Registered: July 2009 |
Senior Member |
|
|
follow-up below:
Ed Merks wrote:
> Christophe,
>
> Comments below.
>
> Christophe Bouhier wrote:
>> Hi,
>>
>> The eclipse adapter framework allows adapter factories to be
>> registered, so adaptations of an object can be done on the object
>> itself, (Versus dragging around an adapterfactory).
> Yes, I always considered that a rather poor design feature because it
> only allows a single implementation for the entire application.
>>
>> In EMF, I find myself doing this a lot: (Editor needs to be in the
>> loop all the time).
> No, only the adapter factory needs to be known, not any particular editor.
>>
Yep, ok but my adapter factories in the EMF editor are actually defined
in the Editor itself. So you mean, I could instantiate them anywhere
else correct?
>> Adapter what = editor.getAdapterFactory().adapt(object,
>> IItemPropertySource.class);
> Why do you need to do this directly?
>>
The reason I am doing this, is because I am customizing my
adapterfactories to be able to filter certain features. So while doing
this, I was thinking, why aren't these registered globally, and why do I
need to carry around a factory, if the Platform has an AdapterManager?
Actually, I would like to contribute these customizations somewhere.
Would you mind reviewing this? (Will send it separately)
>>
>> IItemPropertySource src =
>> ((IAdaptable)object).getAdapter(IItemPropertySource.class);
> But your objects don't implement IAdaptable do they?.
>>
Well my objects are EMF object, I have been under the assumption that
these implement IAdaptable.... So if it's not, I guess the adapter
pattern in EMF is different from the adapter pattern intended for the
Platform? If so, it's fine I will just use a Singleton pattern to get my
customized adapter factory.
>>
>> object being of type IMyModelClass1
> I doubt registering your local factories globally will be a good thing.
> I expect they will result in massive leaks.
>>
>>
>> Cheers Christophe
>>
>>
>>
>>
>>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03723 seconds