问题描述
我在Eclipse Luna RCP中遇到命令处理程序问题.
I'm having a problem with command handlers in Eclipse Luna RCP.
在我的E4应用程序模型中,我定义了一些必须启用的命令和相关处理程序仅在某些情况下.因此,在我的处理程序POJO中,我实现了用@CanExecute
注释的方法,在其中检查所需条件.
In my E4 application model, I defined some commands and related handlers that must be enabledonly under certain circumstances. For this reason, in my handler POJOs, I implementedmethods annotated with @CanExecute
where I check the required conditions.
我还定义了与这些命令关联的菜单和工具栏项.
I also defined menu and toolbar items associated with those commands.
问题是我的@CanExecute
方法未正确调用,因此,菜单和工具栏项没有相应地启用/禁用.
The problem is that my @CanExecute
methods aren't properly invoked and, as a consequence,menu and toolbar items aren't enabled/disabled accordingly.
特别是对于菜单项,@CanExecute
方法仅在应用程序启动时被调用几次,但之后不会被调用.
In particular, for menu items, the @CanExecute
methods are only invoked a few times at application startup, but never after that.
对于工具栏项目,仅在活动上下文更改时(例如,在更改活动零件或打开新外壳时)才调用@CanExecute
方法.
For toolbar items, instead, the @CanExecute
methods are only invoked when the active context changes (e.g. when changing the active part or opening a new shell).
在开普勒,行为完全不同(并且按预期工作):
In Kepler, the behaviour was quite different (and worked as expected):
- 对于菜单项,每次显示菜单时都会调用
@CanExecute
方法 - 对于工具栏项目,有一个计时器每400毫秒调用一次
@CanExecute
方法
- for menu items, the
@CanExecute
methods were invoked each time a menu was shown - for toolbar items, there was a timer that invoked the
@CanExecute
methods every 400ms
这是Luna中的已知错误吗?您知道实现预期行为的任何可能的解决方法吗?
Is this a known bug in Luna? Do you know any possible workaround to achieve the expected behaviour?
谢谢!
推荐答案
这是Eclipse Luna中的设计更改,在错误,也 436755
This is a design change in Eclipse Luna described in bug 427465, also 436755
您可以使用以下命令来运行工具栏@CanExecute方法:
You can get the toolbar @CanExecute methods run using:
eventBroker.send(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);
"eventBroker"是IEventBroker
.
'eventBroker' is the IEventBroker
.
这篇关于Eclipse Luna:未调用处理程序的@CanExecute方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!