通用导航器中的过滤器不起作用的可能原因是什么?

时间:2019-03-20 13:59:52

标签: eclipse-plugin

我所做的一切都类似于Filtering contents in Eclipse Common Navigator Framework view中@prashanth所说的,但是我的过滤器似乎没有隐藏任何东西,我可以看到所有文件。 我也尝试按照本教程的每个步骤进行操作,并阅读了文档:https://help.eclipse.org/photon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fcnf.htm 我转到过滤器菜单,并确保另一个过滤器正在工作并且我的过滤器已激活。我试图刷新树..
我绝对不知道在哪里看。你有一个我可以探索的想法吗?还是可以看看我的代码并告诉我是否看到错误的内容?

我的plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?><plugin>
  <extension
        point="org.eclipse.ui.commands">
     <category
           description="A plugin for managing the configuration files of the  Software Product Line framework"
           id="SPL.commands.category"
           name="SPL - Software Product Line">
     </category>
     <command
           categoryId="SPL.commands.category"
           defaultHandler="spl.handlers.ListConfigHandler"
           id="SPL.commandListConfig"
           name="lister les configurations">
     </command>
     <command
           categoryId="SPL.commands.category"
           id="SPL.commandCreateConfig"
           name="Créer une configuration">
     </command>
     <command
           id="SPL.JavaFileCommand"
           name="Java File Command">
     </command>
  </extension>
  <extension
        point="org.eclipse.ui.handlers">
     <handler
           class="spl.handlers.JavaFileHandler"
           commandId="SPL.JavaFileHandler">
     </handler>
     <handler
           class="spl.handlers.ListConfigHandler"
           commandId="SPL.ListConfigHandler">
     </handler>
     <handler
           class="spl.handlers.CreateConfigHandler"
           commandId="SPL.commandCreateConfig">
     </handler>
  </extension>
  <extension
        point="org.eclipse.ui.bindings">
     <key
           commandId="SPL.commands.splCommand"
           schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
           contextId="org.eclipse.ui.contexts.window"
           sequence="M1+6">
     </key>
  </extension>
  <extension
        point="org.eclipse.ui.menus">
     <menuContribution
           locationURI="menu:org.eclipse.ui.main.menu?after=help">
        <menu
              id="SPL.menus.sampleMenu"
              label="SPL Menu"
              mnemonic="L">
           <menu
                 label="insérer @Variability">
              <command
                    commandId="SPL.commandListConfig"
                    label="lister les configurations"
                    style="push">
              </command>
              <command
                    commandId="SPL.commandCreateConfig"
                    label="Créer une configuration"
                    style="push">
              </command>
           </menu>
           <menu
                 label="insérer @Bridge"
                 mnemonic="b">
           </menu>
        </menu>
     </menuContribution>
     <menuContribution
           locationURI="popup:org.eclipse.ui.popup.any">
                  <menu
              id="SPL.menus.sampleMenu"
              label="SPL Menu"
              mnemonic="L">
                  <menu
                 label="insérer @Variability">
              <command
                    commandId="SPL.commandListConfig"
                    label="lister les configurations"
                    style="push">
              </command>
              <command
                    commandId="SPL.commandCreateConfig"
                    label="Créer une configuration"
                    style="push">
              </command>
           </menu>
           <menu
                 label="insérer @Bridge"
                 mnemonic="b">
           </menu>
           </menu>
     </menuContribution>
  </extension>
  <extension
        id="SPLPerspective"
        name="SPL Perspective"
        point="org.eclipse.ui.perspectiveExtensions">
     <perspectiveExtension
           targetID="SPL.perspective4">
     </perspectiveExtension>
  </extension>
  <extension
        point="org.eclipse.ui.views">
     <category
           id="SPL"
           name="SPL">
     </category>
     <view
           category="SPL"
           class="spl.views.VariabilityExplorer"
           id="SPL.VariabilityExplorer"
           name="Point of Variability Explorer"
           restorable="true">
     </view>
     <view
           category="SPL"
           class="spl.views.configurationFileExplorer"
           id="spl-development-plugins.configurationFileExplorer"
           name="Configuration File Explorer"

           restorable="true">
     </view>
     <view
           category="SPL"
           class="org.eclipse.ui.navigator.CommonNavigator"
           id="spl-development-plugins.VariabilityNavigator"
           name="VariabilityNavigator"
           restorable="true">
     </view>
  </extension>
  <extension
        point="org.eclipse.help.contexts">
     <contexts
           file="contexts.xml">
     </contexts>
  </extension>
  <extension
        point="org.eclipse.ui.perspectives">
     <perspective
           class="spl.perspectives.PerspectiveFactory4"
           id="SPL.perspective4"
           name="SPL">
     </perspective>
  </extension>
  <extension
        point="org.eclipse.ui.editors">
     <editor
           class="spl.editors.PropertiesEditor"
           default="true"
           extensions=".properties"
           id="spl-development-plugins.splEditorProperties"
           name="SPL Properties Editor">
     </editor>
  </extension>
  <extension
        point="org.eclipse.ui.navigator.viewer">
     <viewerContentBinding
           viewerId="spl-development-plugins.VariabilityNavigator">
        <includes>
           <contentExtension
                 pattern="org.eclipse.ui.navigator.resourceContent">
           </contentExtension>
           <contentExtension
                 pattern="org.eclipse.ui.navigator.resources.*">
           </contentExtension>
           <contentExtension
                 pattern="org.eclipse.ui.navigator.resources.filters.*">
           </contentExtension>
           <contentExtension
                 pattern="spl-development-plugins.VariabilityContent">
           </contentExtension>
        </includes>
     </viewerContentBinding>
     <viewerActionBinding
           viewerId="spl-development-plugins.VariabilityNavigator">
        <includes>
           <actionExtension
                 pattern="org.eclipse.ui.navigator.resources.*">
           </actionExtension>
        </includes>
     </viewerActionBinding>
  </extension>
  <extension
        point="org.eclipse.ui.navigator.navigatorContent">
     <navigatorContent
           id="spl-development-plugins.VariabilityContent"
           name="Variability File Contents"
           contentProvider="VariabilityContentProvider"
           labelProvider="VariabilityLabelProvider"
           activeByDefault="true"
           icon="icons/sample.png"
           priority="normal">
        <triggerPoints>
           <or>
              <and>
                 <instanceof
                       value="org.eclipse.core.resources.IResource">
                 </instanceof>
                 <test
                       forcePluginActivation="true"
                       property="org.eclipse.core.resources.extension"
                       value="java">
                 </test>
              </and>
              <instanceof
                    value="spl.navigator.VariabilitiesTreeData">
              </instanceof>
           </or>
        </triggerPoints>
        <possibleChildren>
           <or>
              <instanceof
                    value="spl.navigator.VariabilitiesTreeData">
              </instanceof>
           </or>
        </possibleChildren>
     </navigatorContent>
     <commonFilter
           activeByDefault="true"
           class="spl.filter.VariabilityFilter"
           description="hide all files that are not java and whom doesn&apos;t includes @Variability"
           id="spl-development-plugins.commonFilterVariability"
           name="Variability files">
     </commonFilter>
  </extension>

我的过滤器:我知道代码与类名不匹配,仅用于测试目的。我从https://github.com/maxeler/eclipse/blob/master/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/filters/JavaFileFilter.java处获得了代码,BTW提供了我尝试过的其他过滤器,结果相同:

public class VariabilityFilter extends ViewerFilter {

    public VariabilityFilter() {
    }

    /* 
     * Filters out all compilation units and class files elements.
     */
    @Override
    public boolean select(Viewer viewer, Object parent, Object element) {
        if (element instanceof ITypeRoot)
            return false;

        if (element instanceof IPackageFragment)
            try {
                return ((IPackageFragment)element).getNonJavaResources().length > 0;
            } catch (JavaModelException ex) {
                return true;
            }
        return true;
    }
}

注意:VariabilityNavigator是一个扩展CommonNavigator的空类,而VariabilitiesTreeData是一个空类。

0 个答案:

没有答案