简体   繁体   中英

How to associate extension with custom editor in Eclipse 4

I've recently moved to Eclipse 4. In eclipse 3.x to define which editor will be associated with file extension I had to define editors extension with extension associated with it. How to do that in Eclipse 4 where editor doesn't any more inherit from EditorPart but it's a part defined with dependency injection.

Here is the old version. What is best practice for defining custom editor being opened when we double click file with certain extension (ex. bcx) in Projects View?

<extension
         point="org.eclipse.ui.editors">
      <editor
            class="com.abb.pestc.cothex.ui.editors.AirToAirEditor"
            default="true"
            extensions="acx"
            icon="icons/cothexAirToAir.png"
            id="com.abb.pestc.cothex.ui.editors.AirToAirEditor"
            name="Air to Air Editor">
      </editor>
      <editor
            class="com.abb.pestc.cothex.ui.editors.BaseToAirEditor"
            default="true"
            extensions="bcx"
            icon="icons/cothexBaseToAir.png"
            id="com.abb.pestc.cothex.ui.editors.BaseToAirEditor"
            name="Base to Air Editor">
      </editor>
   </extension> 

Interestingly, even in Kepler's sample Plugin projects, 3.* code is used:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.editors">
      <editor
            name="Sample XML Editor"
            extensions="xml"
            icon="icons/sample.gif"
            contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
            class="tempse.editors.XMLEditor"
            id="tempse.editors.XMLEditor">
      </editor>
   </extension>

</plugin>

So I suspect the answer is 'same way you did it before'. I've just moved a custom editor project from 3.* to 4.* without having to make any changes at that end (and for reverse compatibility reasons I'm fairly sure I wouldn't want to).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM