Eclipse Luna: Handlers' @CanExecute methods no

2019-02-19 12:03发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-02-19 12:36

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.

查看更多
登录 后发表回答