Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369682 - Problem with org.eclipse.core.commands and MakeHandlersGo
Summary: Problem with org.eclipse.core.commands and MakeHandlersGo
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-25 10:46 EST by Vincent Lorenzo CLA
Modified: 2012-01-25 13:33 EST (History)
2 users (show)

See Also:


Attachments

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