简体   繁体   English

工具栏描述与Eclipse RCP中的代码之间的连接在哪里?

[英]Where is the connection between toolbar description and the code in Eclipse RCP?

I have added the button in the following way: 我按以下方式添加了按钮:

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               label="File">
            <command
                  commandId="org.eclipse.ui.file.exit"
                  label="Exit">
            </command>
         </menu>
      </menuContribution>
      <menuContribution
            allPopups="false"
            locationURI="toolbar:MYVIEWID">
         <command
               commandId="MYCOMMANDID"
               icon="icons/1389818330_Run.png"
               label="Run a bot"
               style="push">
         </command>
      </menuContribution>
   </extension>

In result, toolbar button appears on the view, but it is dimmed and does nothing. 结果,工具栏按钮出现在视图上,但它变暗并且什么都不做。

Where to set the code which will execute on this button press? 在哪里设置将在此按钮上执行的代码?

You use the org.eclipse.ui.handlers extension point to define a handler for the command id. 您可以使用org.eclipse.ui.handlers扩展点为命令id定义处理程序。

<extension
     point="org.eclipse.ui.handlers">
  <handler
        class="org.eclipse.ui.examples.contributions.handlers.GlobalMenuHandler"
        commandId="org.eclipse.ui.examples.contributions.commands.globalCommand">
  </handler>
</extension>

You must also use the org.eclipse.ui.commands extension point to define the command id in the first place. 您还必须首先使用org.eclipse.ui.commands扩展点来定义命令ID。 You can specify a default handler in the command id definition: 您可以在命令ID定义中指定默认处理程序:

<extension
     point="org.eclipse.ui.handlers">
  <command
        categoryId="org.eclipse.ui.examples.contributions.commands.category"
        defaultHandler="org.eclipse.ui.examples.contributions.handlers.GlobalMenuHandler"
        id="org.eclipse.ui.examples.contributions.commands.globalCommand"
        name="%contributions.commands.globalCommand.name">
  </command>
</extension>

(above examples are from the Eclipse help). (以上示例来自Eclipse帮助)。

There is also this tutorial on commands. 还有关于命令的本教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM