views:

512

answers:

3

This is my first attempt at an Eclipse plugin- the plugin architecture is vast and a little overwhelming, but I've found a number of tutorials and how-to's online which is helping, but trying to do the following is driving me nuts:

I want to add a submenu item that is available in the navigator context menu when you right click on an Eclipse project.

I can get a submenu to appear on a project file or folder, but absolutely no idea how to have it appear on a project.

Would someone be so kind as to provide me with step by step instructions, starting with creating a new plugin-project? This is probably a lot to ask, but I can't seem to find an online guide that has just the right amount of detail. I specifically want to use the plugin-project wizard rather than hand code a plugin.xml file as I am not very familiar with the Eclipse plugin architecture.

Thanks in advance!

A: 

I think you have a similar question (menu in the package explorer) here:
Renaming packages in Eclipse (thanks to Rich Seller)
This could be a good start, and is a complete plugin project.

VonC
@VonC- that is definitely helpful v.helpful, and in terms of implementation may answer the question- but I'm not sure- from scanning the source, it appears that a submenu will be added only when you hover over a file in a project, and not the project folder. I'll try it and see- would still like to know the steps to take with the new plugin project wizard...
VLostBoy
...and thanks btw! Where are my manners? :)
VLostBoy
@VLostBoy: you are welcome :) This link was more to give you a starting point, but may certainly not be *exactly* what you are looking for.
VonC
A: 

You should look into the Eclipse Common Navigator Framework there are a few tutorials on this side that tell you what to do in detail The Project Explorer is an implementation of the CNF. You should also consider using the Platform Commands to add your commands (and popup menu item) to the popup menu associated with the project explorer. It's somewhat easier to use commands than actions. You should be able to do it with by adding a Command in your plugin extensions. Unfortunately off the top of my head I don't know the right incantation to have the command appear in the project explorer. But you will be able to find it in these resources.

Francis Upton
Thats an excellent resource- but the information required is buried in too deep- IMHO Eclipse documentation tends to require a priori knowledge of the subject at hand- which defeats the purpose. I will (and am) interested in a comprehensive knowledge of the plugin architecture in general, but for now- all I want to do is add a pop menu to the context menu in Navigator view that will appear when I right click a project folder, and not a project asset inside a project folder- would you be able to advise me? Also, I am using menuContribtions and not deprecated viewer/object contributions. Thanks!
VLostBoy
+2  A: 

Ok- I got it- it was simple, but I got lost in the noise of the API-

Create a new Plug-in Project using the Plugin-Project Wizard and when the wizard has launched...

1. On the Plug-in Project page, use anything as the project name and 3.5 as target platform eclipse version

2. On the Content page, skip ahead and just press next

3. On the Templates page, select "plug-in with a popup menu" and press next

4. On the Sample Popup Menu page, you will see that eclipse has prefilled the field "Target Object's Class" with a value of "org.eclipse.core.resources.IFile". This means that when your popup menu will only appear when you right-click on a file in a project. As we want the menu to appear when we right click on a Project when we are using the Navigator view, simply use "org.eclipse.core.resources.IProject" instead

5. Finish

You can validate that your pop-up will appear as expected by right-clicking the MF file and "Run-as" > Eclipse Application

Now to refactor the resulting code to use menuContributions and commands rather than objectContributions and actions :)

VLostBoy
Interesting feedback, thank you. +1
VonC