FAQ How do I make my plug-in dynamic aware?
From Eclipsepedia
<!---->
Dynamic awareness requires extra steps that were not required prior to the introduction of dynamic plug-ins. Dynamic awareness requires that you remove all references to classes defined in other plug-ins when those plug-ins are removed from the system. In particular, if your plug-in defines extension points that load classes from other plug-ins—executable extensions—you need to discard those references when other plug-ins are dynamically removed. The extension registry allows you to add a listener that notifies you when extensions are being added or removed from the system. If your plug-in maintains its own cache of extensions that are installed on your extension point, your listener should update this cache for each added or removed extension.
The following is an example of a simple class that maintains its own cache of the set of extensions installed for a given extension point. This example is a bit contrived as simply caching the extension objects has no value. Typically, your plug-in will process the extensions to extract useful information and possibly load one or more classes associated with that extension. The basic structure of this cache example is as follows:
public class ExtCache implements IRegistryChangeListener {
private static final String PID = "my.plugin";
private static final String PT_ID =
PID + "." + "extension.point";
private final HashSet extensions = new HashSet();
...
}
The extensions field stores the set of installed extensions for a particular extension point.
The cache has a startup method that loads the initial set of extensions and then adds an extension registry listener in order to be notified of future changes:
public void startup() {
IExtensionRegistry reg = Platform.getExtensionRegistry();
IExtensionPoint pt = reg.getExtensionPoint(PT_ID);
IExtension[] ext = pt.getExtensions();
for (int i = 0; i < ext.length; i++)
extensions.add(ext[i]);
reg.addRegistryChangeListener(this);
}
The class implements the IRegistryChangeListener interface, which has a single method that is called whenever the registry changes:
public void registryChanged(IRegistryChangeEvent event) {
IExtensionDelta[] deltas =
event.getExtensionDeltas(PID, PT_ID);
for (int i = 0; i < deltas.length; i++) {
if (deltas[i].getKind() == IExtensionDelta.ADDED)
extensions.add(deltas[i].getExtension());
else
extensions.remove(deltas[i].getExtension());
}
}
This class is now dynamic aware but is not yet dynamic enabled; that is, the class does not yet support itself being dynamically removed. The final step is to implement a shutdown method that clears all values from the cache and removes the listener from the extension registry:
public void shutdown() {
extensions.clear();
IExtensionRegistry reg = Platform.getExtensionRegistry();
reg.removeRegistryChangeListener(this);
}
This shutdown method must be called from the shutdown method of the plug-in that defines the cache. For the complete source code of this example, see the ExtCache class in the FAQ Examples plug-in.
Note that not only extensions points acquire and maintain references to classes defined in other plug-ins. You need to be especially aware of static fields and caches that contain references to objects whose class is defined in other plug-ins.
If you hold onto classes defined in other plug-ins through different mechanisms, you also need to discard those references when those other plug-ins are removed.
分享到:
相关推荐
在 Eclipse RCP 中,JUnit 可以用来验证插件的行为是否符合预期。编写良好的单元测试有助于确保代码的质量和稳定性。 ##### JFace Data Binding JFace 数据绑定提供了将 UI 控件与模型对象自动同步的能力。通过...
在IT行业中,RCP(Rich Client Platform)是Eclipse框架提供的一种用于构建桌面应用程序的平台。它允许开发者基于已有的框架构建复杂、可扩展的应用,而无需从零开始编写所有基础架构。本篇文章将深入探讨如何在RCP...
2. **创建项目**:在Eclipse中,通过“New -> Project”创建一个新的RCP项目,选择相应的模板,如“Rich Client Application”。 3. **定义插件结构**:规划并创建所需的插件,包括UI插件、业务逻辑插件、数据访问...
1. **插件体系结构**:Eclipse插件基于OSGi框架,每个插件都是独立的模块,可以动态加载和卸载。它们通过接口通信,遵循“依赖声明”原则,确保了模块间的解耦。 2. **扩展点和扩展**:Eclipse允许开发者定义扩展点...
然后,在项目的插件配置中,引用该语言包作为依赖,这样在运行时,Eclipse会自动加载并显示中文界面。对于开发插件,还需要确保插件的本地化设置正确,以便插件的UI元素也能正确显示中文。 4. **RCP开发流程** ...
视图是Eclipse RCP中显示信息的小型窗口,可以动态地显示数据。创建视图涉及定义视图的类,并实现必要的接口方法来显示内容。还可以通过代码将视图添加到特定的透视图中。 #### 使用编辑器、视图交互及模型更新 ...
10. **Equinox OSGi**:Eclipse RCP基于Equinox OSGi容器运行,这是一种动态模块系统,允许在运行时加载、卸载和更新插件,确保了应用程序的可维护性和可扩展性。 了解并熟练掌握这些概念,对于成功开发Eclipse RCP...
1. **第9章.rar** - 这一章可能涵盖了RCP应用系统的高级主题,如动态插件加载、国际化和本地化、自定义工作流集成等。学习这部分内容有助于开发者了解如何利用Eclipse RCP实现更复杂的功能和定制化需求。 2. **第8...
在描述中提到,打开这个文件的"概述"视图,可以查看插件的基本信息,而"启动Eclipse应用程序"功能则是通过这个视图运行RCP应用,这通常会启动一个Eclipse RCP壳,加载并执行插件中的代码。 Eclipse RCP的应用程序...
Eclipse插件基于OSGi(开放服务网关规范)标准,具有良好的模块化和动态加载特性。 "模态"和"阻塞Eclipse平台"通常是指在Eclipse中,某些操作或对话框会阻止用户与工作台的其余部分交互,直到该操作完成或对话框...
在提供的压缩包中,包含了关于Eclipse RCP插件开发15至24章的学习笔记,这些章节覆盖了多个关键主题,下面将对这些主题进行详细解读。 1. **第15章:对话框和向导(Dialogs and Wizards)** - 在Eclipse RCP中,...
这通常意味着需要配置Java类路径,以便Java虚拟机能够在运行时找到和加载Eclipse插件中定义的类。 Eclipse 4 RCP开发涉及到了解和使用Eclipse平台的基础结构,包括但不限于Eclipse的公共API和内部API。开发者应确保...
在"eclipse开发rcp4应用示例"中,我们将探讨如何使用Eclipse RCP4构建一个应用程序,同时整合log4j日志系统以及自定义的启动画面(splashscreen)。 首先,了解Eclipse RCP4的基础架构至关重要。它基于OSGi服务,...
在Eclipse RCP中开发应用程序,通常涉及以下步骤: 1. 创建一个新的RCP项目。 2. 定义视图和编辑器,用于展示和编辑数据。 3. 实现业务逻辑,包括数据读取、转换和保存。 4. 利用Eclipse的插件机制进行功能扩展和...
- 应用启动:启动过程包括加载插件、初始化工作台等步骤。 - 用户交互:通过视图和编辑器处理用户输入。 - 事件处理:使用Eclipse的事件模型,监听并响应用户操作或系统事件。 - 应用关闭:正确关闭资源,保存...
Eclipse RCP的特性包括组件化开发、动态插件加载、跨平台兼容性以及对Java Swing和 SWT图形库的支持,这些都使得开发者能更灵活地构建和维护应用系统。 总的来说,Eclipse RCP是现代软件开发中的一个强大工具,尤其...
RCP利用OSGi服务来管理和动态加载这些插件。源代码中可能包括了如何创建基本的RCP项目,定义插件结构,以及配置manifest.mf文件的示例。 2. **视图(Views)和编辑器(Editors)** 视图是显示特定信息或提供交互...
2. **新建 RCP 应用程序项目**:选择 "File" > "New" > "Other",然后在 "Project" 分类中找到 "Eclipse Application" 并点击 "Next"。 3. **配置项目**:输入项目名称(例如 "HelloWorldRCP"),选择所需的模板,并...