如何过滤菜单

    开发中通常会碰到这种需求,比如一个“新建”菜单,只想要在项目的第一级或者指定文件夹才显示,这时就需要过滤菜单

    1. 首先需要添加‘新建’菜单的扩展点

    

<plugin>
   <extension
         point="org.eclipse.ui.newWizards">
     <category
           id="abide.web"
           name="%category.name">
     </category>
      <wizard
            category="abide.web"
            class="cn.com.test.HtmlWizard"
             
            icon="icons/icon/html.png"
            id="cn.com.test.HtmlWizard"
            name="新建">
      </wizard>
</extension>
<extension
         point="org.eclipse.ui.navigator.navigatorContent">
        
      <commonWizard
            menuGroupId="group.1.new"
            type="new"
            wizardId="cn.com.test.HtmlWizard">
         <enablement>
            <instanceof
                  value="org.eclipse.core.resources.IResource">
            </instanceof>
            <test
                  property="cn.com.test.ide.navigator.htmlFolder"
                  value="html">
            </test></enablement>
      </commonWizard>
 <extension
         point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
            class="cn.com.test.ide.navigator.propertyTester.ResourceTester"
            id="cn.com.test.ide.navigator.propertyTester"
            namespace="cn.com.agree.ide.navigator"
            properties="htmlFolder,cssFolder" 
            type="org.eclipse.core.resources.IContainer">
      </propertyTester>
</plugin>

对应的test类实现

public class ResourceTester extends PropertyTester {

    public ResourceTester() {
        
    }

    @Override
    public boolean test(Object receiver, String property, Object[] args,
            Object expectedValue) {
         if (property.equals("htmlFolder")) {
            if("html".equals(expectedValue)){
                if (WorkspaceUtil.isProject(receiver)) {
                    boolean mainFolder = WorkspaceUtil.isMainFolder(receiver);
                    boolean htmlFolder = WorkspaceUtil.isHtmlFolder(receiver); 
                    return mainFolder && htmlFolder;
                }
                
                
            } 
        return false;
    }

}
ResourceTester .java