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

Parent Directory Parent Directory | Revision Log 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 &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 :     <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 :     -&gt; Runtime overview -&gt; 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> &lt;extension
37 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
38 :     &lt;content-type
39 :     id=&lt;id&gt;
40 :     name=&lt;name&gt;
41 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;&gt;
42 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
43 :     &lt;parameter name=&quot;element&quot; value=<em>tagValue</em> /&gt;
44 :     &lt;/describer&gt;
45 :     &lt;/content-type&gt;
46 :     &lt;/extension&gt;</pre>
47 :     or
48 :     <pre> &lt;extension
49 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
50 :     &lt;content-type
51 :     id=&lt;id&gt;
52 :     name=&lt;name&gt;
53 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;&gt;
54 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
55 :     &lt;parameter name=&quot;dtd&quot; value=<em>dtdValue</em> /&gt;
56 :     &lt;/describer&gt;
57 :     &lt;/content-type&gt;
58 :     &lt;/extension&gt;</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> &lt;extension
68 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
69 :     &lt;content-type
70 :     id=&quot;topElementContentType&quot;
71 :     name=&quot;Tests top-level element recognition&quot;
72 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;
73 :     priority=&quot;high&quot;&gt;
74 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
75 :     &lt;parameter name=&quot;element&quot; value=&quot;myTag&quot; /&gt;
76 :     &lt;/describer&gt;
77 :     &lt;/content-type&gt;
78 :     &lt;/extension&gt;
79 :    
80 :     &lt;extension
81 :     point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
82 :     &lt;content-type
83 :     id=&quot;dtdContentType&quot;
84 :     name=&quot;Tests dtd element recognition&quot;
85 :     base-type=&quot;org.eclipse.core.runtime.xml&quot;
86 :     priority=&quot;high&quot;&gt;
87 :     &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
88 :     &lt;parameter name=&quot;dtd&quot; value=&quot;myDTD.xml&quot; /&gt;
89 :     &lt;/describer&gt;
90 :     &lt;/content-type&gt;
91 :     &lt;/extension&gt;
92 :     </pre>
93 :     <pre> &lt;extension point=&quot;org.eclipse.ui.popupMenus&quot;&gt;
94 :     &lt;objectContribution
95 :     id=&quot;org.eclipse.ui.examples.objectContributions&quot;
96 :     objectClass=&quot;org.eclipse.core.resources.IFile&quot;
97 :     nameFilter=&quot;*.xml&quot;&gt;
98 :     &lt;visibility&gt;
99 :     &lt;or&gt;
100 :     &lt;objectState
101 :     name=&quot;contentTypeId&quot;
102 :     value=&quot;org.eclipse.ui.examples.topElementContentType&quot;/&gt;
103 :     &lt;objectState
104 :     name=&quot;contentTypeId&quot;
105 :     value=&quot;org.eclipse.ui.examples.dtdContentType&quot;/&gt;
106 :     &lt;/or&gt;
107 :     &lt;/visibility&gt;
108 :     &lt;action id=&quot;org.eclipse.ui.examples.objectContributions.action1&quot;
109 :     label=&quot;%PopupMenus.action&quot;
110 :     icon=&quot;icons/ctool16/openbrwsr.gif&quot;
111 :     menubarPath=&quot;additions&quot;
112 :     class=&quot;org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate&quot;
113 :     enablesFor=&quot;1&quot;&gt;
114 :     &lt;/action&gt;
115 :     &lt;/objectContribution&gt;
116 :     &lt;/extension&gt;</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>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
122 :     &lt;myTag
123 :     id=&quot;org.eclipse.ui.workbench&quot;
124 :     name=&quot;%pluginName&quot;
125 :     version=&quot;3.0.0&quot;
126 :     provider-name=&quot;%providerName&quot;
127 :     class=&quot;org.eclipse.ui.internal.WorkbenchPlugin&quot;&gt;
128 :     &lt;/myTag&gt;</pre>
129 :     <p>Or</p>
130 :     <pre>
131 :     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
132 :     &lt;!DOCTYPE Book SYSTEM &quot;myDTD.xml&quot;&gt;
133 :     &lt;fragment
134 :     id=&quot;org.eclipse.ui.workbench&quot;
135 :     name=&quot;%pluginName&quot;
136 :     version=&quot;3.0.0&quot;
137 :     provider-name=&quot;%providerName&quot;
138 :     class=&quot;org.eclipse.ui.internal.WorkbenchPlugin&quot;&gt;
139 :     &lt;runtime&gt;
140 :     &lt;library name=&quot;workbench.jar&quot;&gt;
141 :     &lt;export name=&quot;*&quot;/&gt;
142 :     &lt;packages prefixes=&quot;org.eclipse.ui, org.eclipse.jface&quot;/&gt;
143 :     &lt;/library&gt;
144 :     &lt;/runtime&gt;
145 : dwilson 1.2 &lt;/fragment&gt;
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 &quot;signature&quot;, &quot;offset&quot; and &quot;required&quot;
153 :     instead of &quot;element&quot; or &quot;dtd&quot;. The Javadoc for BinarySignatureDescriber
154 :     gives complete details on this content describer's class usage.
155 : tod 1.1 </body>
156 :     </html>