platform-ui-home/object-aware-contributions/objCont.htm
Parent Directory
|
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 "Run Ant..." 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"><objectState name="xmlFirstTag" value="<em>tagValue</em>"/></font></p> | ||
| 25 : | <p><font size="3"><objectState name="xmlDTDName" value="<em>dtdValue</em>"\></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> <extension point = "org.eclipse.ui.popupMenus"> | ||
| 34 : | <objectContribution | ||
| 35 : | id="org.eclipse.ui.examples.objectContributions" | ||
| 36 : | objectClass="org.eclipse.core.resources.IFile" | ||
| 37 : | nameFilter="*.xml"> | ||
| 38 : | <visibility> | ||
| 39 : | <or> | ||
| 40 : | <objectState name="xmlFirstTag" value="myTag"/> | ||
| 41 : | <objectState name="xmlDTDName" value="myDTD.xml"/> | ||
| 42 : | </or> | ||
| 43 : | </visibility> | ||
| 44 : | <action id="org.eclipse.ui.examples.objectContributions.action1" | ||
| 45 : | label="%PopupMenus.action" | ||
| 46 : | icon="icons/ctool16/openbrwsr.gif" | ||
| 47 : | menubarPath="additions" | ||
| 48 : | class="org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate" | ||
| 49 : | enablesFor="1"> | ||
| 50 : | </action> | ||
| 51 : | </objectContribution> | ||
| 52 : | </extension></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><?xml version="1.0" encoding="UTF-8"?> | ||
| 58 : | <myTag | ||
| 59 : | id="org.eclipse.ui.workbench" | ||
| 60 : | name="%pluginName" | ||
| 61 : | version="3.0.0" | ||
| 62 : | provider-name="%providerName" | ||
| 63 : | class="org.eclipse.ui.internal.WorkbenchPlugin"> | ||
| 64 : | </myTag></pre> | ||
| 65 : | <p>Or</p> | ||
| 66 : | <pre> | ||
| 67 : | <?xml version="1.0" encoding="UTF-8"?> | ||
| 68 : | <!DOCTYPE Book SYSTEM "myDTD.xml"> | ||
| 69 : | <fragment | ||
| 70 : | id="org.eclipse.ui.workbench" | ||
| 71 : | name="%pluginName" | ||
| 72 : | version="3.0.0" | ||
| 73 : | provider-name="%providerName" | ||
| 74 : | class="org.eclipse.ui.internal.WorkbenchPlugin"> | ||
| 75 : | <runtime> | ||
| 76 : | <library name="workbench.jar"> | ||
| 77 : | <export name="*"/> | ||
| 78 : | <packages prefixes="org.eclipse.ui, org.eclipse.jface"/> | ||
| 79 : | </library> | ||
| 80 : | </runtime> | ||
| 81 : | </fragment></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 "xmlLastMod" 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, "xmlFirstTag" | ||
| 91 : | and "xmlDTDName" 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 "Run Ant..." | ||
| 106 : | item</p> | ||
| 107 : | <p>45024 - JAXP and old Xerces functionality</p> | ||
| 108 : | </body> | ||
| 109 : | </html> |
| help@eclipse.org | ViewVC Help |
| Powered by ViewVC 1.0.3 |
