当前位置: 代码迷 >> Web前端 >> 小弟我的第一个RCP程序
  详细解决方案

小弟我的第一个RCP程序

热度:406   发布时间:2012-10-08 19:54:56.0
我的第一个RCP程序

?????? RCP,就是Rich Client Platform的缩写,即胖客户端平台,是Eclipse进化的产物(自3.0版以后出现),是Eclipse组织向用户提供的强大的开放性开发平台,能够使用户方便地创建自己的基于Eclipse的应用程序,并且这些应用程序能够得到Eclipse的底层支持。更重要的是,我们可以利用Java创建象Eclipse这么漂亮的桌面程序。

桌面应用程序也可称为胖客户端程序或GUI程序。用SWT可以像SWING一样开发独立的桌面应用,但这样无法利用Eclipse的插件机制,所以有些人就折衷了一下:把桌面应用写成Eclipse插件。不过,插件基于Eclipse运行,Eclipse原有的菜单和工具栏无法消除。如果你连Eclipse的那些菜单和工具栏均不想被用户看到,那么就要用到RCP平台。

?

RCP的主要知识基于SWT/JFaceEclipse插件。

下面用向导建立一个RCP工程。

1、Plug-in Project,记得选择富客户端应用。

2、在ApplicationActionBarAdvisor.java类里

//文件菜单里的项目 public IWorkbenchAction newAction; public IWorkbenchAction openAction; public IWorkbenchAction refreshAction; public IWorkbenchAction exitAction; //编辑菜单里的项目 public IWorkbenchAction copyAction; public IWorkbenchAction pasteAction; //帮助菜单里的项目 public IWorkbenchAction helpAction; public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } /** * 创建操作并注册操作 */ protected void makeActions(IWorkbenchWindow window) { newAction = ActionFactory.NEW.create(window); newAction.setText("创建窗口"); newAction.setToolTipText("创建一个新窗口"); register(newAction); //Problem openAction = ActionFactory.NEW_EDITOR.create(window); openAction.setText("打开文件"); register(openAction); refreshAction = ActionFactory.REFRESH.create(window); refreshAction.setText("刷新"); refreshAction.setToolTipText("刷新"); register(refreshAction); exitAction = ActionFactory.QUIT.create(window); exitAction.setText("退出"); register(exitAction); copyAction = ActionFactory.COPY.create(window); copyAction.setText("复制"); register(copyAction); pasteAction = ActionFactory.PASTE.create(window); pasteAction.setText("粘贴"); register(pasteAction); // helpAction = ActionFactory.ABOUT.create(window); helpAction = ActionFactory.HELP_CONTENTS.create(window); helpAction.setText("关于我们"); register(helpAction); } /** * 菜单栏 */ protected void fillMenuBar(IMenuManager menuBar) { MenuManager fileMenu = new MenuManager("文件(&F)",IWorkbenchActionConstants.M_FILE); MenuManager editMenu = new MenuManager("编辑(&E)",IWorkbenchActionConstants.M_EDIT); MenuManager helpMenu = new MenuManager("帮助(&H)",IWorkbenchActionConstants.M_HELP); fileMenu.add(newAction); fileMenu.add(openAction); fileMenu.add(refreshAction); fileMenu.add(exitAction); editMenu.add(copyAction); editMenu.add(pasteAction); helpMenu.add(helpAction); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); } /** * 工具栏 */ protected void fillCoolBar(ICoolBarManager coolBar) { // super.fillCoolBar(coolBar); IToolBarManager toolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); IToolBarManager viewToolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); toolBar.add(newAction); coolBar.add(new ToolBarContributionItem(toolBar,"新建")); viewToolBar.add(refreshAction); coolBar.add(new ToolBarContributionItem(viewToolBar,"刷新")); }


?3、帮助系统的开发

3.1、代码的实现

//帮助 private IWorkbenchAction helpAction; /** * 创建操作 */ protected void makeActions(IWorkbenchWindow window) { /* 帮助 */ helpAction = ActionFactory.HELP_CONTENTS.create(window); register(helpAction); } /** * 填充主菜单 */ protected void fillMenuBar(IMenuManager menuBar) { /* 主菜单栏 */ IMenuManager mainMenu = getActionBarConfigurer().getMenuManager(); MenuManager helpMenu = new MenuManager("帮助(&H)", IWorkbenchActionConstants.M_HELP); helpMenu.add(introAction); helpMenu.add(helpAction); mainMenu.add(helpMenu); }

?


?3.2、添加相关依赖项

打开plugin.xml,转到"依赖项"页,添加以下

? 1. org.apache.lucene

2.org.eclipse.help.appserver

3.org.eclipse.help.base

4.org.eclipse.help.ui

5.org.eclipse.help.webapp

6.org.eclipse.tomcat

7.org.eclipse.ui.forms

3.3、添加org.eclipse.help.toc扩展点

"扩展向导"-->"帮助内容",确定后可以看到所有扩展的列表中多了一个org.eclipse.help.toc扩展,这里可能需要修改一下,生成的toc.xmltestToc.xml里面的label属性标签不能是乱码,不然帮助框架会读不出,到时候显示不出帮助的组织结构。

注意此处的扩展点哦:

<extension point="org.eclipse.help.toc"> <toc file="toc.xml"> </toc> <toc file="testToc.xml" primary="true"> </toc> </extension>

?


?

新建自己的帮助文档如toc.xmltestToc.xml

?

例如在toc.xml中

<toc label="Sample Table of Contents"> <topic label="Main Topic" href="html/maintopic.html"> <topic label="Sub Topic" href="html/subtopic.html"/> </topic> <topic label="Main Topic 2" href="html/maintopic.html"> <topic label="Sub Topic" href="html/subtopic.html"/> </topic> </toc>

?


?

??? 4、实现上下文帮助

?? 暂时没看懂,先不写了哈,呵呵……

?

?? 5、打包发行

?? 可用Ant脚本也可用product导出。

???

?

?

因为初次自学RCP,有不对的地方欢迎大家指正,不胜感激!

?

  相关解决方案