有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

基于资源类型启用java RCP处理程序

我基于Eclipse3RCP为eclipse编写了一个插件。我插入了编辑器的上下文菜单,希望只有在资源类型正确的情况下才启用特定的菜单项

文件的类型为->

com.test.test.resources.test.testphysical.TESTSequentialDataSet 

这是->

com.test.test.resources.test.testphysical.TESTResource

现在我试着:

<handler  
       class="com.test.test.handler.TESTHandler"
       commandId="com.test.test.commands.COBQS">      
     <enabledWhen>
         <with variable="activeEditorInput">
            <iterate>
               <instanceof
                     value="com.test.test.resources.test.testphysical.TESTSequentialDataSet">
               </instanceof>
            </iterate>
         </with>
    </enabledWhen>
</handler>

但这对我不起作用,你知道怎么做吗


共 (1) 个答案

  1. # 1 楼答案

    activeEditorInput不是列表,因此不能使用iterate

    编辑器输入将是一个实现IEditorInput而不是对象的类

    使用类似于:

    <with variable="activeEditorInput">
        <adapt type="org.eclipse.core.resources.IFile">
             <test property="org.eclipse.core.resources.contentTypeId" value="org.eclipse.jdt.core.javaSource" />
        </adapt>
    </with>
    

    adapt元素使用适配器管理器从编辑器输入获取文件

    测试使用文件的“内容类型id”——我在这里使用了Java源文件id,您必须为您的文件类型定义一个内容类型id