激活/停用命令Eclipse插件开发的IHandlerActivation上的这段代码有什么问题 [英] What are wrong with this code on Activating/Deactivating IHandlerActivation of Command Eclipse Plugin Development

查看:95
本文介绍了激活/停用命令Eclipse插件开发的IHandlerActivation上的这段代码有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有2个命令,分别由 PLAY_COMMAND_ID STOP_COMMAND_ID 标识。每个命令都有各自的处理程序,分别是 playHandler stopHandler (这些扩展了 AbstractHandler 类)。

So, I have 2 commands, which are identified by PLAY_COMMAND_ID and STOP_COMMAND_ID. Each of command have each handler, respectively playHandler and stopHandler (these are extending AbstractHandler class).

这些命令以按钮样式添加到我视图的工具栏中。基本上我想要的最初是 PLAY_COMMAND 是活动的,而 STOP_COMMAND 没有。单击 PLAY_COMMAND 时,它将激活 STOP_COMMAND 然后停用自身( PLAY_COMMAND )。反之亦然,当点击 STOP_COMMAND 时。

These commands are contributed to my view's toolbar in Button style. Basically what I want is initially the PLAY_COMMAND is active but the STOP_COMMAND not. When the PLAY_COMMAND is clicked, then it will activate the STOP_COMMAND then deactivate itself(PLAY_COMMAND). And vice versa when the STOP_COMMAND clicked.

所以我要做的就是这样。首先,它起作用(我单击了播放按钮,然后激活了停止按钮,并且禁用了播放按钮。我单击了停止按钮,然后激活了播放按钮,并且禁用了停止按钮。但是当我单击播放按钮时同样,当停止按钮也处于活动状态时,播放按钮仍处于活动状态。因此,我的代码在哪里出问题了:

So what I do is like this. At first it works (I clicked play-button, then stop-button is activated and play-button disabled. I clicked stop-button, then play-button is active and stop-button is disabled. But when I clicked the play-button again, the play-button is still active when the stop-button is active too). So what's wrong with my code here:

private AbstractHandler playHandler, stopHandler, pauseHandler, stepHandler;
private IHandlerActivation playActivation, stopActivation, pauseActivation, stepActivation;
private void createHandlers(){
  final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
    playHandler = new AbstractHandler() {

      @Override
      public Object execute(ExecutionEvent event) throws ExecutionException {
        handlerService.deactivateHandler(playActivation);
        if(stopActivation == null){
          stopActivation = handlerService.activateHandler(STOP_COMMAND_ID, stopHandler);
        } else {
          handlerService.activateHandler(stopActivation);
        }
        return null;
      }
    };

    stopHandler = new AbstractHandler() {

      @Override
      public Object execute(ExecutionEvent event) throws ExecutionException {
        handlerService.deactivateHandler(stopActivation);
        handlerService.activateHandler(playActivation);
        return null;
      }
    };  
    playActivation = handlerService.activateHandler(PLAY_COMMAND_ID, playHandler);
  }
}

createHandlers()方法在我的视图的 createPartControl(Composite parent)方法的末尾被调用。

The createHandlers() method is called at the end of createPartControl(Composite parent) method in my View.

推荐答案

好的,这就是我发现的内容。调用 activateHandler(IHandlerActivation)方法时返回的 IHandlerActivation 不能使用再次激活相同的处理程序。因此,解决方案是尝试调用 handlerService.activateHandler(commandID,playHandler)而不是调用 handlerService.activateHandler(playActivation)

Okay, so here what I found. The IHandlerActivation, that is returned when calling activateHandler(IHandlerActivation) method, when it is deactivated, can't be used again in activating the same handler. So the solution is try calling handlerService.activateHandler(commandID, playHandler) instead of calling handlerService.activateHandler(playActivation).

这篇关于激活/停用命令Eclipse插件开发的IHandlerActivation上的这段代码有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