开发中通常会碰到这种需求,比如一个“新建”菜单,只想要在项目的第一级或者指定文件夹才显示,这时就需要过滤菜单
1. 首先需要添加‘新建’菜单的扩展点
对应的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; }}