所以,我有 2 个命令,它们由PLAY_COMMAND_ID
和标识STOP_COMMAND_ID
。每个命令都有每个处理程序,分别playHandler
和stopHandler
(这些是扩展AbstractHandler
类)。
这些命令以按钮样式贡献给我的视图工具栏。基本上我想要的是最初PLAY_COMMAND
是活跃的,但STOP_COMMAND
不是。单击时PLAY_COMMAND
,它将激活STOP_COMMAND
然后停用自身(PLAY_COMMAND
)。点击时反之亦然STOP_COMMAND
。
所以我的做法是这样的。起初它可以工作(我单击播放按钮,然后激活停止按钮并禁用播放按钮。我单击停止按钮,然后播放按钮处于活动状态并且停止按钮被禁用。但是当我单击播放按钮时同样,当停止按钮也处于活动状态时,播放按钮仍然处于活动状态)。那么我的代码有什么问题:
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)