J Fabian Meier
J Fabian Meier

Reputation: 35795

Different IResource in Eclipse package explorer

I want to extend the popup menu for different resources in the package explorer.

I understand that I can attach menus to IResources, or, more specifically also to IProject or IFolder.

Now I want to add something in the popup menu purely for Java methods (as subelements of java classes, which sit in java files). What should I do to restrict my menus to just those elements?

Upvotes: 0

Views: 41

Answers (1)

Bananeweizen
Bananeweizen

Reputation: 22070

Select a Java method in your package explorer and hit Alt-Shift-F1. The Eclipse spy pops up and tells you that the currently selected element is of type org.eclipse.jdt.internal.core.SourceMethod.

If you are creating a menu contribution, then its "menu" child has a "visibleWhen" core expression where you would add a child "instanceof" referring to the above type.

If you are creating your menu in another way (like extending the common navigator framework) you will also always find some means to specify a core expression for enablement or visibility of your extension, and you can always use an instanceof check in that core expression then.

Upvotes: 1

Related Questions