RCP学习笔记

09年学习Eclipse RCP 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扩展点中的id,id 必须唯一。
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>
	</actionSet>
</extension>

 

学习文档

Rich Client Platform

SWT Snippets

JFaceSnippets

Eclipse 4 RCP - Tutorial

Eclipse p2 updates for RCP applications - Tutorial

Eclipse 4 wiki

 

RCP Maven插件tycho

SWT/Swing设计器 WindowBuilder

中文插件BabelLanguagePack-eclipse-zh

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

Eclipse Trader

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值