| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> |
| <HEAD> |
| |
| <meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > |
| |
| <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> |
| <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> |
| |
| <LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css"> |
| <title>Content Sensitive Object Contributions</title> |
| |
| </HEAD> |
| <BODY BGCOLOR="#ffffff"> |
| <h2>Content Sensitive Object Contributions</h2> |
| <p>Previously, the context menus of some applications were limited by the exclusion |
| of certain menu options. This was based on the known peripheral information, |
| such as the number of selected resources, the physical name of the file, the |
| type of resource, and so on. In some instances, a restricted amount of information |
| was known about the contents of a resource and this significantly reduced unusable |
| menu options. Such information, could be of great use in an XML file as there |
| are numerous situations in which an action is applicable for one type of XML |
| file but not another, such as XML files that contain Ant scripts. The action |
| <strong>Run Ant...</strong>, while logical in its context menu, is not an action |
| that is applicable to an XML file that is used to define a plug-in.</p> |
| <p> With the addition of the extension point, org.eclipse.core.runtime.contentTypes, |
| Eclipse now provides a 'content type', allowing plug-ins to contribute to the |
| Platform content type catalog, further, classes called Content Type Describers |
| are also available. For developers providing their own content types, there |
| are two customizable, built-in content type describers available: BinarySignatureDescriber |
| (for binary content types) and XMLRootElementContentDescriber (for text, XML |
| based content types). Additionally, plug-in providers may create their own content |
| describers, for detailed information see, the Platform Plug-in Developer Guide |
| (Programmer's Guide > Runtime overview > Content types).</p> |
| <h3>XMLRootElementContentDescriber</h3> |
| <p>It is now possible to define object contributions specific to an XML file with |
| a given top level tag or that specifies a given DTD. To do this, define an extension |
| to the org.eclipse.core.runtime.contentTypes extension point with a describer |
| class of XMLRootElementContentDescriber and parameters indicating the top level |
| tag name or the dtd name as follows:</p> |
| <PRE> <extension |
| point="org.eclipse.core.runtime.contentTypes"> |
| <content-type |
| id=<id> |
| name=<name> |
| base-type="org.eclipse.core.runtime.xml"> |
| <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| <parameter name="element" value=<EM>tagValue</EM> /> |
| </describer> |
| </content-type> |
| </extension></PRE>or <PRE> <extension |
| point="org.eclipse.core.runtime.contentTypes"> |
| <content-type |
| id=<id> |
| name=<name> |
| base-type="org.eclipse.core.runtime.xml"> |
| <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| <parameter name="dtd" value=<EM>dtdValue</EM> /> |
| </describer> |
| </content-type> |
| </extension></PRE> |
| <BLOCKQUOTE>where tagValue represents the name of the top level tag to match and |
| <p>dtdValue represents the name of the DTD as seen in the XML file.</p> |
| </BLOCKQUOTE> |
| <p>Consider the following object contribution in a plugin.xml file:</p> |
| <p></p> |
| |
| <PRE> <extension |
| point="org.eclipse.core.runtime.contentTypes"> |
| <content-type |
| id="topElementContentType" |
| name="Tests top-level element recognition" |
| base-type="org.eclipse.core.runtime.xml" |
| priority="high"> |
| <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| <parameter name="element" value="myTag" /> |
| </describer> |
| </content-type> |
| </extension> |
| |
| <extension |
| point="org.eclipse.core.runtime.contentTypes"> |
| <content-type |
| id="dtdContentType" |
| name="Tests dtd element recognition" |
| base-type="org.eclipse.core.runtime.xml" |
| priority="high"> |
| <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| <parameter name="dtd" value="myDTD.xml" /> |
| </describer> |
| </content-type> |
| </extension> |
| </PRE><PRE> <extension point="org.eclipse.ui.popupMenus"> |
| <objectContribution |
| id="org.eclipse.ui.examples.objectContributions" |
| objectClass="org.eclipse.core.resources.IFile" |
| nameFilter="*.xml"> |
| <visibility> |
| <or> |
| <objectState |
| name="contentTypeId" |
| value="org.eclipse.ui.examples.topElementContentType"/> |
| <objectState |
| name="contentTypeId" |
| value="org.eclipse.ui.examples.dtdContentType"/> |
| </or> |
| </visibility> |
| <action id="org.eclipse.ui.examples.objectContributions.action1" |
| label="%PopupMenus.action" |
| icon="icons/ctool16/openbrwsr.png" |
| menubarPath="additions" |
| class="org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate" |
| enablesFor="1"> |
| </action> |
| </objectContribution> |
| </extension></PRE> |
| <P>This will make action1 visible for any IFile with a name matching *.xml |
| provided it contains myTag as the top level XML tag or it uses the DTD called |
| myDTD.xml. So the following XML files will match:</P> |
| <BLOCKQUOTE> |
| <PRE><?xml version="1.0" encoding="UTF-8"?> |
| <myTag |
| id="org.eclipse.ui.workbench" |
| name="%pluginName" |
| version="3.0.0" |
| provider-name="%providerName" |
| class="org.eclipse.ui.internal.WorkbenchPlugin"> |
| </myTag></PRE> |
| </BLOCKQUOTE> |
| <p>or</p> |
| <BLOCKQUOTE> |
| <PRE><?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE Book SYSTEM "myDTD.xml"> |
| <fragment |
| id="org.eclipse.ui.workbench" |
| name="%pluginName" |
| version="3.0.0" |
| provider-name="%providerName" |
| class="org.eclipse.ui.internal.WorkbenchPlugin"> |
| <runtime> |
| <library name="workbench.jar"> |
| <export name="*"/> |
| <packages prefixes="org.eclipse.ui, org.eclipse.jface"/> |
| </library> |
| </runtime> |
| </fragment> |
| </PRE> |
| </BLOCKQUOTE> |
| <H3>BinarySignatureDescriber</H3> |
| <p>The BinarySignatureDescriber is a content describer that detects a specified |
| binary 'signature' at a given offset within a file. This describer is used in |
| the same fashion as the XMLRootElementContentDescriber with the exception that |
| it takes parameters "signature", "offset" and "required" instead of "element" |
| or "dtd". The Javadoc for BinarySignatureDescriber provides complete details |
| on this content describer's class usage. </p> |
| |
| </BODY> |
| </HTML> |