|
Re: Project context menu [message #875774 is a reply to message #875451] |
Wed, 23 May 2012 10:25 |
Eclipse User |
|
|
|
Edwin Park wrote on Tue, 22 May 2012 22:22
2. get access to the selected IProject in the command handler
@Inject
public void handleSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IProject project) {
if (project != null) {
// handle it
}
}
|
|
|
|
Re: Project context menu [message #877003 is a reply to message #876978] |
Fri, 25 May 2012 17:23 |
Eclipse User |
|
|
|
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.
|
|
|
Re: Project context menu [message #880144 is a reply to message #876978] |
Fri, 01 June 2012 14:17 |
|
Edwin Park wrote on Fri, 25 May 2012 12:08
@Execute
@Inject
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IProject project) throws IOException {
if (project != null) {
IPath location = project.getLocation();
...
}
}
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.
Quote:
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.
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.03523 seconds