Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to test whether the active editor part is adaptable to something
How to test whether the active editor part is adaptable to something [message #758855] Thu, 24 November 2011 18:19 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

is it possible to test whether the active editor part is adaptable to something using the core expressions? I need it in menu contribution's <visibleWhen> clause.
Re: How to test whether the active editor part is adaptable to something [message #758863 is a reply to message #758855] Thu, 24 November 2011 19:52 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

I think that the solution is to use a PropertyTester that asks the AdapterManager for the adapter.
See http://wiki.eclipse.org/FAQ_How_do_I_use_IAdaptable_and_IAdapterFactory%3F.



Time is what you make of it.
Re: How to test whether the active editor part is adaptable to something [message #758867 is a reply to message #758855] Thu, 24 November 2011 20:32 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You can use the adapt element with instanceof directly in the core expression. See the Extension Point Description for the full list of elements.

PW


Re: How to test whether the active editor part is adaptable to something [message #758917 is a reply to message #758867] Fri, 25 November 2011 09:19 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I have read the Extension Point Description but still I'm not able to achieve this. What is the exact use of those two elements? I have tried:
<visibleWhen checkEnabled="false">
   <with variable="activeEditor">
       <adapt type="cz.example.MyObjectINeedAdaptTo">
           <instanceof value="cz.example.MyObjectINeedAdaptTo">
           </instanceof>
       </adapt>
   </with>
</visibleWhen>

But it doesn't work.

I my editorpart I have
@Override
public Object getAdapter(Class adapter) {
    if (adapter == MyObjectINeedAdaptTo.class) {
        return new MyObjectINeedAdaptTo();
    }
    return super.getAdapter(adapter);
}

But the code inside if statement isn't called at all.

[Updated on: Fri, 25 November 2011 09:51]

Report message to a moderator

Re: How to test whether the active editor part is adaptable to something [message #758921 is a reply to message #758917] Fri, 25 November 2011 10:06 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I got it. It isn't even necessary to use instanceof expression. The final visibleWhen element I was looking for is
<visibleWhen checkEnabled="false">
   <with variable="activeEditor">
       <adapt type="cz.example.MyObjectINeedAdaptTo">
       </adapt>
   </with>
</visibleWhen>


The reason why it wasn't working before is that evaluating obviously doesn't call getAdapter(Class adapter) on IAdaptable objects.
You must register your own IAdapterFactory and then provide an adapter to whatever you want. Why is that, I have no idea.
Re: How to test whether the active editor part is adaptable to something [message #759041 is a reply to message #758921] Fri, 25 November 2011 18:58 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Behnil wrote on Fri, 25 November 2011 05:06

The reason why it wasn't working before is that evaluating obviously doesn't call getAdapter(Class adapter) on IAdaptable objects.
You must register your own IAdapterFactory and then provide an adapter to whatever you want. Why is that, I have no idea.


The core.expression code can't call getAdapter(Class) as it can't load the class, in your example, cz.example.MyObjectINeedAdaptTo. If IAdaptable had been written to take a String (like IAdapterManager) then it could have worked.

PW


Previous Topic:project names are not visible in "Project Explorer" window
Next Topic:problem with ant builder helios
Goto Forum:
  


Current Time: Sun Nov 23 19:13:10 GMT 2014

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

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