隐藏RCP项目中Project Explorer中以点开头的文件夹

时间:2018-03-27 22:45:47

标签: java eclipse eclipse-rcp

在我的RCP项目中,我想以编程方式隐藏 Project Explorer 中以点开头的文件夹(当用户浏览打开文件时)。

我使用了以下扩展来实现这一目标,但遗憾的是它没有用。有人可以帮忙吗?谢谢。

<extension point="org.eclipse.ui.navigator.navigatorContent">
    <commonFilter
        description="Hides .* resources"
        id="com.xyz.commonFilter.hidePj"
        name=".* resources"
        activeByDefault="true">
        <filterExpression>
            <and>
                <adapt type="org.eclipse.core.resources.IResource">
                    <test property="org.eclipse.core.resources.name" value=".*"/>
                </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>

注意:我正在使用eclipse Ganymede。

1 个答案:

答案 0 :(得分:2)

更改通用IResource类型:

<adapt type="org.eclipse.core.resources.IResource">

并使用最具体的IFolder类型:

<adapt type="org.eclipse.core.resources.IFolder">

相关的源代码如下,使用向导(Ganymede)创建的标准Eclipse插件项目,我刚刚更改了id name属性:

plugin.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

  <extension point="org.eclipse.ui.navigator.navigatorContent">
    <commonFilter
        id="com.stackoverflow.commonFilter.hideFolders"
        name=".* folders"
        description="Hides .* folders"
        activeByDefault="true">
      <filterExpression>
        <and>
            <adapt type="org.eclipse.core.resources.IFolder">
              <test property="org.eclipse.core.resources.name" value=".*"/>
            </adapt>
        </and>
      </filterExpression>
    </commonFilter>
  </extension>

  <extension point="org.eclipse.ui.navigator.viewer">
    <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
      <includes>
        <contentExtension pattern="com.stackoverflow.commonFilter.hideFolders" /> 
      </includes>
    </viewerContentBinding>
  </extension>

</plugin>

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Filter_dot Plug-in
Bundle-SymbolicName: filter_dot;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.ui.navigator,org.eclipse.core.resources

build.properties:

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.xml

在下面的图像中,&#34; Project Explorer&#34;显示&#34; .test&#34;文件夹,如果启用了过滤器,请使用右上角的&#34;箭头&gt;自定义视图...&#34;选项,然后隐藏文件夹。

Eclipse plugin