Search code examples
javaeclipseeclipse-plugineclipse-rcp

Eclipse Plugin: Show context function on all class-Files in external JARs


I am developing an Eclipse plugin and I want to add an entry in the context menu in the Project Explorer. The entry should only be visible when a class-File is selected.

Adding the following to my plugin.xml File works. However, it does not work when I select a class-File in an External JAR. What is the reason for this behavior and how can I achieve that my context menu is visible in this case too?

      <menuContribution
            allPopups="false"
            locationURI="popup:org.eclipse.ui.popup.any">
         <command
               commandId="my_command"
               label="Test"
               style="push">
               <visibleWhen>                           
                    <iterate
                         ifEmpty="false">
                     <adapt type="org.eclipse.core.resources.IFile">
                       <test property="org.eclipse.core.resources.name" value="*class" />
                     </adapt>
                    </iterate>
                </visibleWhen>
         </command>
      </menuContribution>

Context menu entry "Test" is shown Context menu entry "Test" is NOT shown


Solution

  • Thanks to user greg-449 and howlger I solved my problem. The problem was that an object in a JAR file is not represented as an IFile. Therefore, I adapted the visibleWhen section:

    <visibleWhen>                          
        <iterate ifEmpty="false">
              <instanceof value="org.eclipse.jdt.core.IOrdinaryClassFile" />
        </ iterate>
    </visibleWhen>