Skip to content

Instantly share code, notes, and snippets.

@aqubi
Created June 6, 2009 15:49
Show Gist options
  • Save aqubi/124885 to your computer and use it in GitHub Desktop.
Save aqubi/124885 to your computer and use it in GitHub Desktop.
public void resourceChanged(final IResourceChangeEvent event) {
if (event.getType() != IResourceChangeEvent.POST_CHANGE
|| !(getEditorInput() instanceof IFileEditorInput)) {
return;
}
IResourceDelta rootDelta = event.getDelta();
IFile file = ((IFileEditorInput) getEditorInput()).getFile();
IPath filePath = file.getFullPath();
IResourceDelta delta = rootDelta.findMember(filePath);
if (delta == null) {
return;
}
Runnable changeRunnable = null;
if (delta.getKind() == IResourceDelta.REMOVED) {
if ((IResourceDelta.MOVED_TO & delta.getFlags()) != 0) {
IPath path = delta.getMovedToPath();
final IFile newFile = delta.getResource().getWorkspace().getRoot().getFile(path);
if (newFile != null) {
changeRunnable = new Runnable() {
public void run() {
setInput(new FileEditorInput(newFile));
setPartName(getEditorInput().getName());
}
};
}
} else {
changeRunnable = new Runnable() {
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.closeEditor(VisualMXMLEditor.this, false);
}
};
}
} else if (delta.getKind() == IResourceDelta.CHANGED) {
changeRunnable = new Runnable() {
public void run() {
refreshGraphicalViewer();
}
};
}
if (changeRunnable != null) {
getSite().getShell().getDisplay().asyncExec(changeRunnable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment