Writing an Eclipse Plug-in (Part 6): Adding an Icon To New Project Types
So there you are: it’s the middle of the night and you suddenly wake up bathed in sweat with the question that has been haunting you for ages: how does a newly defined Eclipse project type get an associated image?
Adding an Icon to Newly Created Custom Projects
It has to do with natures. Remember how in Part 4 we added a custom nature to our custom project? Well, let’s put that custom nature to some use:
- Open
customplugin plugin.xml
–> Extensions. Click onorg.eclipse.core.resources.natures
. Note that its ID iscustomplugin.projectNature
. - From the Extensions tab click Add. Type proj in the Extensions window. The
org.eclipse.ui.ide.projectNatureImages
extension should be the only item left. Select it and click Finish. - Right click on org.eclipse.ui.ide.projectNatureImages –> New –> image.
- Select customplugin.image1 (image), or whatever the name is of the new extension element, and enter the following in the fields to the right:
- id: customplugin.natureImage
- natureId: customplugin.projectNature
- icon: icons/project-folder.png
The id is the name of this extension element. The natureId is the id of the nature created previously and the icon image is the project folder image we used with the New Project Wizard (feel free to use an image of your own choosing or making). I should probably have selected something a little less heavy handed as typically the icon is a smaller image that Eclipse overlays in the upper right hand corner of the folder icon. We’ll fix it eventually…maybe.
Go ahead. Run the runtime workbench and create a custom project. Open the Navigator view to take an unadulterated view of the project with its new shiny icon.
It’s okay. You can get some sleep now. The cat is alive.
Leave a comment Cancel reply
Top Posts
Archives
- January 2012 (1)
- February 2011 (1)
- January 2011 (1)
- August 2010 (2)
- June 2010 (1)
- May 2010 (2)
- April 2010 (1)
- March 2010 (1)
- February 2010 (4)
- January 2010 (2)
- December 2009 (5)
- November 2009 (2)
- October 2009 (6)
- September 2009 (6)
- August 2009 (4)
- July 2009 (6)
- April 2009 (2)
- February 2009 (2)
- December 2008 (1)
- October 2008 (2)
- September 2008 (2)
- August 2008 (1)
Top Rated
Blog Stats
- 494,313 hits
Hello, I can not see the .project file in my custom navigator but I see this file in the normal navigator. Can you help me? Thanks.
Hi, Pedro!
You can’t see the .project file in the custom navigator because I must have inadvertently turned off one of the display filters. If you click on the downward pointing arrow in the navigator menubar select Customize View.
When the Available Customizations dialog opens, go to the Filters tab and uncheck .* resources. Click OK and the .project file will appear in the custom navigator.
Thanks for pointing that out!
Ok, thanks.