public class EditorUtils {
public static synchronized void closeEditorIfRequired(IResourceChangeEvent event, final IFile file, final IEditorPart editor) {
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
IResourceDelta delta = event.getDelta().findMember(file.getFullPath());
if (delta != null) {
IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) {
if (delta.getKind() == IResourceDelta.REMOVED) {
if (file.equals(delta.getResource())) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
editor.getSite().getPage().closeEditor(editor, false);
} catch (Exception e) {
DesignerLogger.logErrorWithoutDialog("Close editor on delete", e);
}
}
});
return false;
}
}
return true;
}
};
try {
delta.accept(visitor);
} catch (CoreException e) {
DesignerLogger.logErrorWithoutDialog("Visit on delete", e);
}
}
}