Support POJO handlers in the org.eclipse.ui.handlers extension point - #4242
Support POJO handlers in the org.eclipse.ui.handlers extension point#4242vogella wants to merge 1 commit into
Conversation
A handler contributed via the class attribute had to implement IHandler. Anything else failed the cast in HandlerProxy with a logged ClassCastException and left the proxy permanently disabled. Contributions that do not implement IHandler are now wrapped in an adapter that dispatches to their @execute and @CanExecute methods through dependency injection, the same mechanism the E4 application model already uses for its handlers. Field and method injection plus @PostConstruct work as well. Instantiation still goes through createExecutableExtension, so IExecutableExtension and the <class><parameter> form keep working unchanged, and handlers implementing IHandler take the previous path untouched.
Test Results 858 files 858 suites 51m 7s ⏱️ Results for commit 1b492d9. |
|
Why would an E4 handler be additional being registered through |
|
This is for the migration path e3 handlers -> POJO -> later to model similar to what we offer for view and e4 views. As a migration path is currently missing we have seen zero migration of e3 to e4 handlers in the last 10 years in platform. |
You know that "later" is a synonym for "never" in computer programming right? So I don't see how this would benefit anything from going straight to e4-model - what should actually be possible already. If not it would better be enabled like that instead of offering to use a middle-ground between e3 + e4. |
|
Lots of my RCP client would be able to migrate their handler code to POJOs with little risk with this change. |
But again, what is the risk of declaring them in e4.xmi directly? If I remember right there is/was even an automatic migration offered there for views as well. That would offer a much more sustainable migration path here. |
The e4 model persists its state while plugin.xml is recreated every startup so e4 model contributions have the risk of getting stale. So the client hesitate to do this one by one for a handler. With this change they can first migrate the Java code and afterwards do the model migration. |
Handlers contributed through the
classattribute oforg.eclipse.ui.handlershad to implementIHandler. Anything else failed the cast inHandlerProxy, which logged aClassCastExceptionand left the proxy permanently disabled.Such contributions are now wrapped in an adapter that dispatches to their
@Executeand@CanExecutemethods through dependency injection, the same mechanism the E4 application model already uses for its handlers. Field and method injection plus@PostConstructwork as well. This lets plug-ins written against the E4 programming model contribute handlers declaratively without deriving fromAbstractHandler, and removes the need for hand-written bridge classes.Instantiation still goes through
createExecutableExtension, soIExecutableExtensionand the<class><parameter>form keep working unchanged, and handlers implementingIHandlertake the previous path untouched. The schema is deliberately left alone:basedOnproduces no validation markers in PDE, it only scopes the type browse dialog and prefills the new class wizard, so keeping it preserves that assistance for theIHandlermajority at the cost of the Browse button for POJO authors.Two limitations are worth noting. Constructor injection is not supported, since instantiation stays on the registry path.
IObjectWithStateis not forwarded to the handler, so a POJO cannot read or write command state directly, although toggle and radio rendering is unaffected becauseHandlerProxyholds that state itself.