RCP学习笔记

学习文档

Rich Client Platform http://wiki.eclipse.org/Rich_Client_Platform

SWT Snippets http://www.eclipse.org/swt/snippets/

JFaceSnippets http://wiki.eclipse.org/index.php/JFaceSnippets

Eclipse 4 RCP - Tutorial http://www.vogella.com/articles/EclipseRCP/article.html

Eclipse p2 updates for RCP applications - Tutorial http://www.vogella.com/articles/EclipseP2Update/article.html

Eclipse4 wiki http://wiki.eclipse.org/Eclipse4

 

RCP Maven插件tycho http://www.eclipse.org/tycho/

SWT/Swing设计器 WindowBuilder http://www.eclipse.org/windowbuilder/

 

日历插件

swtcalendar http://swtcalendar.sourceforge.net/

swt-datepicker http://sourceforge.net/projects/swt-datepicker/

 

表格工具ktable http://sourceforge.net/projects/ktable/

 

中文插件BabelLanguagePack-eclipse-zh http://www.eclipse.org/babel/downloads.php

 

RAP http://eclipse.org/rap/

2013年1月11日,Eclipse RAP 2.0发布。

Eclipse RAP 2.0发布——首词相同,含义不同

使用 RAP 将 RCP 应用程序转换成 web 应用程序

 

EclipseTrader

    EclipseTrader is an ​Eclipse Rich Client Platform (RCP) application focused to the building of an online stock trading system, featuring shares pricing watch, intraday and history charts with technical analysis indicators, level II/market depth view, news watching, and integrated trading. The standard Eclipse RCP plug-ins architecture allows third-party vendors to extend the functionality of the program to include custom indicators, views or access to subscription-based data feeds and order entry.

 

09年开始学习使用RCP时记录的一点东西,当时使用的是Eclipse 3.3。

 

一、product 配置文件plugin_customization .ini 说明

创建RCP 项目的产品配置后,在运行程序时,将读取项目根目录下的plugin_customization .ini 文件,设置默认参数。

 

常用参数意义如下:

org.eclipse.ui/SHOW_TRADITIONAL_STYLE_TABS=false Editor View 是否使用传统的Tab 的样式

org.eclipse.ui/SHOW_PROGRESS_ON_STARTUP=false splash 的画面中, 是否显示进度条

org.eclipse.ui/presentationFactoryId 定义外观样式,默认为WorkbenchPresentationFactory

org.eclipse.ui/defaultPerspectiveId 默认初始打开的Perspective

org.eclipse.ui/KEY_CONFIGURATION_ID 定义scheme ,默认值为org.eclipse.ui.defaultAcceleratorConfiguration 。用户在定义binding 时可创建新的scheme

org.eclipse.ui/SHOW_MEMORY_MONITOR=false 是否显示内存情况, 并可进行GC 操作

org.eclipse.ui/DOCK_PERSPECTIVE_BAR=topRight PerspectiveBar 的显示位置

org.eclipse.ui/SHOW_OPEN_ON_PERSPECTIVE_BAR=false PerspectiveBar, 是否显示New Perspective 按钮

org.eclipse.ui/SHOW_TEXT_ON_PERSPECTIVE_BAR=false PerspectiveBar, 是否显示Perspective 的名称

org.eclipse.ui/DISABLE_NEW_FAST_VIEW=false 是否禁止左下角的Show View As a Fast View 按钮

 

更多变量名和取值, 可以参见 org.eclipse.ui.IworkbenchPreferenceConstants

 

自定义配置文件名称:

在创建产品配置后(可能需同步),会在plugin.xml 文件自动创建products 扩展,为product 填加属性preferenceCustomization ,指定实际文件名称。

 

通过代码实现默认配置, 不依赖配置文件。

实现方法:在WorkbenchAdvisor#initialize() 里面进行赋值即可。代码如下:

 

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

     public void initialize(IWorkbenchConfigurer configurer) {

        PlatformUI.getPreferenceStore().setDefault(

IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP, true);

       PlatformUI.getPreferenceStore().setDefault(

IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false);

         //是否保存最后程序窗口状态
         configurer.setSaveAndRestore(true);

     }

}

二、菜单与快捷键

1 、创建快捷键

首先在plugin.xml 中加入两个扩展点:

<extension

