Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Plugin Development, associating different editors to same file extension

I am developing an eclipse plugin that associates a certain Editor to a specific file extension, say ".abc".

The problem is I want to associate .abc files to that editor only for my own projects with my own nature on it. As it is now, it will always open .abc files with that editor no matter in which project.

How can I open my own editor for ".abc" files only if they are in projects with my own nature?

like image 345
FabianB Avatar asked Feb 10 '11 01:02

FabianB


People also ask

How do I open the same file twice in Eclipse?

Select New Editor, then you have 2 files with the same name opened in the same window. . Drag one file to other window. In this way, you can open the same file more than twice in different windows or the in same window.


1 Answers

You need to define a content-type using the org.eclipse.core.contenttype extension point. Then you need to associate your editor with the particular content type (and not the file extension).

Next, you need to associate your project nature with the content type that you just defined.

You may also need to create a second content type that should be used for your files when outside of a project with the specific nature.

Here is an example that we used in Groovy-Eclipse so that *.groovy files would be opened with a groovy editor by default in groovy projects, but by a text editor outside of groovy projects:

 <extension point="org.eclipse.core.contenttype.contentTypes">
    <content-type
       base-type="org.eclipse.jdt.core.javaSource"
       file-extensions="groovy"
       id="groovySource"
       name="Groovy Source File (for Groovy projects)"
       priority="high"/>

    <content-type
       base-type="org.eclipse.core.runtime.text"
       file-extensions="groovy"
       id="groovyText"
       name="Groovy Text File (for non-Groovy projects)"
       priority="low"/>
</extension>

<extension
     id="groovyNature"
     name="Groovy Nature"
     point="org.eclipse.core.resources.natures">
  <runtime>
     <run class="org.codehaus.jdt.groovy.model.GroovyNature"/>
  </runtime>
  <requires-nature id="org.eclipse.jdt.core.javanature"/>
  <content-type
        id="org.eclipse.jdt.groovy.core.groovySource">
  </content-type>

Here, we define groovySource for groovy projects and groovyText for non-groovy projects. Notice also, that the priority of the content-types are different.

And then, elsewhere, we associate the GroovyEditor with the groovySource content-type.

like image 136
Andrew Eisenberg Avatar answered Sep 30 '22 04:09

Andrew Eisenberg