Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 469692 - Command.getHandler return WorkbenchHandlerServiceHandler instead of mine
Summary: Command.getHandler return WorkbenchHandlerServiceHandler instead of mine
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4.2   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-09 05:02 EDT by Jonathan CLAUDE CLA
Modified: 2020-07-27 11:50 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan CLAUDE CLA 2015-06-09 05:02:34 EDT
Hi all,

Switching our product from eclipse 3.6 to eclipse 4.4, I find a regression on our popup menus. We get some actions we should not have on some tree items.

We have our own implementation of org.eclipse.core.commands.AbstractHandler which override method isEnabled().

What we do when a tree item is selected is something like that :

commandService = (ICommandService) getWorkbench().getAdapter(ICommandService.class)
Command command = commandService.getCommand(cmdId);
IHandler handler = command.getHandler();

if (handler instanceOf MyHandler) {
   ((MyHandler) handler).setEnabled(false);  //to disable the command
}

It used to work in eclipse 3.x but not anymore with eclipse 4.4.2 because instead of MyHandler, I have an instance of WorkbenchHandlerServiceHandler.

I have found a workaround right now but I would like something cleaner if exists to avoid going into internal package of eclipse.

What I do to get my own instance of Handler : 

IEclipseContext eclipseContext = (IEclipseContext) activeWorkbench.getService(IEclipseContext.class); 
Object obj = HandlerServiceImpl.lookUpHandler(eclipseContext, cmdId);
if (obj instanceof E4HandlerProxy) { 
   E4HandlerProxy e4HandlerProxy = (E4HandlerProxy) obj;
   IHandler activeHandler = e4HandlerProxy.getHandler(); 
      if (activeHandler instanceof MyHandler) {
         final MyHandler dHandler = (MyHandler) activeHandler;
         ((MyHandler) dHandler).setEnabled(enabled);
      }
}
Comment 1 Eclipse Genie CLA 2020-07-27 11:50:33 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.