Eclipse Search

Loading

Apr 1, 2008

Content type Specific File icons

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!

3 comments:

  1. Hi Prakash,
    Would you be interested in writing a small icon plugin for a small group of eclipse users?

    What we need is the ability for files (and I presume tabs by relation) to have a custom icon depending on what subfolder they are in.

    Is this possible?

    If you could contact me via my site, that would be great!

    Thanks,
    Dave
    ReplyDelete
  2. @Dave,
    I'm sorry, I can't do that. That would violate the terms of my employment :-)
    ReplyDelete
  3. what is the editor class for xml editor ? (defualt xml editor ). I want to change the icon and just run it from xml editor.
    thanks
    ReplyDelete