Eclipse 3.4 M6 is out. It has lots of wonderful features like p2 and the installer. But one small change that is going to save a lot of developers time is the content type specific file icons. Earlier if I had to contribute an icon for a specific file, I've to write my own label decorator. Now Eclipse comes with a label decorator that does the same.
All you have to do is to define the content type and associate an editor with that content type. If you were wondering writing an editor is not a trivial task, don't worry, you can reuse the existing ones.
Assume that in my app, I have some files with extension 'config'. They are nothing but normal properties files. I would like to invoke the Properties editor on this extension and give a different icon. Here is how I create a new content type for the extension associated the Properties editor for that.
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type base-type="org.eclipse.core.runtime.properties"
file-extensions="config"
id="in.cypal.eclipse.myConfig"
name="My Config File"
priority="normal">
</content-type>
</extension>
<extension point="org.eclipse.ui.editors">
<editor class="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditor"
default="false"
extensions="config"
icon="icons/sample.gif"
id="in.cypal.eclipse.editors.myConfigEditor"
name="My Config Editor">
<contentTypeBinding contentTypeId="in.cypal.eclipse.myConfig">
</contentTypeBinding>
</editor>
</extension>
Content types are not just based on file names/extensions. If you have an xml file, you can use the XMLContentDescriber to find the content type based on the root element; create an editor extension; specify the Text Editor/XML Editor class; associate the content id and add the icon to the editor. You are done. All of this without writing a single line of code!
Showing posts with label icons. Show all posts
Showing posts with label icons. Show all posts
Apr 1, 2008
Content type Specific File icons
Feb 11, 2008
Eclipse Icons - follow up post
Follow up 1:
Ben had a nice script for fetching all the icons from the cvs. I'm adding it here:
#!/bin/sh
CVSROOT=:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse
export CVSROOT
mkdir -p eclipse
cd eclipse
cvs -q co org.eclipse.debug.ui/icons
cvs -q co org.eclipse.pde.ui/icons
cvs -q co org.eclipse.jdt.ui/icons
cvs -q co org.eclipse.vcm.ui/icons
cvs -q co org.eclipse.team.ui/icons
cvs -q co org.eclipse.ant.ui/icons
cvs -q co org.eclipse.help.ui/icons
cvs -q co org.eclipse.ui/icons
cvs -q co org.eclipse.ui.views/icons
cvs -q co org.eclipse.ui.console/icons
cd ..
rm -f ~/public_html/eclipse-icons.zip
find eclipse -name "*.gif" -print | zip ~/public_html/eclipse-icons.zip -@
I remember Ben having a HTML page which lists all the icons. But due to bandwidth issues, he moved it to a zipped set of icons. Now that is also gone from the page. I've a back up of those icons. So if you want the complete set of icons, instead of the most commonly used ones, download them here.
Follow up 3:
Phillipus left a comment in the post saying how to access the icons from other plugins without bundling them in your plugin:
AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", "$nl$/icons/full/etool16/import_wiz.gif");
This is cool but raises an interesting question. What happens during an Eclipse upgrade? Will they be retained in the same name? Or rather a straight question: Are these icons part of API? I didn't know the answer. So posting the question here. Those who know please throw some light on this.
Related:
Eclipse Icons - original post
Searching for Eclipse - source, blogs, images ...
Accessing CVS of Eclipse.org
Subscribe to:
Posts (Atom)
