Adding a filter to the Project Explorer in Eclipse

主宰稳场 提交于 2019-12-03 00:32:23

There you go:

<extension point="org.eclipse.ui.navigator.navigatorContent">
    <commonFilter
        description="Hides *.pj resources"
        id="com.xyz.commonFilter.hidePj"
        name="*.pj resources"
        activeByDefault="true">
        <filterExpression>
            <and>
                <adapt type="org.eclipse.core.resources.IResource">
                    <test property="org.eclipse.core.resources.name" value="*.pj"/>
                </adapt>
            </and>
        </filterExpression>
    </commonFilter>
</extension>
<extension point="org.eclipse.ui.navigator.viewer">
    <viewerContentBinding
          viewerId="org.eclipse.ui.navigator.ProjectExplorer">
          <includes>
            <contentExtension pattern="com.xyz.commonFilter.hidePj"/> 
          </includes>
    </viewerContentBinding>
</extension>

Don't forget to import org.eclipse.ui.navigator package

I found the right set of extension points. It is more of a pain that I expected, because the Project Explorer is a specialization of the common navigator.

This is a two-step process:

  • extend org.eclipse.ui.navigator.navigatorContent

    • Add a common filter to this extension point.
    • Set a name and id to the filter
    • Implement the filter viewer with the desired logic
  • extend org.eclipse.ui.navigator.viewer

    • Add a viewerContentBinding
    • Set the content id to org.eclipse.ui.navigator.ProjectExplorer
    • Add two includes
    • In the first include add a patter that matches the id of the common filter
    • In the second include add the id org.eclipse.ui.navigator.resourceContent

And then, the filter is associated to the common Project Explorer

Filters... for the Project Explorer view?

There are some long standing bugs on that:

That may requiere some specific development (as suggested in this thread)

you could probably accomplish this by creating a class that extends ViewFilter and associating your class with the project explorer.

(Note: FilterViewer were broken in Eclipse3.3.1, some using 3.3.2 here is a good idea)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!