java - 如何订阅 Eclipse 中的 OpenProject 事件?

标签 java eclipse eclipse-plugin eclipse-rcp

我正在开发 Eclipse 插件。

我一直在阅读如何使用界面 IResourceChangeListener 在项目即将关闭时订阅获取通知。 ,并使用 PRE_CLOSE 事件类型。以下文字摘自 Eclipse help :

Notifies listeners that a project is about to be closed. This event can be used to extract and save necessary information from the in-memory representation (e.g., session properties) of a project before it is closed. (When a project is closed, the in-memory representation is disposed). The workspace is locked (no resources can be updated) during this event. The event contains the project that is being closed.

我没有找到如何在项目即将打开时收到通知。

最佳答案

您可以创建自己的IResourceChangeListener 并通过IResourceDelta.OPEN 过滤delta 的种类,它只影响IProjects,并且在打开和关闭项目时都会触发:

public void resourceChanged(IResourceChangeEvent event) {
    if (event == null || event.getDelta() == null)
        return;
    event.getDelta().accept(new IResourceDeltaVisitor() {
        public boolean visit(IResourceDelta delta) throws CoreException {
            if (delta.getKind() == IResourceDelta.OPEN)
                final IResource resource = delta.getResource();
                if (!(resource instanceof IProject))
                    return;
               //do your stuff and check the project is opened or closed
        }
}

有用的链接: http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.html

关于java - 如何订阅 Eclipse 中的 OpenProject 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7664758/

相关文章:

java - java中socket编程如何切换turn

java + reSTLet = 奇怪的性能行为

java - 使用文件的 ActionProvider - Eclipse CNF

java - Eclipse 插件内的图像路径

java - 如何在 Eclipse 中获取工作区路径?

android - 开关盒错误。 Mac 上用于 Android 开发的 Eclipse IDE : Change workspace compliance to JRE 1. 7

java - InputStream音频混合(MODE_STREAM)

java - 是否可以向我没有源代码的类添加断点?

java - jUnit 测试不输出任何内容

eclipse - Servlet 在 Eclipse 中的 Tomcat 上运行但不显示在 Ubuntu Server Tomcat 上