Eclipse插件:toggle menu命令无法找到处理程序

时间:2011-02-03 16:57:47

标签: eclipse-plugin eclipse-rcp

我正在尝试使用切换菜单选项,但可能会犯一些错误。下面的代码创建切换菜单项和当我在加载后第一次单击此选项时,它工作正常,但当我再次单击以将其切换回旧状态时,我收到以下错误:

org.eclipse.core.commands.NotHandledException: There is no handler to execute for command my.commands.compileAutomatically
    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)
    ....

菜单:

<command
    commandId="my.commands.compileAutomatically"
    label="Compile Automatically"
    style="toggle">
</command>

命令:

<command
    defaultHandler="my.handlers.CompileAutomaticallyHandler"
    id="my.commands.compileAutomatically"
    name="Compile Automatically">
    <state
        class="org.eclipse.ui.handlers.RegistryToggleState:true"
        id="org.eclipse.ui.commands.toggleState">
    </state>
</command>

处理程序:

public class CompileAutomaticallyHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Command command = event.getCommand();
        boolean oldValue = HandlerUtil.toggleCommandState(command);
        System.out.println(oldValue);
        return null;
    }
}

有人可以帮助我理解我的代码有什么问题,它无论当前菜单状态如何都只找到一次处理程序吗? 感谢

1 个答案:

答案 0 :(得分:0)

尝试覆盖isHandled()并在CompileAutomaticallyHandler中返回false。