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

时间:2014-06-03 06:34:20

标签: java eclipse

我基于Eclipse 3 RCP为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 个答案:

答案 0 :(得分:0)

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元素使用适配器管理器从编辑器输入中获取文件。

测试使用文件的'content type id' - 我在这里使用了Java源文件id,你必须为你的文件类型定义一个内容类型id。