Posts

Showing posts from December, 2011

How to register an eclipse editor by file content

Sometimes you may want to register an eclipse editor by reading file content. As an example if we need to open Maven POM file with specificity packing type with your editor or if you need to use different files without file extension, so we have to write a custom ContentDescriber to handle it.  We can write custom ContentDescriber by extending or implementing following classes/ interfaces. ITextContentDescriber XMLContentDescriber IContentDescriber BinarySignatureDescriber   So let's write a custom ContentDescriber by extending XMLContentDescriber package org.my.editor.describer; import java.io.IOException; import java.io.InputStream; import org.eclipse.core.runtime.content.IContentDescription; import org.eclipse.core.runtime.content.XMLContentDescriber; public class MyDescriber extends XMLContentDescriber { public int describe(InputStream input, IContentDescription description) throws IOException { /** Implement logics to validate content by reading input strea