RCP添加动态帮助

添加动态帮助

    除了联机帮助外也可以为界面中的元素添加动态的帮助,动态帮助是通过按 F1 键来获得的,要添加动态帮助,需要扩展org.eclipse.help.contexts扩展点。以下为步骤:
(1)在plugin.xml文件中配置以下代码:(手工输入的,extentions页面中没有这一项)
   <extension
         point="org.eclipse.help.contexts">
      <contexts file="SampleViewHelp.xml"/>
   </extension>

    其中,file的文件名为设置动态帮助的xml文件,该文件要符合一个格式。

    (2) 新建一个所对应的SampleViewHelp.xml文件,然后输入以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<contexts>
<context id="SampleViewContextId">
   <description> 这是一个帮助示例。</description>
   <topic href="html/samples/maintopic.html" label="主题1"/>
   <topic href="html/samples/subtopic.html" label="主题2"/> 
</context>
</contexts>

    其中,id很重要,为该上下文帮助的唯一标识。

    (3)最后,为该帮助指定所关联的控件,例如在上文视图中,有一个SampleView的类,可以在该类的方法createPartControl中添加以下代码:
   PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getTable(), "SampleViewContextId");

    其中,PlatformUI.getWorkbench().getHelpSystem()方法可以获得帮助对象IWorkbenchHelpSystem。然后将上文中定义的context的id注册到帮助系统中。
    IWorkbenchHelpSystem对象除了可以为某个控件注册上下文帮助外,也可以为菜单、操作注册上下文帮助。该类中的主要方法如下所示:
    ◇ setHelp(IAction action, String contextId):为操作注册上下文帮助。
    ◇ setHelp(Control control, String contextId):为控件注册上下文帮助。
    ◇ setHelp(Menu menu, String contextId):为菜单注册上下文帮助。
    ◇ setHelp(MenuItem item, String contextId):为菜单项注册上下文帮助。

你可能感兴趣的:(eclipse,xml)