Is it possible to track resource read-only property in Eclipse?
I am working with eclipse resources right now and interested whether it is possible to han开发者_StackOverflow社区dle file read-only property change ? For example user changes file read-only property outside application and then I can handle this property change event in my application.
I don't think, it is possible to do it automatically, as Eclipse resources do not synchronize all the time with the file system. More specifically, file changes do not trigger events in the Eclipse resources directly. Files are refreshed only when the resources are read.
Maybe if you are refreshing continously, it would be possible, but that can have quite an overhead. After a refresh it is possible to listen to changes in resources - thats what Builders and resource listeners are for.
To be more precise than Zoltan's answer:
No, it is not possible to do this directly. However, it is possible to periodically refresh the workspace and look for changes that you are interested in.
- Create and schedule a Job that runs every XXX seconds. This job will run IProject.refreshLocal(IResource.DEPTH_INFINITE, null). After running this operation, it will re-schedule itself to run in another XXX seconds.
- Add an IResourceChangeListener that listens for the changes you are interested in.
Now, if the Read-only changes happen from inside the workspace, you will not have to do #1, and #2 (the resource change listener) will run automatically.
精彩评论