eclipse rcp change icon for xml configuration file

2019-05-24 17:42发布

问题:

I built an Eclipse RCP application that uses the configuration.xml in the root of the project for some project configurations. I would like to customize the icon and keep default xml editor. I found one blog post, that does exactly what I'm looking for a property file. I extracted it:

<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>

I guess that I basically need to adjust the attribute class of the editor element to the implementation of the xml editor in Eclipse. I installed the org.eclipse.wst.xml_ui.feature.feature.group. I'm not able to find the right implementation. Please help :) Thank you!

回答1:

I could to solve my problem, here is my solution if someone should have the same issue.

 <extension
        point="org.eclipse.core.contenttype.contentTypes">
     <content-type
           base-type="org.eclipse.core.runtime.xml"
           file-names="configuration.xml"
           id="org.eclipse.core.runtime.xml.spl"
           name="Software Product Line Configuration"
           priority="normal">
     </content-type>
  </extension>
  <extension
        point="org.eclipse.ui.editors">
     <editor
           class="org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"
           default="true"
           icon="icons/configuration.png"
           id="YOUR_ID"
           name="Software Product Line Configuration">
        <contentTypeBinding
              contentTypeId="org.eclipse.core.runtime.xml.spl">
        </contentTypeBinding>
     </editor>
  </extension>

I imported the org.eclipse.wst.xml.ui bundle to my workspace and had a look into Extension tab in the MANIFEST.MF file. The extension point org.eclipse.ui.editors appeared just one. So I used the implementation in the class attribute and it worked :)

Edit: If I would have known about the Eclipse Plugin Spy, this would have been easier. So, if a feature is already present, just use the magic shortcut to figure out the implementation details :)