point= "org.eclipse.ui.bindings" >

<scheme

id= "com.sunjc.rcpapp.scheme"

name= "rcp scheme"

parentId= "org.eclipse.ui.defaultAcceleratorConfiguration" >

</scheme>

<key

commandId= "command_exit"

contextId= "com.sunjc.rcpapp.context"

schemeId= "com.sunjc.rcpapp.scheme"

sequence= "Ctrl+Shift+X" >

</key>

<key

commandId= "org.eclipse.ui.file.exit"

schemeId= "org.eclipse.ui.defaultAcceleratorConfiguration"

sequence= "CTRL+X" >

</key>

</extension>

<extension

point= "org.eclipse.ui.commands" >

<command

defaultHandler= "com.sunjc.rcpapp.action.DefaultHandler"

id= "command_exit "

name= "%action.label.exit" >

</command>

</extension>

如上,定义了两个“退出”快捷键,“org.eclipse.ui.file.exit ”复用了eclipse 本身的。

bindings 扩展点中的commandId 对应于commands 扩展点中的idid 必须唯一。

 

bindings 中定义的scheme 为快捷键方案(Schemes are used to represent a general style or theme of bindings, eclipse keys 提供 "Default" "Emacs” 两种scheme 。仅激活的scheme 才能使用,可在 plugin_customization .ini 文件进行配置。 Scheme 可以继承, 激活子scheme 也将激活父scheme eclipse 默认的schemeId 为:“org.eclipse.ui.defaultAcceleratorConfiguration ”, 这个schema 存储了Eclipse 默认快捷键 。定义key 时必须指定schemeId

 

contextId 定义了快捷键的上下文环境,如指定了contextId 则必须激活才能使快捷键生效。Context 定义如下:

<extension

point="org.eclipse.ui.contexts">

<context

id="com.sunjc.rcpapp.context"

name="context">

</context>

</extension>

激活代码可写在ApplicationWorkbenchWindowAdvisor# preWindowOpen() 方法内

private static IContextActivation activation ;

public void preWindowOpen() {

if ( activation != null ) {

activation .getContextService().deactivateContext( activation );

}

 

IContextService contextService = (IContextService) PlatformUI

.getWorkbench ().getService(IContextService. class );

 

activation = contextService.activateContext(“ com.sunjc.rcpapp.context”);

}

Sequence 定义快键键。

defaultHandler 定义默认处理类,多个快捷键可共用,在无对应action 时将调用此类。以下为通过defaultHandler 实现的退出方法:

public class DefaultHandler implements IHandler {

 

public void addHandlerListener(IHandlerListener handlerListener) {

}

 

public void dispose() {

}

 

public Object execute(ExecutionEvent event) throws ExecutionException {

if ( "command_exit" .equals(event.getCommand().getId())) {

PlatformUI.getWorkbench ().close();

}

return null ;

}

 

public boolean isEnabled() {

return true ;

}

 

public boolean isHandled() {

return true ;

}

 

public void removeHandlerListener(IHandlerListener handlerListener) {

}

 

}

2 、创建菜单

<extension

point= "org.eclipse.ui.actionSets" >

<actionSet

id= "com.sunjc.rcpapp.actionSet"

label= "Main View"

visible= "true" >

<menu

id= "menuSystem"

label= "%menu.menuSystem" >

<separator

name= "menuAbout" >

</separator>

<separator

name= "menuLanguage" >

</separator>

<separator

name= "menuExit" >

</separator>

</menu>

<menu

id= "com.sunjc.rcpapp.language"

label= "%action.label.language"

path= "menuSystem/menuLanguage" >

<groupMarker

name= "platform.lanaguage" >

</groupMarker>

</menu>

<action

class= "com.sunjc.rcpapp.action.nl.ZhCNAction"

id= "com.sunjc.rcpapp.action.nl.zhCNAction"

label= "%action.label.zhcn"

menubarPath= "menuSystem/com.sunjc.rcpapp.language/platform.lanaguage" >

</action>

<action

class= "com.sunjc.rcpapp.action.ExitAction"

id= "com.sunjc.rcpapp.action.exitAction"

label= "%action.label.exit"

menubarPath= "menuSystem/menuExit" >

</action>

猜你喜欢

转载自billben.iteye.com/blog/1704980
今日推荐