Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » <adapt>-Problem
<adapt>-Problem [message #325095] Fri, 08 February 2008 09:07 Go to next message
Eclipse UserFriend
Hi all,

I have a problem with <adapt>. <adapt> checks the object to be adapted
per Expressions.isInstanceOf(). If that fails, it asks the
Platform.getAdapterManager() via hasAdapter().

Here is my problem. The object itself implements IAdaptable and returns
the desired adapter for the requested adapter type.

Is there any solution?

Thanks in advance.


Marco
Re: <adapt>-Problem [message #325096 is a reply to message #325095] Fri, 08 February 2008 09:43 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, should have checked before:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=184046

CU,

Marco

Marco Lehmann schrieb:
> Hi all,
>
> I have a problem with <adapt>. <adapt> checks the object to be adapted
> per Expressions.isInstanceOf(). If that fails, it asks the
> Platform.getAdapterManager() via hasAdapter().
>
> Here is my problem. The object itself implements IAdaptable and returns
> the desired adapter for the requested adapter type.
>
> Is there any solution?
>
> Thanks in advance.
>
>
> Marco
Re: <adapt>-Problem [message #325105 is a reply to message #325096] Fri, 08 February 2008 15:07 Go to previous messageGo to next message
Eclipse UserFriend
Core Expressions cannot see that workbench Util code. What's more, core
expressions cannot load Class, the class you want to adapt to. All it
has is a String. That's why you see Expressions.isInstanceOf(*) instead
of the just the instanceof operator ... you have the String name for a
class that core.expressions can't load.

I think one potential workaround might be:
if (var instanceof IAdaptable) {
try {
Class c = var.getClass().getClassLoader()
.loadClass(fTypeName);
adapted = ((IAdaptable)var).getAdapter(c);
} catch (ClassNotFoundException e) { }
}

However, there are problems with this approach. The adapt element
returns NOT_LOADED if the adapter factory is not loaded. It should also
return NOT_LOADED if the Class c cannot be loaded instead of starting a
bundle just to load the class.

The code to try and guess if a particular String className can be loaded
without activating a bundle can be quite complex, I think, although I've
never attempted it.

Rather than generalize, perhaps adapt could add a forcePluginLoading
attribute like the test element, and only use the IAdaptable if the
attribute is set to true and the context allows plugin activations
(handlers, context, and menu contributions all have contexts that allow
plugin activation).

Later,
PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Re: <adapt>-Problem [message #333031 is a reply to message #325105] Thu, 20 November 2008 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: apicard.tampabay.rr.com

Has any progress been made here? I am having the same issue.

But, at the same time I did create a Manager/Factory to handle my
adapter, but the current manager implementation seems to assume that the
adapter class must be a direct match with the list of classes returned
by the getAdapterList of the factory.

How should one proceed when the list should include anything that
isAssignableFrom the adapter class. I wouldn't know where to start to
even generate such as list in the first place as this can get rather
complicated.

So, we either need to be able to use the getAdapter in the adaptable
class and have <adapt> fully respect the interface contract, or we need
to see how to broaden the vision of the manager.

Ideas??

Alain


Paul Webster wrote:
> Core Expressions cannot see that workbench Util code. What's more, core
> expressions cannot load Class, the class you want to adapt to. All it
> has is a String. That's why you see Expressions.isInstanceOf(*) instead
> of the just the instanceof operator ... you have the String name for a
> class that core.expressions can't load.
>
> I think one potential workaround might be:
> if (var instanceof IAdaptable) {
> try {
> Class c = var.getClass().getClassLoader()
> .loadClass(fTypeName);
> adapted = ((IAdaptable)var).getAdapter(c);
> } catch (ClassNotFoundException e) { }
> }
>
> However, there are problems with this approach. The adapt element
> returns NOT_LOADED if the adapter factory is not loaded. It should also
> return NOT_LOADED if the Class c cannot be loaded instead of starting a
> bundle just to load the class.
>
> The code to try and guess if a particular String className can be loaded
> without activating a bundle can be quite complex, I think, although I've
> never attempted it.
>
> Rather than generalize, perhaps adapt could add a forcePluginLoading
> attribute like the test element, and only use the IAdaptable if the
> attribute is set to true and the context allows plugin activations
> (handlers, context, and menu contributions all have contexts that allow
> plugin activation).
>
> Later,
> PW
>
>
Re: <adapt>-Problem [message #333068 is a reply to message #333031] Mon, 24 November 2008 13:25 Go to previous message
Eclipse UserFriend
Alain Picard wrote:
> Has any progress been made here? I am having the same issue.
>
> But, at the same time I did create a Manager/Factory to handle my
> adapter, but the current manager implementation seems to assume that the
> adapter class must be a direct match with the list of classes returned
> by the getAdapterList of the factory.
>
> How should one proceed when the list should include anything that
> isAssignableFrom the adapter class. I wouldn't know where to start to
> even generate such as list in the first place as this can get rather
> complicated.
>
> So, we either need to be able to use the getAdapter in the adaptable
> class and have <adapt> fully respect the interface contract, or we need
> to see how to broaden the vision of the manager.
>

No one is looking at this at all, AFAIK. You can open enhancement
requests at https://bugs.eclipse.org/bugs/

Later,
PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Previous Topic:Contributing org.eclipse.ui.menus to actionSets
Next Topic:Cannot find the button to reset or forget the dialog settings
Goto Forum:
  


Current Time: Fri Feb 14 18:44:04 GMT 2025

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

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

Back to the top