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

Bug 369682

Summary: Problem with org.eclipse.core.commands and MakeHandlersGo
Product: [Eclipse Project] Platform Reporter: Vincent Lorenzo <vincent.lorenzo>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: pwebster, remy.suen
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Vincent Lorenzo CLA 2012-01-25 10:46:29 EST
I wrote JUnit tests on Indigo to tests the handler activation. On Juno, this code doesn't work for several reasons : 
	- MakeHandlersGo.isEnabled() returns always true without testing the real handler
	- MakeHandlerGo is not a HandlerProxy, so I can't get the Handler declared in the plugin.xml to do an instanceof on it.


org.eclipse.core.commands.Command testedCommand = ...
IHandler handler = testedCommand.getHandler();
if(handler instanceof HandlerProxy) {
handler = ((HandlerProxy)currentHandler).getHandler();
}
Assert.isTrue(handler instanceof MyOwnHandler);
Assert.isTrue(handler.isEnabled());

Now with this code I get a MakeHandlersGo which is always enabled...

I think it is a bug on the compatibility layer? Do you have a solution to adapt my tests
Comment 1 Paul Webster CLA 2012-01-25 10:57:08 EST
You cannot depend on Command#getHandler();  We are free to set that to whatever we want.  

MakeHandlerGo in the M5 warmup isEnabled() will return enable for the active handlers now.

In Eclipse 4 you can look up a handler (technically also using internals) using something like:

MApplication app = workbench.getService(MAppliation.class);
IEclipseContext context = app.getContext();
Object handler = HandlerServiceImpl.lookUpHandler(context, "command.id");

In 4.2 that tends to be an E4HandlerProxy, also an internal class.

If you are looking on more information on this, I would suggest the Eclipse Platform or E4 forum at http://www.eclipse.org/forums/

PW
Comment 2 Vincent Lorenzo CLA 2012-01-25 11:18:44 EST
Thank you for your answer. I posted this question on the forum the 23th of January before to post this bug, but I didn't get an answer. 
/Vincent Lorenzo