Trying to put new “Generate” option under Source menu in Eclipse

可紊 提交于 2019-12-12 03:09:47

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/14864415/trying-to-put-new-generate-option-under-source-menu-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!