4.1 概述
Common Filter负责进行节点过滤,类似JFace Viewer中的Sorter功能,比如
org.eclipse.jface.viewers.StructuredViewer.setSorter(ViewerSorter sorter)
CNF中也一样,不过它使用Common Filter对Sorter进行了封装,使得用户更容易自定义过滤器。具体效果见第一节中的部分。
4.2 扩展点
扩展点org.eclipse.ui.navigator.navigatorContent/commonFilter,定义的Common Filter在navigatorContent中通过viewerContentBinding引用。

具体声明为:

该扩展点中最重要的就是filterExtension,它将确定合适启用过滤器。在filterExtension中,可以使用PropertyTest,Instanceof等一切可以用于判断的表达式:

4.3 Eclipse实现
在这里讲解一下Eclipse中Non-JavaProject过滤器的实现。代码如下:
<commonFilter
id="org.eclipse.ui.examples.navigator.filters.hideNonJavaProjects"
name="Hide non-Java Projects">
<filterExpression>
<not>
<adapt
type="org.eclipse.core.resources.IProject">
<test
property="org.eclipse.core.resources.projectNature"
value="org.eclipse.jdt.core.javanature">
</test>
</adapt>
</not>
</filterExpression>
</commonFilter>
这里使用了Property Test,使用“org.eclipse.core.resources.projectNature”属性,这是Eclipse内置的一个属性,如果该属性不是“org.eclipse.jdt.core.javanature”时候,启用过滤器,过滤掉不是Java工程的工程。
4.4 说明
扩展点org.eclipse.ui.navigator.navigatorContent/commonFilter,定义的Common Filter在navigatorContent中通过viewerContentBinding引用。
本文详细介绍了Eclipse中CommonFilter的使用方式及其扩展点。CommonFilter用于节点过滤,类似于JFaceViewer中的Sorter功能,允许用户自定义过滤器。文章还展示了如何实现一个Non-JavaProject过滤器。
764

被折叠的 条评论
为什么被折叠?



