1

I am using menuContribution + command along with the <visibleWhen> element in my plugin.xml.

Say there is a particular folder "XYZ" in my Project Structure with subfolders "xyz1" "xyz2".
I want my popup menu entry to be only visible on right click of XYZ, xyz1 and xyz2 folders only.

Any inputs to do the same will be really helpful.

Thanks, Abbas

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Abbas
  • 3,144
  • 2
  • 25
  • 45

2 Answers2

2

You should be able to define your own PropertyTester, or to use a predefined one, like the ResourcePropertyTester, which gets the path of the resource as parameter.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2
<test   forcePluginActivation="true"
        property="testWizard.propertyTester.checkFolder"
         value="org.eclipse.wst.jsdt.core.jsNature"
 </test>  is the reference to the property tester , which can be defined as

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

then the kind of folder and it's subfolders can be tested as below in

package testwizard.wizards;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;

public class MyPropTester extends PropertyTester{

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

        IFolder folder=(IFolder)receiver;
        String folderPath=folder.getProjectRelativePath().toString();
        String arr[]=folderPath.split("/");     
        try {
            if(folder.getProject().hasNature(expectedValue.toString()))
            {
                if(arr[0].equals("XYZ"))
                {
                    return true;
                }
            }
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return false;
    }

}
Abbas
  • 3,144
  • 2
  • 25
  • 45