0
我想使用切換菜單選項,但可能會犯一些錯誤。下面的代碼切換菜單項創建,當我點擊該選項用於加載後的首次,它工作正常,但是當我再次點擊切換回老態,我得到以下錯誤:Eclipse插件:切換菜單命令無法找到處理程序
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;
}
}
有人能幫我理解我的代碼有什麼問題,它只查找處理程序一次,而不管當前的菜單狀態如何?
謝謝