Eclipse Luna: Handlers' @CanExecute methods not called

柔情痞子 提交于 2019-12-19 09:46:47

问题


I'm having a problem with command handlers in Eclipse Luna RCP.

In my E4 application model, I defined some commands and related handlers that must be enabled only under certain circumstances. For this reason, in my handler POJOs, I implemented methods annotated with @CanExecute where I check the required conditions.

I also defined menu and toolbar items associated with those commands.

The problem is that my @CanExecute methods aren't properly invoked and, as a consequence, menu and toolbar items aren't enabled/disabled accordingly.

In particular, for menu items, the @CanExecute methods are only invoked a few times at application startup, but never after that.

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):

  • 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

Is this a known bug in Luna? Do you know any possible workaround to achieve the expected behaviour?

Thanks!


回答1:


This is a design change in Eclipse Luna described in bug 427465, also 436755

You can get the toolbar @CanExecute methods run using:

eventBroker.send(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);

'eventBroker' is the IEventBroker.



来源:https://stackoverflow.com/questions/24413817/eclipse-luna-handlers-canexecute-methods-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!