现在的位置: 首页 > 综合 > 正文

Rcp添加帮助

2013年09月03日 ⁄ 综合 ⁄ 共 2455字 ⁄ 字号 评论关闭

Juno项目开发到一段时间,发现之前很多操作上的小细节慢慢的都被遗忘了,在use case里面提到的,或者是后来方便操作的新加的tips越来越多,一个完整的帮助文档成为必需,开发一个rcp的帮助文档相当方便,其功能确实相当强大。
1, 在RCP项目中找到AppllicationiActionBarAdvisor这个类
//声明
private IAction helpContentAction = null;
private IAction helpSerchAction = null;
private IAction helpDynamicAction = null;

//初始化makeActions(final IWorkbenchWindow window) helpContentAction = ActionFactory.HELP_CONTENTS.create(window);
register(helpContentAction);
helpSerchAction = ActionFactory.HELP_SEARCH.create(window);
register(helpSerchAction);
helpDynamicAction = ActionFactory.DYNAMIC_HELP.create(window);
register(helpDynamicAction);

//绑定到菜单上fillMenuBar(IMenuManager menuBar)方法中
MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
helpMenu.add(helpContentAction);
helpMenu.add(helpSerchAction);
helpMenu.add(helpDynamicAction);
如果菜单使用的extension配置。可以在菜单下面添加command,然后使用系统提供的commandId.

commandId可以去ActionFactory中看去.
2, 为产品添加插件依赖,也为help所在的插件添加插件依赖
org.apache.lucene
org.eclipse.help.appserver
org.eclipse.help.base
org.eclipse.help.ui
org.eclipse.help.webapp
org.eclipse.tomcat
org.eclipse.ui.forms
其中tomacat会提示找不着
org.eclipse.tomcat no longer included
What is affected: Any RCP application with a dependency on the org.eclipse.tomcat plugin.
Description: Up to and including Eclipse 3.2 the help system used a Tomcat server and included the plug-in org.eclipse.tomcat. Since Eclipse 3.3 the help system no longer uses Tomcat and instead uses the Equinox web server. In Eclipse 3.4 org.eclipse.tomcat was removed from platform and sdk builds.
Action required: Remove any dependencies to org.eclipse.tomcat. If you need a web server use the Equinox server defined in org.eclipse.equinox.http.jetty.
官方给的解释,用jetty代替tomcat,并且在添加的时候一并添加required plugin-in
3, 添加扩展点
如下图所示,添加 org.eclipse.help.toc扩展点,并选中使用模板,添加后在项目目录下会多出html目录,和toc.xml,testToc.xml的配置文件,toc.xml是每个帮助文档具体内容,testToc.xml则有点类似挂载帮助文档的配置,即可以有多个帮助文档
将写好的帮助文件的HTML放到html目录下,然后修改toc文件,启动项目点击help contents就可以看到完整的help document,改帮助已经集成打印,前进,后退等基本功能和查找等进阶功能,相当好用。
4, 添加上下文帮助
所谓上下文帮助,就是在相应功能上点击F1会出来相应的help
在plguin-in.xml中直接添加
<extension point="org.eclipse.help.contexts">
<contexts file="JunoHelpDocument.xml"/>
</extension>
然后新建JunoHelpDocument.xml文件,建立上下文帮助索引。
<contexts>
<context id="BulkLoaderId">
<description>help document of bulkloader</description>
<topic href="html/bulkloader.html" label="BulkLoader"/>
</context>
</contexts>
现在去项目中的view中注册帮助,找到view的createPartControl(Composite parent)
添加PlatformUI.getWorkbench().getHelpSystem().setHelp(container, "RcpJuno. BulkLoaderId ");
RcpJuno为help文档所在的项目名字,BulkLoaderId即对应的帮助文档
最后还得在setFocus()中让container获得焦点,然后在对应的view按F1会弹出对应的help。

 

【上篇】
【下篇】

抱歉!评论已关闭.