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

Bug 340026

Summary: @canExecute in Handlers does not effect tool items in a toolbar
Product: [Eclipse Project] e4 Reporter: Kai Toedter <kai.toedter>
Component: UIAssignee: Paul Webster <pwebster>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, pwebster, remy.suen, tom.schindl
Version: unspecified   
Target Milestone: 4.1 RC2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Kai Toedter CLA 2011-03-15 10:10:38 EDT
As an example: in the e4 contacts demo the SaveHandler has a @canExecute annotation. This works perfectly when putting either a direct or a handled menu item in a menu (in the contacts demo in the File menu). But is does not work when putting a direct or handled tool item into a toolbar.
Comment 1 Kai Toedter CLA 2011-03-15 11:59:26 EDT
even modifying class HandledContributionItem (this is used as renderer for both menu and tool items) like	

private boolean isEnabled(MHandledItem item) {
  final IEclipseContext lclContext = getContext(item);
  ParameterizedCommand cmd = item.getWbCommand();
  if (cmd != null) {
    EHandlerService service = (EHandlerService) lclContext
     .get(EHandlerService.class.getName());
    return service.canExecute(cmd);
  }
  return item.isEnabled();
}

and invoking isEnabled(...) does only help when creating the toolbar. The checking of menu items (invoking the service.canExecute() method) is done every time a menu pops down. But the toolbar is static and nothing triggers the canExecute check.
Comment 2 Paul Webster CLA 2011-03-15 14:37:19 EDT
We're creating RATs for the visibility of toolitems, jut not for the enabled state.

PW
Comment 3 Kai Toedter CLA 2011-03-28 09:16:26 EDT
Paul, is this easy to fix then?
Comment 4 Paul Webster CLA 2011-03-28 13:59:30 EDT
I think so ... ToolBarManagerRenderer needs to generate RATs for enabled state, similar to org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.processAddition(MToolBar, ToolBarManager, MToolBarContribution) does for visibility.

Although because enabled is all about the handler @CanExecute, maybe HandledContributionItem should generate the RAT (and make sure it's disposed when necessary).

PW
Comment 5 Remy Suen CLA 2011-05-13 14:14:56 EDT
Paul, think this was the bug that Tom was talking about yesterday?
Comment 6 Paul Webster CLA 2011-05-17 10:19:18 EDT
Released to HEAD
PW