How can I get the IResource associated with the propertyChanged event in Eclipse?
I am developing an Eclipse plugin that monitors events in the workspace. One of my classes implements IPropertyListener which means that it inherits the propertyChanged method. This method gets fired when a file in the plugin's workspace gets dirtied. I need to know what IResource is associated with the propertyChanged event but my current implementation isn't working.
public void propertyChanged(Object source开发者_运维问答, int propId)
{
if(propId == IEditorPart.PROP_DIRTY)
{
IResource resource = (IResource)source;
}
}
I think this isn't working because source is not of type IResource, but I don't know how else to get at the resource associated with this property change.
Any ideas of how I would get at the IResource?
Try casting source to IEditorPart. Then call getEditorInput(). Not all editor inputs are workspace resources, so check for one of the sub-types (probably FileEditorInput) and go from there.
Alternatively, just listen to resource changes yourself via IWorkspace.addResourceChangeListener() instead of relying on a third party.
精彩评论