Zack Macomber
Zack Macomber

Reputation: 6905

Trying to put new "Generate" option under Source menu in Eclipse

I'm trying to add a new "Generate..." option under the Source menu when you right-click on a Java file. At this point, I'm just trying to get the menu option to show up but I haven't had success yet.

Is there something wrong with my plugin.xml file below as far as you can see?

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
    <extension point="org.eclipse.ui.popupMenus">
        <objectContribution
            id="GenerateBuilderPlugin.contribution1"
            objectClass="org.eclipse.core.resources.IFile">
         <action
               class="generatebuilderplugin.popup.actions.GenerateBuilder"
               enablesFor="1"
               id="GenerateBuilderPlugin.newAction"
               label="Generate Builder..."
               menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup">
         </action>
      </objectContribution>
   </extension>
</plugin>

Upvotes: 0

Views: 474

Answers (1)

Zack Macomber
Zack Macomber

Reputation: 6905

I ended up going with the "Hello, World Command" template and adjusting for my needs.

Below is the updated plugin.xml that successfully displays the a new "Generate..." option on the Source menu. One just basically needs to setup a command and a handler class that does the actual work. I'd recommend just following the "Hello, World Command" plugin template and tweaking for your needs.

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
    <extension point="org.eclipse.ui.commands">
        <command
             name="Generate Builder..."
             id="GenerateBuilderProject.commands.GenerateBuilder">
        </command>
    </extension>
   <extension point="org.eclipse.ui.handlers">
      <handler
            commandId="GenerateBuilderProject.commands.GenerateBuilder"
            class="generatebuilderproject.handlers.GenerateBuilderHandler">
      </handler>
   </extension>
   <extension point="org.eclipse.ui.menus">
      <menuContribution locationURI="popup:org.eclipse.jdt.ui.source.menu?after=generateGroup">
        <command
              commandId="GenerateBuilderProject.commands.GenerateBuilder"
              id="GenerateBuilder.menus.GenerateBuilder">
        </command>
      </menuContribution>
   </extension>
</plugin>

Upvotes: 1

Related Questions