Contenttypes and describers

From Bioclipse
Jump to: navigation, search
Development tutorial
Responsible author:Ola
Bioclipse version:N/A
"N/A" is not a number.
Last updated:2009-10-10
Tags:


ContentTypes basics

ContentTypes are used to collect file extensions in an entity. A basic ContentType looks like this:

       <content-type
             file-extensions="pdb"
             id="net.bioclipse.contenttypes.pdb"
             name="PDBContentType"
             priority="high">
       </content-type>

Describers

It is possible to add a describer that inspects the content and ensures it is accurate for this content type. It makes use of a Describer, which must implement IContentDescriber (or extend TextContentDescriber or XMLContentDescriber). You can (and should, if possible) make use of existing describers, for example CMLRootElementDescriber2.

     <content-type
             base-type="org.eclipse.core.runtime.xml"
             file-extensions="cml,xml"
             id="net.bioclipse.contenttypes.cml.molecule3d"
             name="CMLmoleculeContentType3D"
             priority="high">
        <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber2">
             <parameter
                   name="element"
                   value="{http://www.xml-cml.org/schema}molecule">
             </parameter>
        </describer>
     </content-type>

But feel free to implement your own describer, like below for CML to inspect if it contains 3D coordinates:

       <content-type
             base-type="org.eclipse.core.runtime.xml"
             file-extensions="cml,xml"
             id="net.bioclipse.contenttypes.cml.molecule3d"
             name="CMLmoleculeContentType3D"
             priority="high">
      <describer class="net.bioclipse.ui.contenttypes.CmlFileCoordinatesDescriber">
             <parameter
                   name="type"
                   value="3D">
             </parameter>
      	</describer>
       </content-type>


Editors should use contenttypes

Editors should not hardcode file-extensions but use the content type instead, like:

  <extension
        point="org.eclipse.ui.editors">
     <editor
           name="Jmol Editor"
         icon="icons/molecule3D.gif"
           contributorClass="net.bioclipse.jmol.editors.JmolEditorContributor"
           class="net.bioclipse.jmol.editors.JmolEditor"
           id="net.bioclipse.jmol.editors.JmolEditor">
           <contentTypeBinding
                 contentTypeId="net.bioclipse.contenttypes.pdb">
           </contentTypeBinding>
           <contentTypeBinding
                 contentTypeId="net.bioclipse.contenttypes.cml.molecule3d">
           </contentTypeBinding>
     </editor>
  </extension>

Note: do NOT use file extensions together with contenttypes! The idea is that contenttypes should REPLACE extensions, and if duplicated it will bypass the describer.

Actions can use contenttypes

Actions should also make use of content types. This one adds an action to an IFile which is of type CML with a molecule with 3D coordinates.

<extension point = "org.eclipse.ui.popupMenus">
 <objectContribution
   id="net.bioclipse.jmol.cmlaction"
   objectClass="org.eclipse.core.resources.IFile"
   adaptable="true">
   <visibility>
       <objectState name="contentTypeId" 
          value="net.bioclipse.contenttypes.cml.molecule3d"/>
   </visibility>
   <action id="net.bioclipse.jmol.actions.cmlaction"
     label="CMLAction3D"
     menubarPath="additions"
     class="net.bioclipse.jmol.actions.CmlAction"
     enablesFor="1">
   </action>
 </objectContribution>
</extension>