Eclipse Tip:Define Custom Conteet Types to Identify Your Data Files


【自転】http://www.developer.com/java/data/article.php/3648736/Eclipse-Tip-Define-Custom-Content-Types-to-Identify-Your-Data-Files.htm
In desk top environmenmenmenments,the typical aaappaaaaphphininininininfile's contetentisto chchectttttxtenseextens.You're famimimimirir with the mree-letter eextensed used byther r r r r-grgrgrowowowowinininininininininininininininininindededededededeststststststststststststststststststststststststststststststststststststststststststststststststststststststststststststststs name ends in a'.doc'は、it may not be the text document format you expect.In the Eclipse Workbench,ティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティティアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアs is「.xml」regardless of what kind of data the y contain.This way,generaniation capable of viewing XML files can immediate recognize the file as.However,this does not work for specialized Eclipse editors built to handle a specific type of XML content.Defining Contit Type Listing 1:Declaring a contentite extens for XML files containing the「apples」element.ement.ement.ement.ement.ement.Etentrement.com.                              Starting with version 3.0、Eclipse provides a mechange ism to programmatic ally dentify file types based on their actual content.The org.eclipse.cope.contens.contentinewhich is a class capable of recognizing specific types of content given n n n input steam.Editors designed to work with a specific content can be bound to it instead of a file extens.Although it it is posstrablethe default ones oten will do the job.Eclipse provides a BinarySignature Describer,which uses the file's binary signature to identifty content,and a XMLrootEment Describer,which chectttchement Xtem'ttttttttttttchectres.Both can be parameterized with aplication-specifiic values.Listing 1 illustrates how to define a custom content type to represent XML files whose root element is「aples」.See the Resource.See Resource.    「.xml」.This makes the ididentiification process more efficient-it allows the pltform to eexcluuud d d type from condededededededestinininfor fis therererereeeeeeeeftitititttttttininininininininininininststststststststinininininininininininininininininininststststststststststststststststinininininininininininininininininininininininininininininininininininininininininines"content type.
<extension point=「org.eclipse.ui.editors」                  Once You define a content type for your data format,you can bind the apprate editor it.In the autched example,you have two sample XML editors.The Apple Editor is for.the Oranges Editor handles XML files with“oranges”in their root.Listing 2 shows an extension declaring the Apples Editor and binding it to the“apples”content type.    Note:As far as the ediitors ararare concerned,the file extetensno longarmaters.Any file eeextetensininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininins「s」as its root element.Based on this,the workbench then opens ethe Appless Editor the the Oranges Editor,respively.Also,when you right-click an XML in the Reso Resource Navigator,prest the Prot Prote the profilt.    * Eclipse Platform Plug-inn Developer Guide:Contit types    * Dcumentation for the org.eclipse.co re.runtime.com ntTypes extension point    * Example plug-inn source(Eclipse 3.2 project)About the Author Peter Nehrer is a sofffftware consultant specializing Eclipse- based enterprprinininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininintts at Amhers、MA.Peter can be reached at pnerer AT eclipticalsoftware DOT com.
 
時間の問題で整理もできずにそのままコピーしてきました.自分で簡単に試してみました.とても簡単です.
plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.editors">
      <editor
            name="Sample XML Editor"
            extensions="test"
            icon="icons/sample.gif"
            contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
            class="contest.editors.XMLEditor"
            id="contest.editors.XMLEditor">
         <contentTypeBinding
               contentTypeId="ca.ecliptical.examples.contenttype.apples">
         </contentTypeBinding>
            
      </editor>
   </extension>
   <extension
         point="org.eclipse.core.contenttype.contentTypes">
         <content-type base-type="org.eclipse.core.runtime.xml"
	                 file-extensions="test"
	                 id="ca.ecliptical.examples.contenttype.apples"
	                 name="Apples File"
	                 priority="normal">
	      <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
	         <parameter name="element"
	                    value="apples">
	         </parameter>
	      </describer>
	   </content-type>
   </extension>
   

</plugin>
 界面効果:
contets type
Eclipse Tip: Define Custom Content Types to Identify Your Data Files file assioniations
Eclipse Tip: Define Custom Content Types to Identify Your Data Files