Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360357

Summary: CanExecute of Handler are checked ever 500ms
Product: [Eclipse Project] Platform Reporter: Hannes Niederhausen <hniederhausen>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED DUPLICATE QA Contact: Paul Webster <pwebster>
Severity: normal    
Priority: P3 CC: daniel.rolka, daniel_megert, eclipse, ob1.eclipse, pelder.eclipse, remy.suen
Version: 4.2   
Target Milestone: 4.4 M5   
Hardware: All   
OS: All   
Whiteboard:

Description Hannes Niederhausen CLA 2011-10-09 10:06:43 EDT
Hi,

I created a CommandHandler using the @CanExecute and @Execute annotations.

Inside the annotated can execute method I added a tiny log message to check how the toolbar items in my e4 rcp are updated.

I was suprised that their seems to be a thread which checks the state constantly, which is in my opinion a great waste of CPU time.

I'm not sure if I did something wrong but if not I stonrgly suggest to extend the API for execution to annotate methods to add or remove a listnener.

I suggest some sort of minimalistic listener interface like:

interface IStateListener {

    public void stateChanged();
}


I know this would require the Handler implementations to be more complex, but would decrease the CPU usage.

The annotations could look like:

@AddStateListener
@RemoveStateListener
Comment 1 Paul Webster CLA 2011-10-09 11:46:07 EDT
The listener was the old way, and had a lot of problems (i.e. the handler and the command shouldn't have state, except in the context they could be executed in).

The toolitems must ask the @CanExecute question in their context (window, part, or dialog).

We used to allow them to be re-asked in their context when a consumed variable (from the IEclipseContext) changed, but that was not performant.  As it turns out asking every 500ms or so is more performant.

But we are still looking at this arrangement to see if we can improve it.

PW
Comment 2 Simon Chemouil CLA 2011-10-10 05:32:46 EDT
As far as I know this is only true for MHandledToolItems. 

For the record, when profiling our application, this came first in CPU usage. Costs a lot especially if the @CanExecute method is intensive.

In our application, we have similar buttons/toolitems that are bound to a command whose state is refreshed only when the @CanExecute parameters change (using RAT).

The class that does this does not imply any change of interface (afaik), and we might be able to share it (authorization pending) so we can use it as an inspiration for a patch, if interested.
Comment 3 Paul Webster CLA 2011-10-10 07:36:37 EDT
See also bug 358658

PW
Comment 4 Oleg Besedin CLA 2011-10-11 10:32:05 EDT
See also bug 358158 , bug 359082 , bug 358494 .
Comment 5 Paul Webster CLA 2014-01-14 13:29:25 EST

*** This bug has been marked as a duplicate of bug 385394 ***