blob: 4f7ef840c44df091e7d590df7159ebedb349b3b9 [file] [log] [blame]
<!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 &gt; Runtime overview &gt; 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> &lt;extension
point="org.eclipse.core.runtime.contentTypes"&gt;
&lt;content-type
id=&lt;id&gt;
name=&lt;name&gt;
base-type="org.eclipse.core.runtime.xml"&gt;
&lt;describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"&gt;
&lt;parameter name="element" value=<EM>tagValue</EM> /&gt;
&lt;/describer&gt;
&lt;/content-type&gt;
&lt;/extension&gt;</PRE>or <PRE> &lt;extension
point="org.eclipse.core.runtime.contentTypes"&gt;
&lt;content-type
id=&lt;id&gt;
name=&lt;name&gt;
base-type="org.eclipse.core.runtime.xml"&gt;
&lt;describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"&gt;
&lt;parameter name="dtd" value=<EM>dtdValue</EM> /&gt;
&lt;/describer&gt;
&lt;/content-type&gt;
&lt;/extension&gt;</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> &lt;extension
point="org.eclipse.core.runtime.contentTypes"&gt;
&lt;content-type
id="topElementContentType"
name="Tests top-level element recognition"
base-type="org.eclipse.core.runtime.xml"
priority="high"&gt;
&lt;describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"&gt;
&lt;parameter name="element" value="myTag" /&gt;
&lt;/describer&gt;
&lt;/content-type&gt;
&lt;/extension&gt;
&lt;extension
point="org.eclipse.core.runtime.contentTypes"&gt;
&lt;content-type
id="dtdContentType"
name="Tests dtd element recognition"
base-type="org.eclipse.core.runtime.xml"
priority="high"&gt;
&lt;describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"&gt;
&lt;parameter name="dtd" value="myDTD.xml" /&gt;
&lt;/describer&gt;
&lt;/content-type&gt;
&lt;/extension&gt;
</PRE><PRE> &lt;extension point="org.eclipse.ui.popupMenus"&gt;
&lt;objectContribution
id="org.eclipse.ui.examples.objectContributions"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.xml"&gt;
&lt;visibility&gt;
&lt;or&gt;
&lt;objectState
name="contentTypeId"
value="org.eclipse.ui.examples.topElementContentType"/&gt;
&lt;objectState
name="contentTypeId"
value="org.eclipse.ui.examples.dtdContentType"/&gt;
&lt;/or&gt;
&lt;/visibility&gt;
&lt;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"&gt;
&lt;/action&gt;
&lt;/objectContribution&gt;
&lt;/extension&gt;</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>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;myTag
id="org.eclipse.ui.workbench"
name="%pluginName"
version="3.0.0"
provider-name="%providerName"
class="org.eclipse.ui.internal.WorkbenchPlugin"&gt;
&lt;/myTag&gt;</PRE>
</BLOCKQUOTE>
<p>or</p>
<BLOCKQUOTE>
<PRE>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Book SYSTEM "myDTD.xml"&gt;
&lt;fragment
id="org.eclipse.ui.workbench"
name="%pluginName"
version="3.0.0"
provider-name="%providerName"
class="org.eclipse.ui.internal.WorkbenchPlugin"&gt;
&lt;runtime&gt;
&lt;library name="workbench.jar"&gt;
&lt;export name="*"/&gt;
&lt;packages prefixes="org.eclipse.ui, org.eclipse.jface"/&gt;
&lt;/library&gt;
&lt;/runtime&gt;
&lt;/fragment&gt;
</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>