Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340026 - @canExecute in Handlers does not effect tool items in a toolbar
Summary: @canExecute in Handlers does not effect tool items in a toolbar
Status: RESOLVED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.1 RC2   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-15 10:10 EDT by Kai Toedter CLA
Modified: 2013-04-29 12:28 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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