Milinda Bandara
Milinda Bandara

Reputation: 552

Enable context menu item for Java files

My Eclipse plugin defines menu items which are not enabled for the Java file selections but are enabled for other file formats. (.xml, .txt)

    <plugin>

   <extension
         point="org.eclipse.ui.popupMenus">
      <objectContribution
            objectClass="org.eclipse.core.resources.IResource"
             nameFilter="*"            
            id="test1.contribution1">

         <menu
               label="MY Plugin"
               path="additions"
               id="test1.menu1">
            <separator
                  name="group1">
            </separator>
         </menu>

         <action
               label="Plugin Launcher"
               class="plugin.model.ExecutePlugin"
               menubarPath="test1.menu1/group1"
               enablesFor="*"
               id="test1.newAction">
         </action>

      </objectContribution>
   </extension>

</plugin>

I want to enable my menu items for the .java files.

Upvotes: 2

Views: 311

Answers (1)

greg-449
greg-449

Reputation: 111142

You probably need to specify the adaptable option:

 <objectContribution
        objectClass="org.eclipse.core.resources.IResource"
        adaptable="true"
        ... >

Note: The org.eclipse.ui.popupMenus extension point is now deprecated, you should move away from using it.

Edit:

Specifying true for adaptable means that the system will use the IAdapterManager interface to check if the object adapts to the objectClass instead of requiring that the object implements the objectClass directly. This allows the view to use a different class for the actual view objects. The view code uses an IAdapterFactory to tell the adapter manager how to get the required class from the view object class.

Upvotes: 3

Related Questions