Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Mechanism to provide IAdapterFactory for classes, not instances?
Mechanism to provide IAdapterFactory for classes, not instances? [message #988488] Fri, 30 November 2012 08:23 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
I am using Eclipse's IAdapterFactory - IAdapterManager mechanism to provide some decentral Adapters for custom classes.

Now the IAdapterFactory is usually retrieved by doing.
Platform.getAdapterManager().getAdapter(OBJECT adaptable, class adapterType);


This mechanism is great, but unfortunatly requires an INSTANCE of an adaptable Object, to retrieve a fitting adapter.

Sometimes, e.g. when doing some preparations for displaying Objects - I do not have any instances of adoptable objects yet. i only know the objects class I whant to display.

Question:
Is there such a mechanism in Eclipse, which would allow to register an IAdapterFactory for CLASSES (not instances) ?

So that one could do:
Platform.getAdapterManager().getAdapter(CLASS adaptable, class adapterType);
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988490 is a reply to message #988488] Fri, 30 November 2012 08:44 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
First of all I would suggest to use org.eclipse.e4.core.services.Adapter service instead of retrieving it via Platform singleton. Unless you are planning to create an Eclipse 3.x application.

Second, IMO an adapter is some kind of wrapper to an existing object. So it doesn't make sense to retrieve an adapter for a class, because it couldn't wrap anything. So you would need some other mechanism to retrieve what you are looking for, but it's not the adapter pattern.

[Updated on: Fri, 30 November 2012 08:45]

Report message to a moderator

Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988493 is a reply to message #988490] Fri, 30 November 2012 08:58 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
Thnx Dirk!

It is not an Adapter, which I would like to retrieve from the Platform in this case - it is some kind of class decorator.
(to be precise a Renderer , which will be able to render special classes. This renderer is registered once an forever, )

Unfortunately the only thing I can register to the Platform - is an IAdapter, so I am forced to use this mechanism.

I am aware, that I am missusing the Adapter-mechanism here.

P.S. thnx for the tip with org.eclipse.e4.core.services.Adapter
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988495 is a reply to message #988493] Fri, 30 November 2012 09:11 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
I haven't looked at this in much detail yet, but as you speaking of renderers, maybe you want to have a look at this: http://www.vogella.com/articles/Eclipse4Renderer/article.html

AFAIK you should be able to extend the model and register a renderer for it.

If that doesn't fit your requirements, maybe it would be an option to set your renderer/decorator that is only created once and initially to the context by some special name.
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988500 is a reply to message #988495] Fri, 30 November 2012 09:29 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
BTW. a java.lang.Class is 'just another' java.lang.Object. So, your 'adaptable' can also be a Class (for example YourType.class) which you would check for in your Adapter instance.
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988503 is a reply to message #988495] Fri, 30 November 2012 09:41 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
Maybe i should be more precise here:

I am talking about my own renderer (for a table I am drawing).

The situation:
An Eclipse Plugin will contribute some new classes. Those classes will be rendered by my application. (Inside a table)
The Plugin should register the renderer, for the new classes. Registration is done over the Platform.

The Application knows, that it will render some new class X. There are no instances of this classes yet. (E.g. the table with is empty)
It asks the Platform for a renderer, which is responsible for class X.

My Solution:
A beautiful decentral solution - is to provide renderers through the IAdapterFactory pattern. This totally separates plugin and Application. Allows to contribute renderers from special plugins etc.

Problem:
Unfortunately I can not retrieve any kind of stuff by CLASS. Only by providing an INSTANCE.
The Eclipse4Renderer do not apply here either...
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988504 is a reply to message #988500] Fri, 30 November 2012 09:46 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
Erdal Karaca wrote on Fri, 30 November 2012 04:29
BTW. a java.lang.Class is 'just another' java.lang.Object. So, your 'adaptable' can also be a Class (for example YourType.class) which you would check for in your Adapter instance.


Unfortunately, the Eclipse mechanism , which then retrives the Object by class - does something like object.getClass() to decide for what kind of object we need to search for an adapter.

When providing a MyClass.class it does MyClass.class.getClass(), retrieves a Class<?> object and tries to adopt Class<?> objects - not MyClass.class
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988511 is a reply to message #988500] Fri, 30 November 2012 10:13 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
Erdal Karaca wrote on Fri, 30 November 2012 10:29
BTW. a java.lang.Class is 'just another' java.lang.Object. So, your 'adaptable' can also be a Class (for example YourType.class) which you would check for in your Adapter instance.


Sorry, but for me this sounds like simply missusing a pattern.

Still not sure why it is necessary to get an adapter by class. Why not getting the adapter for an instance, and in the case there is no instance, use a default renderer that is always known. Otherwise rendering of nothing needs to be handled in every implementation.

But maybe I'm still to far away from understanding your requirements. Smile
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988522 is a reply to message #988511] Fri, 30 November 2012 10:59 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
E.g. in NatTable the ICellRenderers can be registered for whole Columns, during the configruation phase, before the table is filled with instances.

There you know which classes will be inside the table, but you do not have any instances yet.
Re: Mechanism to provide IAdapterFactory for classes, not instances? [message #988536 is a reply to message #988522] Fri, 30 November 2012 11:53 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
For this special case IMHO you are going the wrong way and should have a look on how to configure and style NatTable. It is not the correct forum here, but if you want to change the ICellPainter specific to some content (whether this means the type of the object or the value), you should add a specialized label and then connect a special painter for that label.

For further questions on this, please use the NatTable forum to don't bother the E4 guys. Smile
Previous Topic:Is there some animation support in e4?
Next Topic:@Focus in Eclipse 4.3 M3
Goto Forum:
  


Current Time: Mon Nov 24 18:16:54 GMT 2014

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

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