开发者

PropertyTester: How to determine Project Type on right click?

开发者 https://www.devze.com 2023-03-27 19:42 出处:网络
I am able to check for a Project Type I want for e.g by using <instanceof value=\"org.eclipse.core.resources.IProject\"/>

I am able to check for a Project Type I want for e.g by using

<instanceof value="org.eclipse.core.resources.IProject"/>
<test property="org.eclipse.core.resources.projectNature" 
      value="org.eclipse.wst.jsdt.core.jsNature"/> 

in my for a pop-up menu command and then display my menu entry accordingly. However, there are some complex conditions to be checked, I was therefore asked to use a Property Tester. Below is the plugin.xml extract:

<with variable="selection">
  <test forcePluginActivation="true"
        property="testWizard.propertyTester.checkFolder"/>  

<extension
        point="org.eclipse.core.expressions.propertyTesters">
     <propertyTester
           class="testwizard.wizards.MyPropTester"
           id="MyPropTester"
           namespace="testWizard.propertyTester"
           properties="checkFolder"
           type="org.eclipse.core.resources.IProject">
     </propertyTester>
  </extension>

... and the PropertyTester java code:

package testwizard.wizards;

import org.eclipse.core.internal.propertytester.ResourcePropertyTester;
import org.eclipse.core.resources.IResource;

@SuppressWarnings("restriction")
public class MyPropTester extends ResourcePropertyTester {

    @Override
    public boolean test(Object receiver, String property, Object[] args,
            Object expectedValue) {

        IResource res = (IResource) receiver;

        if(res instanceof IProject)
        {
            return true;
        }
        return false;
    }
开发者_Python百科
}

I am pretty new to using Property Testers,I'd really appreciate it If someone could guide me where my mistakes are.


Found the solution: You need to define a property Tester as given before and use

<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.wst.jsdt.core.jsNature"/>, here the value acts as the expected value in the test Method of the Property Tester class, then use

IProject project=(IProject)receiver;
 if(project.hasNature(expectedValue.toString())) return true;
0

精彩评论

暂无评论...
验证码 换一张
取 消