Simple SWT/JFace exercise fails to find handler

♀尐吖头ヾ 提交于 2019-12-24 19:07:05

问题


I'm working through "Eclipse 4 Plug-in Development by Example Beginner's Guide" and up to section "Time for action creating commands and handlers".

This defines a simple command, handler, and menuContribution. I followed the instructions in the text, but when the menu rendered, the menu item was insensitive.

I then noticed that the default implementation of the "isEnabled" method in the handler just returns "false". I changed it to "true" and that made the menu item sensitive, but when I selected it, I saw the following:

org.eclipse.core.commands.NotHandledException: There is no handler to execute for command com.packtpub.e4.clock.ui.command.hello
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:485)
    at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
    at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)

Here is the relevant excerpt from my plugin.xml file:

<extension point="org.eclipse.ui.commands">
  <command description="Says Hello World"
       id="com.packtpub.e4.clock.ui.command.hello" name="Hello">
  </command>
</extension>
<extension point="org.eclipse.ui.handlers">
  <handler class="com.packtpub.e4.clock.ui.handlers.HelloHandler"
       commandId="com.packtpub.e4.clock.ui.command.hello">
  </handler>
</extension>
<extension point="org.eclipse.ui.menus">
  <menuContribution allPopups="false"
        locationURI="menu:help?after=additions">
<command commandId="com.packtpub.e4.clock.ui.command.hello"
     label="Hello"
     style="push">
</command>
  </menuContribution>
</extension>

The text in the book even stated "If the Hello menu is disabled, verify that the handler extension point is defined, which connects the command to the handler class." As far as I can tell, I've done that, but apparently not.

来源:https://stackoverflow.com/questions/33190307/simple-swt-jface-exercise-fails-to-find-handler

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