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:
customplugin plugin.xml–> Extensions. Click on
org.eclipse.core.resources.natures. Note that its ID is
- From the Extensions tab click Add. Type proj in the Extensions window. The
org.eclipse.ui.ide.projectNatureImagesextension 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.
- Writing an Eclipse Plug-in (Part 2): Creating a custom project in Eclipse - Adding to the New Project Wizard
- Writing an Eclipse Plug-in (Part 1)- What I'm going to do
- Writing an Eclipse Plug-in (Part 4): Create a Custom Project in Eclipse - New Project Wizard: the Behavior
- Writing an Eclipse Plug-in (Part 7): Creating a Custom Navigator
- Writing an Eclipse Plug-in (Part 11): Common Navigator: Displaying Custom Resources or Refresh Or Die or The Magic of navigatorContent
- 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)
- 435,579 hits