Add "Help button" for Eclipse dialog

By | 1月 17, 2016

See the snapshot below:


To do this, we should use JFace TrayDialog instead of SWT Dialog.The method “setHelpAvailable(boolean helpAvailable)” of TrayDalog indicates whether show the help button on the left-bottom corner on the TrayDilog. So the steps should be:

  1. Make the dialog extends the TrayDialog.
  2. In TrayDialog constructor, call method setHelpAvailable(true) to make help button appear.
  3. Override configureShell(Shell newShell), add PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, contextHelpID); – The help is for the whole dialog, so  should bind the context id with dialog shell.
  4. Show help content for the focus control in the dialog. In the method createDialogArea(Composite parent) of our dialog, associate related controls with their help contents.(like this way: PlatformUI.getWorkbench().getHelpSystem().setHelp(control, contextHelpID);
  5. Last and most important one, the initialize dialog size’s height shall not less than 450. If dialog’s height less than 450, helpInfo will be in a pop-up window instead on the right side tray.

PS. We can use PlatformUI.getWorkbench().getHelpSystem().setHelp(control, contextHelpID) method to add different help content for different controls. Therefor, when we press help-button, it will show the help topic of current focused control. If the focused control don’t have help topic, then it will traverse it’s parent control until find a help topic. Of course help-button will do nothing if every control of the dialog has no associated help topic.