platform-ui-home/object-aware-contributions/objCont.htm
Parent Directory
|
Revision Log
Revision 1.2 - (view) (download) (as text)
| 1 : | tod | 1.1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 : | <html> | ||
| 3 : | <head> | ||
| 4 : | <title>Untitled Document</title> | ||
| 5 : | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | ||
| 6 : | </head> | ||
| 7 : | |||
| 8 : | <body> | ||
| 9 : | <h1>Content Sensitive Object Contributions</h1> | ||
| 10 : | dwilson | 1.2 | <p><em>Last modified June 10, 2004</em></p> |
| 11 : | tod | 1.1 | <p>Context menus for some applications have previously only been able to exclude |
| 12 : | some menu options based on peripheral information known about the resources | ||
| 13 : | selected (the number of resources selected, the physical name of the file, the | ||
| 14 : | type of the resource, etc.). There are some cases where a restricted amount | ||
| 15 : | dwilson | 1.2 | of information known about the contents of the resource would significantly |
| 16 : | reduce unusable options from the menus. Consider XML files as a good example | ||
| 17 : | of where such information would be useful. There are numerous situations where | ||
| 18 : | an action is applicable for one type of XML file but not another. For example, | ||
| 19 : | some XML files contain Ant scripts. The action "Run Ant..." makes | ||
| 20 : | sense in its context menu. But this action is not applicable to an XML file | ||
| 21 : | used to define a plug-in.</p> | ||
| 22 : | <p>The notion of a content type has been added to Eclipse. A new extension point, | ||
| 23 : | org.eclipse.core.runtime.contentTypes allows plug-ins to contribute to the Platform | ||
| 24 : | content type catalog. Further, classes called Content Type Describers have been | ||
| 25 : | added.</p> | ||
| 26 : | <p>Initially, two content describers will be supported: BinarySignatureDescriber | ||
| 27 : | and XMLRootElementContentDescriber. Eclipse developers may create their own | ||
| 28 : | content describers. The Platform Plug-in Developer Guide (Programmer's Guide | ||
| 29 : | -> Runtime overview -> Content types) describes this in more detail.</p> | ||
| 30 : | <h3>XMLRootElementContentDescriber</h3> | ||
| 31 : | tod | 1.1 | <p>It will now be possible to define object contributions which are specific to |
| 32 : | dwilson | 1.2 | an XML file with a given top level tag or which specify a given DTD. To do this, |
| 33 : | define an extension to the org.eclipse.core.runtime.contentTypes extension point | ||
| 34 : | with a describer class of XMLRootElementContentDescriber and parameters indicating | ||
| 35 : | the top level tag name or the dtd name as follows:</p> | ||
| 36 : | <pre> <extension | ||
| 37 : | point="org.eclipse.core.runtime.contentTypes"> | ||
| 38 : | <content-type | ||
| 39 : | id=<id> | ||
| 40 : | name=<name> | ||
| 41 : | base-type="org.eclipse.core.runtime.xml"> | ||
| 42 : | <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> | ||
| 43 : | <parameter name="element" value=<em>tagValue</em> /> | ||
| 44 : | </describer> | ||
| 45 : | </content-type> | ||
| 46 : | </extension></pre> | ||
| 47 : | or | ||
| 48 : | <pre> <extension | ||
| 49 : | point="org.eclipse.core.runtime.contentTypes"> | ||
| 50 : | <content-type | ||
| 51 : | id=<id> | ||
| 52 : | name=<name> | ||
| 53 : | base-type="org.eclipse.core.runtime.xml"> | ||
| 54 : | <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> | ||
| 55 : | <parameter name="dtd" value=<em>dtdValue</em> /> | ||
| 56 : | </describer> | ||
| 57 : | </content-type> | ||
| 58 : | </extension></pre> | ||
| 59 : | |||
| 60 : | tod | 1.1 | <blockquote> |
| 61 : | <p><font size="3">where <em>tagValue</em> represents the name of the top level | ||
| 62 : | tag to match and</font></p> | ||
| 63 : | <p><font size="3"><em>dtdValue</em> represents the name of the DTD as seen in | ||
| 64 : | the XML file.</font></p> | ||
| 65 : | </blockquote> | ||
| 66 : | <p><font size="3">Consider the following object contribution in a plugin.xml file:</font></p> | ||
| 67 : | dwilson | 1.2 | <pre> <extension |
| 68 : | point="org.eclipse.core.runtime.contentTypes"> | ||
| 69 : | <content-type | ||
| 70 : | id="topElementContentType" | ||
| 71 : | name="Tests top-level element recognition" | ||
| 72 : | base-type="org.eclipse.core.runtime.xml" | ||
| 73 : | priority="high"> | ||
| 74 : | <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> | ||
| 75 : | <parameter name="element" value="myTag" /> | ||
| 76 : | </describer> | ||
| 77 : | </content-type> | ||
| 78 : | </extension> | ||
| 79 : | |||
| 80 : | <extension | ||
| 81 : | point="org.eclipse.core.runtime.contentTypes"> | ||
| 82 : | <content-type | ||
| 83 : | id="dtdContentType" | ||
| 84 : | name="Tests dtd element recognition" | ||
| 85 : | base-type="org.eclipse.core.runtime.xml" | ||
| 86 : | priority="high"> | ||
| 87 : | <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> | ||
| 88 : | <parameter name="dtd" value="myDTD.xml" /> | ||
| 89 : | </describer> | ||
| 90 : | </content-type> | ||
| 91 : | </extension> | ||
| 92 : | </pre> | ||
| 93 : | <pre> <extension point="org.eclipse.ui.popupMenus"> | ||
| 94 : | <objectContribution | ||
| 95 : | id="org.eclipse.ui.examples.objectContributions" | ||
| 96 : | objectClass="org.eclipse.core.resources.IFile" | ||
| 97 : | nameFilter="*.xml"> | ||
| 98 : | <visibility> | ||
| 99 : | <or> | ||
| 100 : | <objectState | ||
| 101 : | name="contentTypeId" | ||
| 102 : | value="org.eclipse.ui.examples.topElementContentType"/> | ||
| 103 : | <objectState | ||
| 104 : | name="contentTypeId" | ||
| 105 : | value="org.eclipse.ui.examples.dtdContentType"/> | ||
| 106 : | </or> | ||
| 107 : | </visibility> | ||
| 108 : | <action id="org.eclipse.ui.examples.objectContributions.action1" | ||
| 109 : | label="%PopupMenus.action" | ||
| 110 : | icon="icons/ctool16/openbrwsr.gif" | ||
| 111 : | menubarPath="additions" | ||
| 112 : | class="org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate" | ||
| 113 : | enablesFor="1"> | ||
| 114 : | </action> | ||
| 115 : | </objectContribution> | ||
| 116 : | </extension></pre> | ||
| 117 : | tod | 1.1 | <p>This will make action1 visible for any IFile with a name matching *.xml provided |
| 118 : | it contains myTag as the top level XML tag or it uses the DTD called myDTD.xml. | ||
| 119 : | So the following XML files will match:</p> | ||
| 120 : | dwilson | 1.2 | <blockquote> |
| 121 : | tod | 1.1 | <pre><?xml version="1.0" encoding="UTF-8"?> |
| 122 : | <myTag | ||
| 123 : | id="org.eclipse.ui.workbench" | ||
| 124 : | name="%pluginName" | ||
| 125 : | version="3.0.0" | ||
| 126 : | provider-name="%providerName" | ||
| 127 : | class="org.eclipse.ui.internal.WorkbenchPlugin"> | ||
| 128 : | </myTag></pre> | ||
| 129 : | <p>Or</p> | ||
| 130 : | <pre> | ||
| 131 : | <?xml version="1.0" encoding="UTF-8"?> | ||
| 132 : | <!DOCTYPE Book SYSTEM "myDTD.xml"> | ||
| 133 : | <fragment | ||
| 134 : | id="org.eclipse.ui.workbench" | ||
| 135 : | name="%pluginName" | ||
| 136 : | version="3.0.0" | ||
| 137 : | provider-name="%providerName" | ||
| 138 : | class="org.eclipse.ui.internal.WorkbenchPlugin"> | ||
| 139 : | <runtime> | ||
| 140 : | <library name="workbench.jar"> | ||
| 141 : | <export name="*"/> | ||
| 142 : | <packages prefixes="org.eclipse.ui, org.eclipse.jface"/> | ||
| 143 : | </library> | ||
| 144 : | </runtime> | ||
| 145 : | dwilson | 1.2 | </fragment> |
| 146 : | </pre> | ||
| 147 : | tod | 1.1 | </blockquote> |
| 148 : | dwilson | 1.2 | <h3>BinarySignatureDescriber</h3> |
| 149 : | The BinarySignatureDescriber is a content describer to detect a specified binary | ||
| 150 : | 'signature' at a given offset within a file. This describer is used in the same | ||
| 151 : | fashion as the XMLRootElementContentDescriber with the exception that it takes | ||
| 152 : | parameters "signature", "offset" and "required" | ||
| 153 : | instead of "element" or "dtd". The Javadoc for BinarySignatureDescriber | ||
| 154 : | gives complete details on this content describer's class usage. | ||
| 155 : | tod | 1.1 | </body> |
| 156 : | </html> |
| help@eclipse.org | ViewVC Help |
| Powered by ViewVC 1.0.3 |
