public class HtmlEditor extends MultiPageEditorPart
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
initResourceChangeListener();
}
private IWorkspace getWorkspace() {
return ((IFileEditorInput) getEditorInput()).getFile().getWorkspace();
}
private void initResourceChangeListener() {
IResourceChangeListener resourceChangeListener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
handleResourceChange(event);
}
};
getWorkspace().addResourceChangeListener(resourceChangeListener);
}
private void handleResourceChange(IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
IFile file = ((IFileEditorInput) getEditorInput()).getFile();
// update editor
}
}
/**
*当更新或者删除文件的时候
**/
public void resourceChanged(final IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.POST_CHANGE)
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IResourceDelta rootDelta = event.getDelta();
if(rootDelta ==null){
return;
}
IResourceDelta htmlDelta = rootDelta.findMember(new Path("DefaultProject/t.html"));
if(htmlDelta == null){
return;
}
}
});
if (event.getType() == IResourceChangeEvent.PRE_CLOSE) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
for (int i = 0; i < pages.length; i++) {
if (((FileEditorInput) getSourceEditor().getEditorInput()).getFile().getProject().equals(event.getResource())) {
IEditorPart editorPart = pages[i].findEditor(getSourceEditor().getEditorInput());
pages[i].closeEditor(editorPart, true);
}
}
}
});
}
}