Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Problems with restricting property tester by using the type attribute
Problems with restricting property tester by using the type attribute [message #698521] Tue, 19 July 2011 15:33 Go to next message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
I posted this issue in the PDE subforums but I noticed that this one is more active. Sorry if I did something wrong with re-posting it here.


My main problem is that in the Package Explorer projects can be either IProject or IJavaProject objects. I know that programmatically the IProject -> IJavaProject conversion is possible through the IAdaptable interface. But sometimes you just can't use this.

In my case I created my own PropertyTester. Here's how I defined it in my plugin.xml:

<extension 
          point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
         id="my.plugin.MyPropertyTester"
         type="org.eclipse.core.resources.IProject"
         namespace="my.plugin"
         properties="isProject"
         class="my.plugin.MyPropertyTester">
      </propertyTester>
</extension>


The problem here is that the type attribute restricts when the property tester is called. So if a project in the package explorer is an IProject object there's no problem but my property tester is not called when it's an IJavaProject. I could use java.lang.Object instead of org.eclipse.core.resources.IProject but the property tester would run on every object in the UI that way.
I can't find a way to define two different types as restriction for a property tester or any other solution.

Any ideas or do somebody know how to do this properly?

Thank you.

[Updated on: Tue, 19 July 2011 15:35]

Report message to a moderator

Re: Problems with restricting property tester by using the type attribute [message #698589 is a reply to message #698521] Tue, 19 July 2011 18:52 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

When dealing with navigator or explorer elements in core expressions, you usually use:

<adapt type="org.eclipse.core.resources.IProject">
  <test ..../>
</adapt>


that makes sure the IJavaProjects become IProject before you deal with them.

PW


Re: Problems with restricting property tester by using the type attribute [message #699240 is a reply to message #698589] Thu, 21 July 2011 07:25 Go to previous messageGo to next message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Hi Paul!

I've read about the solution you mentioned but it doesn't work in my case.

Here's the situation in details:
I have 4 plug-ins. 3 of them do different tasks and the last one is a menu extension which implements a submenu for the first 3 in the Package Exlporer's context menu. The menu plug-in contains my property tester (whose XML code is in my first post). Properties are tested in the 3 separate plug-ins.

If I modify the definition of the property tester in my menu plug-in like this:
<extension 
          point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
         id="my.plugin.MyPropertyTester"
         type="org.eclipse.core.resources.IProject"
         namespace="my.plugin"
         properties="isProject"
         class="my.plugin.MyPropertyTester">
      </propertyTester>
</extension>
and use the <adapt> tag in the others' plugin.xml like this:
<adapt type="org.eclipse.core.resources.IProject">
   <test
         property="my.plugin.isProject">
   </test>
</adapt>
the adaptation is not performed and my property tester is not called.

Is it a problem that testing against the property and the property's definiton are in different plug-ins? It wouldn't seem too logical to me if I had to define the same property tester in each plug-in.

UPDATE: I put my property tester class, the property tester definiton and the actual testing into the same plug-in but it's still no good. When I use java.lang.Object for the type attribute my tester is called but when I use org.eclipse.core.resources.IProject instead it doesn't work with IJavaProject objects even if I use the adapt element.

UPDATE #2: I also tried with java.lang.Object as type restriction and the adapt element but again the property tester is not called. If I remove the adapt tag it's OK, however this way I return to where I started.

[Updated on: Thu, 21 July 2011 10:01]

Report message to a moderator

Re: Problems with restricting property tester by using the type attribute [message #699335 is a reply to message #699240] Thu, 21 July 2011 11:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Please show a full expression with the <adapt/> element that you used that didn't work.

PW


Re: Problems with restricting property tester by using the type attribute [message #699368 is a reply to message #699335] Thu, 21 July 2011 12:52 Go to previous messageGo to next message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Here's the definition of my handler:

<extension point="org.eclipse.ui.handlers">
   <handler 
        commandId="my.plugin.command"
        class="my.plugin.CommandHandler">
      <enabledWhen>
         <iterate
              ifEmpty="false">
            <and>
               <with
                    variable="selection">
                  <adapt type="org.eclipse.core.resources.IProject">
                     <test
                          property="my.plugin.isProject">
                     </test>
                  </adapt>
               </with>
            </and>
         </iterate>
      </enabledWhen>
   </handler>
</extension>

The definition of the property tester is in my previous post.
Re: Problems with restricting property tester by using the type attribute [message #699478 is a reply to message #699368] Thu, 21 July 2011 15:50 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You want the <with variable="selection"> to be the only element under enabledWhen, and put your iterate under with.

"selection" is something that needs to be iterated over, it won't adapt to anything useful except maybe a java.util.Collection.

PW


Re: Problems with restricting property tester by using the type attribute [message #701501 is a reply to message #698521] Mon, 25 July 2011 07:35 Go to previous message
Tam Gom is currently offline Tam GomFriend
Messages: 36
Registered: July 2011
Member
Thank you, Paul!

Now I understand how this works!
Previous Topic:The program 'Eclipse' received an X Window System error.
Next Topic:Nasty thread death with no breakpoint or exception
Goto Forum:
  


Current Time: Tue Mar 19 10:46:23 GMT 2024

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

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

Back to the top