1. contribute a menu item command in the right-click context menu of a project in the Project Explorer view.
2. get access to the selected IProject in the command handler
I currently have a top-level menu/command/handler contributed via a fragment.e4xmi that uses the ESelectionService to determine if the selection holds an IProject. This is fine, but given that the command is really only related to a project, I'd like to be able to let the user right-click on the project itself and select the command from the project's context menu.
Thanks for the reply, but I don't think this works for my particular situation (or I may need some additional help figuring out how it would!)
My understanding is the @Inject would work for a handleSelection() method in a View... but in my case I want to get access to the selected project from a command handler annotated with @Execute. Basically this is a one-off command I want to run that needs to know the location of the selected project to do its work.
Sopot Cela Messages: 597 Registered: December 2010
Try to remove the @Inject after @Execute in the second code sample.
When you annotate methods with @Focus, @Execute the framework tries to inject the values of the matching type or of the matching name (what @Inject does), regardless if it is in a view or in a handler.
Another alternative would be to use the ESelectionService.getSelection() inside your method which gets the value from the context after the aggregation, much in the same way as the parameter injection does.
I think Sopot mentioned this, but your handlers shouldn't have any @Inject annotations in them. Everything should be requested in your @Execute method parameter list.
I'm also still in the dark as to how to contribute a menu item to the right-click context menu for a project (my original question #1)...
To contribute to a popup menu, use an MMenuContribution added to the MApplication. It follows the same patterns as an org.eclipse.ui.menus menuContribution. There's also a visibleWhen attribute where you can add an MCoreExpression. The expression must still be defined in the org.eclipse.core.expressions.definitions extension point.