platform-ui-home/object-aware-contributions/objCont.htm
Parent Directory
|
Revision Log
Revision 1.2 -
(download)
(as text)
(annotate)
Fri Jun 11 15:12:05 2004 UTC (5 years, 5 months ago) by dwilson
Branch: MAIN
Changes since 1.1: +105 -58 lines
Fri Jun 11 15:12:05 2004 UTC (5 years, 5 months ago) by dwilson
Branch: MAIN
Changes since 1.1: +105 -58 lines
Update for new format for object contributions
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Content Sensitive Object Contributions</h1>
<p><em>Last modified June 10, 2004</em></p>
<p>Context menus for some applications have previously only been able to exclude
some menu options based on peripheral information known about the resources
selected (the number of resources selected, the physical name of the file, the
type of the resource, etc.). There are some cases where a restricted amount
of information known about the contents of the resource would significantly
reduce unusable options from the menus. Consider XML files as a good example
of where such information would be useful. There are numerous situations where
an action is applicable for one type of XML file but not another. For example,
some XML files contain Ant scripts. The action "Run Ant..." makes
sense in its context menu. But this action is not applicable to an XML file
used to define a plug-in.</p>
<p>The notion of a content type has been added to Eclipse. A new extension point,
org.eclipse.core.runtime.contentTypes allows plug-ins to contribute to the Platform
content type catalog. Further, classes called Content Type Describers have been
added.</p>
<p>Initially, two content describers will be supported: BinarySignatureDescriber
and XMLRootElementContentDescriber. Eclipse developers may create their own
content describers. The Platform Plug-in Developer Guide (Programmer's Guide
-> Runtime overview -> Content types) describes this in more detail.</p>
<h3>XMLRootElementContentDescriber</h3>
<p>It will now be possible to define object contributions which are specific to
an XML file with a given top level tag or which specify 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>
<p><font size="3">where <em>tagValue</em> represents the name of the top level
tag to match and</font></p>
<p><font size="3"><em>dtdValue</em> represents the name of the DTD as seen in
the XML file.</font></p>
</blockquote>
<p><font size="3">Consider the following object contribution in a plugin.xml file:</font></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.gif"
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>
<p>Or</p>
<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>
The BinarySignatureDescriber is a content describer to detect 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
gives complete details on this content describer's class usage.
</body>
</html>
| help@eclipse.org | ViewVC Help |
| Powered by ViewVC 1.0.3 |
