IResourceChangeEvent - 如何识别项目删除/重命名 [英] IResourceChangeEvent - how to identify a project delete/rename
问题描述
IResourceChangeListener 中如何正确区分:addResourceChangeListener(...) c $ c>项目被删除/重命名?
How can I properly distinguish, inside an IResourceChangeListener
that is added via ResourcePlugin.getWorkspace().addResourceChangeListener(...)
that a Project was deleted / renamed?
通过尝试的东西,似乎是$ code> IResourceChangeEvent.getDelta() - > ; IResourceDelta 将是答案。
Through trying things out, it would seem that the IResourceChangeEvent.getDelta() -> IResourceDelta
would be the answer.
从 Eclipse API :
任意创建,删除和
修改一个或多个资源的事后批量报告,表示为分层
资源增量。事件类型为POST_CHANGE,getDelta返回
分层增量。资源增量根据工作空间
root。在一组
资源更改后,这些事件会广播给有关各方,无论自动建造是否启用都会发生。
在通知这些
事件时,工作区已关闭以进行更改。在这个事件周期中报告的增量在所有注册此类事件的
监听器中是相同的。
After-the-fact batch reports of arbitrary creations, deletions and modifications to one or more resources expressed as a hierarchical resource delta. Event type is POST_CHANGE, and getDelta returns the hierarchical delta. The resource delta is rooted at the workspace root. These events are broadcast to interested parties after a set of resource changes and happen whether or not autobuilding is enabled. The workspace is closed for change during notification of these events. The delta reported in this event cycle is identical across all listeners registered for this type of event.
编辑:添加我的发现到目前为止
adding my findings so far
所以, Event.getType()
是 POST_CHANGE
并且需要
-
包含一个小孩的增量
IResourceDelta
具有
getKind()== REMOVED
用于删除,deltagetResource()。getType()== PROJECT
,以便我们知道这是一个项目
(这个IResourceDelta
不应该有任何孩子)
a delta that contains a child
IResourceDelta
that has thegetKind() == REMOVED
for a deletion, and the deltagetResource().getType() == PROJECT
so that we know it's a project ( thisIResourceDelta
should not have any children )
a getDelta()
包含两个孩子 IResourceDelta
> getKind()== REMOVED 和 getKind()== ADDED
,还有 getResource()。getType() == PROJECT
,而那些 IResourceDelta
不包含任何儿童Deltas(我观察到当一个文件被重命名/删除时,的IProject
资源属于父母 Delta
...的第一行子项的资源)
a getDelta()
that contains two children IResourceDelta
that have getKind() == REMOVED
and getKind() == ADDED
, also the getResource().getType() == PROJECT
, and those IResourceDelta
contain no children Deltas (I've observed that when a file is renamed/deleted, the IProject
the resource belongs to is the one that is on the first row of children of the parent Delta
...)
有人可以确认这个假设吗?是否真的有必要对孩子进行深度搜索以实现事件是否是项目重命名/删除或文件/文件夹?
Can someone confirm this supposition? Is if it really necessary to do a tree depth search for children to realize if the Event is of a project rename/delete or a file/folder?
推荐答案
-
您需要通过
ResourcePlugin.getWorkspace()添加资源更改侦听器addResourceChangeListener(listener,
IResourceChangeEvent .POST_CHANGE)在您的监听器中,使用
IResourceDeltaVisitor
访问delta的所有变化通过
event.getDelta()。accept(...)
In your listener, use a
IResourceDeltaVisitor
to visit all the changes in the delta viaevent.getDelta().accept(...)
访问者应查看
REMOVED
的项目如果您期待项目被删除并创建了相同的名称(如在构建事件期间文件&文件夹
发生的),然后除了REMOVED
,还要在delta中找到
REPLACED
If you are expecting the project to be removed and created with the same name (as happens to files & folders during build events), then in addition to the
REMOVED
, also look forREPLACED
in the delta这篇关于IResourceChangeEvent - 如何识别项目删除/重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!