{"id":448,"date":"2009-01-10T08:42:57","date_gmt":"2009-01-10T07:42:57","guid":{"rendered":"http:\/\/www.sahits.ch\/blog\/?p=448"},"modified":"2017-12-24T21:42:28","modified_gmt":"2017-12-24T20:42:28","slug":"adding-context-sensitive-help-to-your-plug-in","status":"publish","type":"post","link":"http:\/\/sahits.ch\/blog\/blog\/2009\/01\/10\/adding-context-sensitive-help-to-your-plug-in\/","title":{"rendered":"Adding context sensitive Help to your Plug-in"},"content":{"rendered":"<p>For my <a href=\"http:\/\/sourceforge.net\/projects\/codegenjava\/\">Code generation plug-in<\/a> I wanted to add some context sensitive help. Looking for any hints I only found a quick description at <a href=\"http:\/\/www.macrobug.com\/blog\/2007\/09\/27\/displaying-help-in-wizards-in-eclipse\/\">Macrobug&#8217;s<\/a> that dates back in autumn 2007 when Eclipse 3.3 (Europa) was the current platform. Following these steps I could not produce any meaningful results. Therefore I figured it out on my own and present my solution here for anyone interested.<br \/>\n<!--more--><br \/>\nTo reduce the the problem to its most simplest I created a new plug-in to test this out: New->Other->Plug-in-Project. Fill in the required values with some sensible data. On the third page select the &#8222;Plug-in with multi-page editor&#8220;. Then you can hit finish since all we need is a wizard with one page where we can call the context sensitive help.<br \/>\nIn the project create a new folder and name it &#8222;html&#8220;. Create some html files in this folder (ie. help1.htm,help2.htm,&#8230;) that contain the contents of your context help. Then create an XML file under your project root (ie. contextHelp.xml) and add the contexts to it:<br \/>\n<a href=\"http:\/\/www.sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/contexthelp.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/contexthelp.gif\" alt=\"contexthelp\" title=\"contexthelp\" width=\"473\" height=\"102\" class=\"alignleft size-full wp-image-454\" srcset=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/contexthelp.gif 473w, http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/contexthelp-300x64.gif 300w\" sizes=\"auto, (max-width: 473px) 85vw, 473px\" \/><\/a><br \/>\n<a name=\"contextID\">Note the id &#8222;firsthelp&#8220;<\/a>. The href points to your corresponding html file with a relative path. You can add several topic elements. Now you have to make your context sensitive known in the plug-in through the extension point <a href=\"http:\/\/help.eclipse.org\/ganymede\/topic\/org.eclipse.platform.doc.isv\/reference\/extension-points\/org_eclipse_help_contexts.html\" target=\"_blank\">org.eclipse.help.contexts<\/a>. To do that add the following lines to the plugin.xml:<br \/>\n<a href=\"http:\/\/www.sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/plugin.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/plugin.gif\" alt=\"plugin\" title=\"plugin\" width=\"577\" height=\"137\" class=\"alignleft size-full wp-image-456\" srcset=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/plugin.gif 577w, http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/plugin-300x71.gif 300w\" sizes=\"auto, (max-width: 577px) 85vw, 577px\" \/><\/a><br \/>\nThe file has the path to your XML file you just defined. Note that the plugin attribute denotes this plug-in. It can define some other plug-in if your XML context help file is located in another bundle\/plug-in.<br \/>\nWhat we have done until now is generating some artefacts that are not needed &#8211; yet. So we have to tie up all the loose ends. In effect this is done with essentially one line of code. But to understand how all this works let&#8217;s take a closer look on how the context sensitive help works.<br \/>\nThe context is defined by a unique ID the context-ID. In your wizard this context-ID is set as a data attribute on the widget of the shell. To understand why this is important lets take a look at the suggested solution by <a href=\"http:\/\/www.macrobug.com\/blog\/2007\/09\/27\/displaying-help-in-wizards-in-eclipse\/\">Macrobugs<\/a>:<\/p>\n<pre>\r\nPlatformUI.getWorkbench().getHelpSystem.displayHelp(context-ID);\r\n<\/pre>\n<p>What happens here is that the help context is created with your supplied context-ID and afterwards a second time with the context-ID defined in the shell that overrides your context. Your call stems from the direct call in the method performHelp, the second is executed based on the registered event listener. For all more interested in the details are referred to the inner class WorkbenchHelpListener in org.eclipse.ui.internal.help.WorkbenchHelp and there have a look at the method helpRequested(Event).<br \/>\nWith that said all we have to is supply the widget with our context-ID. For that we override the method performHelp in our WizardPage class:<\/p>\n<pre>\r\n\/**\r\n * Set the right help key for the context sensitive help\r\n *\/\r\npublic void performHelp() {\r\n\t\/\/ (WorkbenchHelpSystem.HELP_KEY = \"org.eclipse.ui.help\"\r\n\tgetShell().setData(WorkbenchHelpSystem.HELP_KEY, \"ch.sahits.tutorial.help.firsthelp\");\r\n}\r\n<\/pre>\n<p>The HELP_KEY is a constant in an internal class. This will generate you a warning for discouraged access, alternatively you can use the value of the constant: &#8222;org.eclipse.ui.help&#8220;. The important part is the second argument of the setData method, the value. This is your context-ID. This context-ID is put together from the plug-in ID of your plug-in where you defined your extension (in our case the very same plug-in) and the <a href=\"#contextID\">id<\/a> of the context divided by a point.<br \/>\nAn example plug-in that followed basically the same steps described here can be <a href='http:\/\/www.sahits.ch\/blog\/wp-content\/uploads\/2009\/01\/wizardhelp.zip'>obtained<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my Code generation plug-in I wanted to add some context sensitive help. Looking for any hints I only found a quick description at Macrobug&#8217;s that dates back in autumn 2007 when Eclipse 3.3 (Europa) was the current platform. Following these steps I could not produce any meaningful results. Therefore I figured it out on &hellip; <a href=\"http:\/\/sahits.ch\/blog\/blog\/2009\/01\/10\/adding-context-sensitive-help-to-your-plug-in\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eAdding context sensitive Help to your Plug-in\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,7,6],"tags":[304,301,12,300,25,13],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-eclipse","category-java","category-programmieren","tag-eclipse","tag-java","tag-plugin","tag-programmieren","tag-tutorial","tag-wizard"],"_links":{"self":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":20,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":473,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions\/473"}],"wp:attachment":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}