Eclipse Luna: Handlers' @CanExecute methods not called
Asked Answered
I

1

3

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!

Impromptu answered 25/6, 2014 at 16:16 Comment(0)
A
8

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.

Apostatize answered 25/6, 2014 at 16:25 Comment(6)
Thanks for your answer. Would this solution also work for menu items?Impromptu
I'm not seeing a problem with main menu @CanExecute methodsApostatize
I think I found the problem for the menu items. It is related to the Unity panel (I'm developing under Ubuntu). If i run my application with an empty value for the UBUNTU_MENUPROXY environment variable, then @CanExecute methods are called correctly. Otherwise, I have the issue i described in my post.Impromptu
I added the line but it didn't work for me :-(. Should I subscribe to the event?Casease
@Casease No you don't subscribe to this. You make this call at the point in your code where you want to force toolbar item CanExecute methods to be run (only works for toolbars). If you continue to have problems ask a new question.Apostatize
I opened a new question: #25619403Casease

© 2022 - 2024 — McMap. All rights reserved.