platform-ui-home/object-aware-contributions/objCont.htm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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.3 <p><em>Last modified June 14, 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 &quot;Run Ant...&quot; 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 : dwilson 1.3 <p>For developers providing their own content types, two customizable, built-in
27 :     content type describers are available: BinarySignatureDescriber (for binary
28 :     content types) and XMLRootElementContentDescriber (for text, XML based content
29 :     types). Plug-in providers may create their own content describers. The Platform
30 :     Plug-in Developer Guide (Programmer's Guide -&gt; Runtime overview -&gt; Content
31 :     types) describes this in more detail.</p>
32 : dwilson 1.2 <h3>XMLRootElementContentDescriber</h3>
33 : tod 1.1 <p>It will now be possible to define object contributions which are specific to
34 : dwilson 1.2 an XML file with a given top level tag or which specify a given DTD. To do this,
35 :     define an extension to the org.eclipse.core.runtime.contentTypes extension point
36 :     with a describer class of XMLRootElementContentDescriber and parameters indicating
37 :     the top level tag name or the dtd name as follows:</p>
38 :     <pre> &lt;extension
39 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
40 :     &lt;content-type
41 :     id=&lt;id&gt;
42 :     name=&lt;name&gt;
43 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;&gt;
44 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
45 :     &lt;parameter name=&quot;element&quot; value=<em>tagValue</em> /&gt;
46 :     &lt;/describer&gt;
47 :     &lt;/content-type&gt;
48 :     &lt;/extension&gt;</pre>
49 :     or
50 :     <pre> &lt;extension
51 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
52 :     &lt;content-type
53 :     id=&lt;id&gt;
54 :     name=&lt;name&gt;
55 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;&gt;
56 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
57 :     &lt;parameter name=&quot;dtd&quot; value=<em>dtdValue</em> /&gt;
58 :     &lt;/describer&gt;
59 :     &lt;/content-type&gt;
60 :     &lt;/extension&gt;</pre>
61 :    
62 : tod 1.1 <blockquote>
63 :     <p><font size="3">where <em>tagValue</em> represents the name of the top level
64 :     tag to match and</font></p>
65 :     <p><font size="3"><em>dtdValue</em> represents the name of the DTD as seen in
66 :     the XML file.</font></p>
67 :     </blockquote>
68 :     <p><font size="3">Consider the following object contribution in a plugin.xml file:</font></p>
69 : dwilson 1.2 <pre> &lt;extension
70 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
71 :     &lt;content-type
72 :     id=&quot;topElementContentType&quot;
73 :     name=&quot;Tests top-level element recognition&quot;
74 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;
75 :     priority=&quot;high&quot;&gt;
76 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
77 :     &lt;parameter name=&quot;element&quot; value=&quot;myTag&quot; /&gt;
78 :     &lt;/describer&gt;
79 :     &lt;/content-type&gt;
80 :     &lt;/extension&gt;
81 :    
82 :     &lt;extension
83 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
84 :     &lt;content-type
85 :     id=&quot;dtdContentType&quot;
86 :     name=&quot;Tests dtd element recognition&quot;
87 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;
88 :     priority=&quot;high&quot;&gt;
89 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
90 :     &lt;parameter name=&quot;dtd&quot; value=&quot;myDTD.xml&quot; /&gt;
91 :     &lt;/describer&gt;
92 :     &lt;/content-type&gt;
93 :     &lt;/extension&gt;
94 :     </pre>
95 :     <pre> &lt;extension point=&quot;org.eclipse.ui.popupMenus&quot;&gt;
96 :     &lt;objectContribution
97 :     id=&quot;org.eclipse.ui.examples.objectContributions&quot;
98 :     objectClass=&quot;org.eclipse.core.resources.IFile&quot;
99 :     nameFilter=&quot;*.xml&quot;&gt;
100 :     &lt;visibility&gt;
101 :     &lt;or&gt;
102 :     &lt;objectState
103 :     name=&quot;contentTypeId&quot;
104 :     value=&quot;org.eclipse.ui.examples.topElementContentType&quot;/&gt;
105 :     &lt;objectState
106 :     name=&quot;contentTypeId&quot;
107 :     value=&quot;org.eclipse.ui.examples.dtdContentType&quot;/&gt;
108 :     &lt;/or&gt;
109 :     &lt;/visibility&gt;
110 :     &lt;action id=&quot;org.eclipse.ui.examples.objectContributions.action1&quot;
111 :     label=&quot;%PopupMenus.action&quot;
112 :     icon=&quot;icons/ctool16/openbrwsr.gif&quot;
113 :     menubarPath=&quot;additions&quot;
114 :     class=&quot;org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate&quot;
115 :     enablesFor=&quot;1&quot;&gt;
116 :     &lt;/action&gt;
117 :     &lt;/objectContribution&gt;
118 :     &lt;/extension&gt;</pre>
119 : tod 1.1 <p>This will make action1 visible for any IFile with a name matching *.xml provided
120 :     it contains myTag as the top level XML tag or it uses the DTD called myDTD.xml.
121 :     So the following XML files will match:</p>
122 : dwilson 1.2 <blockquote>
123 : tod 1.1 <pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
124 :     &lt;myTag
125 :     id=&quot;org.eclipse.ui.workbench&quot;
126 :     name=&quot;%pluginName&quot;
127 :     version=&quot;3.0.0&quot;
128 :     provider-name=&quot;%providerName&quot;
129 :     class=&quot;org.eclipse.ui.internal.WorkbenchPlugin&quot;&gt;
130 :     &lt;/myTag&gt;</pre>
131 :     <p>Or</p>
132 :     <pre>
133 :     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
134 :     &lt;!DOCTYPE Book SYSTEM &quot;myDTD.xml&quot;&gt;
135 :     &lt;fragment
136 :     id=&quot;org.eclipse.ui.workbench&quot;
137 :     name=&quot;%pluginName&quot;
138 :     version=&quot;3.0.0&quot;
139 :     provider-name=&quot;%providerName&quot;
140 :     class=&quot;org.eclipse.ui.internal.WorkbenchPlugin&quot;&gt;
141 :     &lt;runtime&gt;
142 :     &lt;library name=&quot;workbench.jar&quot;&gt;
143 :     &lt;export name=&quot;*&quot;/&gt;
144 :     &lt;packages prefixes=&quot;org.eclipse.ui, org.eclipse.jface&quot;/&gt;
145 :     &lt;/library&gt;
146 :     &lt;/runtime&gt;
147 : dwilson 1.2 &lt;/fragment&gt;
148 :     </pre>
149 : tod 1.1 </blockquote>
150 : dwilson 1.2 <h3>BinarySignatureDescriber</h3>
151 :     The BinarySignatureDescriber is a content describer to detect a specified binary
152 :     'signature' at a given offset within a file. This describer is used in the same
153 :     fashion as the XMLRootElementContentDescriber with the exception that it takes
154 :     parameters &quot;signature&quot;, &quot;offset&quot; and &quot;required&quot;
155 :     instead of &quot;element&quot; or &quot;dtd&quot;. The Javadoc for BinarySignatureDescriber
156 :     gives complete details on this content describer's class usage.
157 : tod 1.1 </body>
158 :     </html>