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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (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 :     <p><em>Last modified December 10, 2003</em></p>
11 :     <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 :     of information, known about the contents of the resource would significantly
16 :     reduce unusable options from the menus. The first area targeted is that of XML
17 :     files. There are numerous situations where an action is applicable for one type
18 :     of XML file but not another. For example, some XML files contain Ant scripts.
19 :     The action &quot;Run Ant...&quot; makes sense in its context menu. But this
20 :     action is not applicable to an XML file used to define a plug-in.</p>
21 :     <p>It will now be possible to define object contributions which are specific to
22 :     an XML file with a given top level tag or which specify a given DTD. The objectState
23 :     key of an ActionExpression will be used to specify these values as follows:</p>
24 :     <p><font size="3">&lt;objectState name=&quot;xmlFirstTag&quot; value=&quot;<em>tagValue</em>&quot;/&gt;</font></p>
25 :     <p><font size="3">&lt;objectState name=&quot;xmlDTDName&quot; value=&quot;<em>dtdValue</em>&quot;\&gt;</font></p>
26 :     <blockquote>
27 :     <p><font size="3">where <em>tagValue</em> represents the name of the top level
28 :     tag to match and</font></p>
29 :     <p><font size="3"><em>dtdValue</em> represents the name of the DTD as seen in
30 :     the XML file.</font></p>
31 :     </blockquote>
32 :     <p><font size="3">Consider the following object contribution in a plugin.xml file:</font></p>
33 :     <pre> &lt;extension point = &quot;org.eclipse.ui.popupMenus&quot;&gt;
34 :     &lt;objectContribution
35 :     id=&quot;org.eclipse.ui.examples.objectContributions&quot;
36 :     objectClass=&quot;org.eclipse.core.resources.IFile&quot;
37 :     nameFilter=&quot;*.xml&quot;&gt;
38 :     &lt;visibility&gt;
39 :     &lt;or&gt;
40 :     &lt;objectState name=&quot;xmlFirstTag&quot; value=&quot;myTag&quot;/&gt;
41 :     &lt;objectState name=&quot;xmlDTDName&quot; value=&quot;myDTD.xml&quot;/&gt;
42 :     &lt;/or&gt;
43 :     &lt;/visibility&gt;
44 :     &lt;action id=&quot;org.eclipse.ui.examples.objectContributions.action1&quot;
45 :     label=&quot;%PopupMenus.action&quot;
46 :     icon=&quot;icons/ctool16/openbrwsr.gif&quot;
47 :     menubarPath=&quot;additions&quot;
48 :     class=&quot;org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate&quot;
49 :     enablesFor=&quot;1&quot;&gt;
50 :     &lt;/action&gt;
51 :     &lt;/objectContribution&gt;
52 :     &lt;/extension&gt;</pre>
53 :     <p>This will make action1 visible for any IFile with a name matching *.xml provided
54 :     it contains myTag as the top level XML tag or it uses the DTD called myDTD.xml.
55 :     So the following XML files will match:</p>
56 :     <blockquote>
57 :     <pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
58 :     &lt;myTag
59 :     id=&quot;org.eclipse.ui.workbench&quot;
60 :     name=&quot;%pluginName&quot;
61 :     version=&quot;3.0.0&quot;
62 :     provider-name=&quot;%providerName&quot;
63 :     class=&quot;org.eclipse.ui.internal.WorkbenchPlugin&quot;&gt;
64 :     &lt;/myTag&gt;</pre>
65 :     <p>Or</p>
66 :     <pre>
67 :     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
68 :     &lt;!DOCTYPE Book SYSTEM &quot;myDTD.xml&quot;&gt;
69 :     &lt;fragment
70 :     id=&quot;org.eclipse.ui.workbench&quot;
71 :     name=&quot;%pluginName&quot;
72 :     version=&quot;3.0.0&quot;
73 :     provider-name=&quot;%providerName&quot;
74 :     class=&quot;org.eclipse.ui.internal.WorkbenchPlugin&quot;&gt;
75 :     &lt;runtime&gt;
76 :     &lt;library name=&quot;workbench.jar&quot;&gt;
77 :     &lt;export name=&quot;*&quot;/&gt;
78 :     &lt;packages prefixes=&quot;org.eclipse.ui, org.eclipse.jface&quot;/&gt;
79 :     &lt;/library&gt;
80 :     &lt;/runtime&gt;
81 :     &lt;/fragment&gt;</pre>
82 :     </blockquote>
83 :    
84 :     <p>A new parser, called PropertyParser, will be used to collect this information.
85 :     This parser will be a SAX based parser as we don't necessarily need to parse
86 :     the entire file.</p>
87 :     <p>New persistent properties will be stored for any file that requires this information.
88 :     First, a property called &quot;xmlLastMod&quot; will be used to store the last
89 :     modified time of the file (as know by IResource). This will ensure that we don't
90 :     re-parse this file if it isn't necessary. Two other properties, &quot;xmlFirstTag&quot;
91 :     and &quot;xmlDTDName&quot; will be used to store the name of the root level
92 :     tag and a DTD file (if specified) respectively. Note that if the parser is called
93 :     for either one of these, both will be stored (if they exist). The structure
94 :     of XML dictates that the DTD specification, if it exists, must occur before
95 :     the root level tag. As a result, once PropertyParser has parsed to the root
96 :     level tag, it's work is done. At this point, all other parsing is stopped.</p>
97 :     <p>Any exceptions thrown by the parser are output to the .log file. PropertyParser
98 :     will explicitly test for an empty file as many SAX parsers will throw an exception
99 :     if they encounter an XML file without a root level tag.</p>
100 :     <p>It should be noted that if a DTD is specified in a file, Crimson, a commonly
101 :     used SAX parser in Eclipse, requires that the DTD file exists and is readable.
102 :     If this is not the case, a SAXException will be thrown. The PropertyParser does
103 :     not require the DTD to be present, but the underlying parser often does.</p>
104 :     <p>Related Bug Reports</p>
105 :     <p>33018 - [Contributions] plugin.xml context menu should not have &quot;Run Ant...&quot;
106 :     item</p>
107 :     <p>45024 - JAXP and old Xerces functionality</p>
108 :     </body>
109 :     </html>