gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 01:04:16 27 4
gpt4 key购买 nike

我正在开发 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com