Bug 201743 - [Contributions] Core Expressions: adapt element should optionally use .getAdapter(..)
Summary: [Contributions] Core Expressions: adapt element should optionally use .getAda...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement with 2 votes (vote)
Target Milestone: 4.3 M4   Edit
Assignee: Paul Webster CLA
QA Contact: Paul Webster CLA
URL:
Whiteboard:
Keywords: helpwanted
: 184046 208336 366573 (view as bug list)
Depends on:
Blocks: 219207
  Show dependency tree
 
Reported: 2007-08-30 10:23 EDT by Tonny Madsen CLA
Modified: 2012-11-07 14:26 EST (History)
10 users (show)

See Also:


Attachments
Patch with proposed fix. (1.90 KB, patch)
2008-04-29 00:49 EDT, Pawel Piech CLA
no flags Details | Diff
Unit test for the feature. (3.38 KB, patch)
2008-04-29 00:50 EDT, Pawel Piech CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tonny Madsen CLA 2007-08-30 10:23:24 EDT
Version: 3.3.0
Build id: I20070621-1340

The adapt element of the expression mechanism only adapts using the AdapterManager. This is first of all not documented for the adapt element, but it would be better to allow the adaption to optionally be handled via the IAdaptable interface.

The choice can be specified in a new attribute of the adapt element as in the following example. (The attribute name is not good :-/))

   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="....MailContactHandler"
            commandId="....newmailforcontact">
         <enabledWhen>
            <with
                  variable="selection">
               <iterate
                     ifEmpty="false"
                     operator="or">
                  <adapt
                        type="....data.IContact">
                        useGetAdapter="true">                                       <<<<<<<<<<<<<<================
                     <test
                           forcePluginActivation="true"
                           property="....datamodel.hasMail">
                     </test>
                  </adapt>
               </iterate>
            </with>
         </enabledWhen>
      </handler>
   </extension>

Alternatively, the adaption element of in org.eclipse.core.expressions/schema/expressionLanguage.exsd should be properly documented:

This element is used to adapt the object in focus to the type specified by the attribute type. The expression returns not loaded if either the adapter or the type referenced isn't loaded yet. It throws a ExpressionException during evaluation if the type name doesn't exist at all. The children of an adapt expression are combined using the and operator.

Note that the adaption is solely handled via the AdapterManager and not via the IAdaptable interface. This means all relevant adaption must be declared via the  org.eclipse.core.runtime.adapters extension point
Comment 1 Paul Webster CLA 2007-08-30 10:39:30 EDT
I suspect this has to do with the fact that org.eclipse.core.expressions cannot load the adapt-to type, and so cannot use the IAdapatable interface.

We'll have to document this in the extension point description.

PW
Comment 2 Tonny Madsen CLA 2007-08-30 13:20:45 EDT
Paul,

Do you have any description as to why this is the case. I cannot see why it should be a problem, as you can ask for the adapt-to class in the context of the bundle with the plugin.xml. I'll see if I can make the change and get it to work :-) -- unless of cause you have a description to the contrary.

Comment 3 Paul Webster CLA 2007-08-30 13:42:37 EDT
(In reply to comment #2)
> Paul,
> 
> Do you have any description as to why this is the case. I cannot see why it
> should be a problem, as you can ask for the adapt-to class in the context of
> the bundle with the plugin.xml. I'll see if I can make the change and get it to
> work :-) -- unless of cause you have a description to the contrary.
> 

The expression itself provides a string for core.expressions to work with.  Even going to the core.expressions bundle won't allow it to load, say org.eclipse.core.resources.IResources so that it can be supplied to IAdaptable#getAdapter(Class).

There might be some hack around that but I'm not sure whether it would be acceptable.  You could try asking the classloader that loaded the receiver class ...

PW
Comment 4 Pawel Piech CLA 2008-04-29 00:49:42 EDT
Created attachment 97898 [details]
Patch with proposed fix.
Comment 5 Pawel Piech CLA 2008-04-29 00:50:44 EDT
Created attachment 97899 [details]
Unit test for the feature.
Comment 6 Pawel Piech CLA 2008-04-29 01:04:32 EDT
It may not be a perfect solution, but I think this patch would address the most common use case, where the adaptee creates an instance of the adapter directly and returns it from IAdaptable.getAdapter().

BTW, bug 184046 and bug 208336 appear to be duplicates of this request.
Comment 7 Paul Webster CLA 2008-04-29 10:28:25 EDT
*** Bug 184046 has been marked as a duplicate of this bug. ***
Comment 8 Paul Webster CLA 2008-04-29 10:28:33 EDT
*** Bug 208336 has been marked as a duplicate of this bug. ***
Comment 9 Tonny Madsen CLA 2008-04-30 04:40:44 EDT
It looks to me like the fix will do the trick.

But... why doesn't the AdapterManager do this by default? Doesn't it really belong there?
Comment 10 Paul Webster CLA 2008-04-30 08:35:50 EDT
(In reply to comment #9)
> It looks to me like the fix will do the trick.
> 
> But... why doesn't the AdapterManager do this by default? Doesn't it really
> belong there?

Because IAdapterManager was designed to back IAdaptables to allow the types they support to be extended declaratively or programmatically.

javadoc:
 * ... All adaptable objects (that is, objects that implement the <code>IAdaptable</code>
 * interface) funnel <code>IAdaptable.getAdapter</code> invocations to their
 * adapter manager's <code>IAdapterManger.getAdapter</code> method...

PW
Comment 11 Paul Webster CLA 2009-03-02 11:41:23 EST
Updated as per http://wiki.eclipse.org/Platform_UI/Bug_Triage
PW
Comment 12 Paul Webster CLA 2011-12-13 12:48:49 EST
*** Bug 366573 has been marked as a duplicate of this bug. ***
Comment 13 Paul Webster CLA 2011-12-13 12:50:10 EST
Pawel, are you still interested in this?

PW
Comment 14 Pawel Piech CLA 2011-12-13 17:18:16 EST
(In reply to comment #13)
> Pawel, are you still interested in this?
> 
> PW

I don't have any open bugs that depend on this, so I think we found workarounds as needed.  But it would be a nice feature to have.
Comment 15 Eric Moffatt CLA 2012-02-09 14:30:35 EST
Paul, can we take this one off of the 4.2 list and triage it for a look in 4.3 ?
Comment 16 Paul Webster CLA 2012-02-09 14:38:21 EST
(In reply to comment #15)
> Paul, can we take this one off of the 4.2 list and triage it for a look in 4.3
> ?

Yes, I think we'll have to move this off again, sorry about that.

PW
Comment 18 Pawel Piech CLA 2012-11-07 14:26:29 EST
Thank You :-)