Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Why not register an adapterfactory with Platform?
Why not register an adapterfactory with Platform? [message #495563] Thu, 05 November 2009 11:13 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
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).

In EMF, I find myself doing this a lot: (Editor needs to be in the loop
all the time).

Adapter what = editor.getAdapterFactory().adapt(object,
IItemPropertySource.class);


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);



So with this I could then call:


IItemPropertySource src =
((IAdaptable)object).getAdapter(IItemPropertySource.class);


object being of type IMyModelClass1


Cheers Christophe
Re: Why not register an adapterfactory with Platform? [message #495571 is a reply to message #495563] Thu, 05 November 2009 11:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
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
>>
>>
>>
>>
>>
Re: Why not register an adapterfactory with Platform? [message #495578 is a reply to message #495573] Thu, 05 November 2009 11:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[...]

>>>
>>> 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

Thank God they are not else EMF would have a dependency on the platform.

Tom
Re: Why not register an adapterfactory with Platform? [message #495579 is a reply to message #495578] Thu, 05 November 2009 11:59 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Tom Schindl wrote:
> [...]
>
>>>> 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
>
> Thank God they are not else EMF would have a dependency on the platform.
>
> Tom
yep, good point.
Re: Why not register an adapterfactory with Platform? [message #495864 is a reply to message #495579] Fri, 06 November 2009 12:49 Go to previous messageGo to next message
Mario Winterer is currently offline Mario WintererFriend
Messages: 136
Registered: July 2009
Senior Member
Christophe Bouhier schrieb:
> Tom Schindl wrote:
>> [...]
>>
>>>>> 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
>>
>> Thank God they are not else EMF would have a dependency on the platform.
>>
>> Tom
> yep, good point.

If it is absolutely necessary to have all your model objects implement
IAdaptable you could simply change the "Root Extends Class" and "Root
Extends Interface" properties of your generator model.
(Your new root interface must extend EObject as well as IAdaptable; your
new root class should extend your prefered EObject-implementation and
implement your new root interface which results in implementing
IAdaptable.getAdapter(...)).

Mario
Re: Why not register an adapterfactory with Platform? [message #495907 is a reply to message #495864] Fri, 06 November 2009 15:09 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Or bring in the IAdaptable into your .ecore and add it as a superclass
to your classes.

Tom

Mario Winterer schrieb:
> Christophe Bouhier schrieb:
>> Tom Schindl wrote:
>>> [...]
>>>
>>>>>> 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
>>>
>>> Thank God they are not else EMF would have a dependency on the platform.
>>>
>>> Tom
>> yep, good point.
>
> If it is absolutely necessary to have all your model objects implement
> IAdaptable you could simply change the "Root Extends Class" and "Root
> Extends Interface" properties of your generator model.
> (Your new root interface must extend EObject as well as IAdaptable; your
> new root class should extend your prefered EObject-implementation and
> implement your new root interface which results in implementing
> IAdaptable.getAdapter(...)).
>
> Mario
Previous Topic:How to print the tree view for an Ecore model?
Next Topic:merging XML files
Goto Forum:
  


Current Time: Mon Sep 23 11:06:13 GMT 2024

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

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

Back to the top