Any change taking place in IResource will invoke the IResource Tracking. It may be caused by mannual operation like adding/remove/rename file by mouse, or eclipse operation like building.
- Register resourceChangedListener
- find IResourceDelta
Each IResourceDelta is tree node, which represents a IResource
- Filter the type (Eclipse Platform Level)
This part of work is proceed in resourceChanged(IResourceChangeEvent event) method which is only method of IResourceChangeListener interface
- Find IResourceDelta event.getDelta() return the root of resourceDelta. Generally, it represents the project where the change takes place.
- Filter the type (Eclipse Platform Level)
-
Traverse resourceDelta(Eclipse project level)
This part of work is prcessed in visit(IResourceDelta delta)method, which is the only method of IResourceDeltaVisitor interface, we can set the return value which is boolean to notify whether the traversaling proceeds. visit will be invoked whenever traversal meets a IResourceDelta. so we need to hander all types of IResource. sometime we are only interested in certain kinds of changes lick content change, we can achieve it by following way In a word, comapred to resourceChanged(IResourceChangeEvent event), visitor focus on the things taking place during the traversal process. Besides that, each traversed node is below the visitor caller which is a IResourceDelta also .
本文介绍如何在Eclipse中监听资源变化,包括注册资源变化监听器、查找资源变化节点及遍历资源变化的方法。通过具体代码示例展示了如何实现文件、文件夹及项目的增删改查操作。
255

被折叠的 条评论
为什么被折叠?



