7. Eclipse4 RCP Application不得不掌握的概念

司空均
2023-12-01

本文主要介绍Eclipse 4 RCP Application中的:Model Objects和Features。

1. Model Objects

在Eclipse 框架启动的时候会通过.Application.e4.xmi配置文件自动解析一些Application model Objects。 下表主要展示在Eclipse中常见的一些重要的Model Objects:

Model ElementsDescription
MApplicationDescribes the application object. All other model elements are contained in this object.
MAddonA self-contained component typically without user interface. It can register for events in the application life cycle and handle these events.
MWindowRepresents a window in your application.
MTrimmedWindowSimilar to MWindow but it allows containing toolbars for the windows (via the TrimBars model elements).
MPerspectiveRepresents a different layout of parts to be shown inside the window. Should be contained in a MPerspectiveStack.
MPartRepresents the model element part, e.g., a view or an editor.
MDirtyableProperty of MPart which can be injected. If set to true, this property informs the Eclipse platform that this Part contains unsaved data (is dirty). In a handler you can query this property to provide a save possibility.
MPartDescriptorMPartDescriptor is a template for new parts. A new part based on this part descriptor can be created and shown via the Eclipse framework.
SnippetsSnippets can be used to pre-configure model parts which you want to create via your program. You can use the Eclipse framework to clone such a application model at runtime.

2. feature projects 和feature

使用eclipse 的创建feature project 和创建一个plugin project是一样的。一个feature project包含 features。一个 feature可以描述一系列的plugins 和 feature ,通常是将一系列相关的组件组合到一个feature中当做是一个逻辑单元。当然Feature和plug-in 一样,也有名称name,版本号version number,通常在license中指定这些信息。
如下为一个简单的feature.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<feature 
    id="com.vogella.eclipse.featuretest.feature" 
    label="Feature" version="1.0.0.qualifier" 
    provider-name="vogella GmbH">

    <description url="http://www.example.com/description">
          [Enter Feature Description here.] 
    </description> 

    <license url="http://www.example.com/license">
        [Enter License Description here.] 
    </license> 
<plugin 
    id="com.vogella.eclipse.featuretest.feature" 
    install-size="0" 
    version="0.0.0" 
    unpack="false"/> 
</feature>

2.1 创建Feature Project

File –> New –>Other –>Plug-in Development –> Feature Project

2.2 编辑Feature信息

  • information tab:可以让你给这个feature添加 desciption 和 copyright .
  • plug-in tab :允许将plug-in 添加到当前feaure;
  • include Feature Tab: 可以将别的feature包含到该feature中;
  • Dependencied tab: 可以定义其他feature,哪个必须使用当前feature;
  • build tab:用于构建过程,包含feature.xml。

2.3 feature, plug-in 和Product

一个产品,可以是依赖于plugin或者feature的,这些设置可以通过product的Overview tab进行配置。
在product的编辑器界面的contents tab指定该产品由那些plugin或者feature组成的。

一个product不会自动执行依赖关系,若你将一个feature添加进产品,同时也想将其依赖添加进来,就可以点击required 按钮,进行添加。

2.4 使用Feature的优点

  • Feature将plugin分组,组成的逻辑单元,更容易掌控一系列的plugin组件。取代了添加一个个独立的plugin到product configure 文件中,使用feature对他们进行分组;
  • feature可以使用eclipse update manager , build progress 来选择最终eclipse产品。feature可以作为一个基础定义一个启动配置。

eclipse提供了几种预定义的features, 比如,给Eclipse RCP application 定义的 org.eclipse.e4.rcp

 类似资料: