Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2014-08-08 15:30:40 +0000
committerElena Laskavaia2014-08-11 15:28:30 +0000
commitb7ec8deec417e0338a13f0f3bde024a2d84f07c3 (patch)
tree178b66e91df621570975c224e3eacf7c14573695
parent1bf2aa825ff722d9ce49873b16b357b4236d8c17 (diff)
downloadorg.eclipse.cdt-b7ec8deec417e0338a13f0f3bde024a2d84f07c3.tar.gz
org.eclipse.cdt-b7ec8deec417e0338a13f0f3bde024a2d84f07c3.tar.xz
org.eclipse.cdt-b7ec8deec417e0338a13f0f3bde024a2d84f07c3.zip
Bug 242405 - Binary file editor does not refresh when binary is rebuilt
Change-Id: I0af100959f8f61b2d2735f9d0d9cd42b6c91e590 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/31300 Tested-by: Hudson CI
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/DefaultBinaryFileEditor.java96
1 files changed, 76 insertions, 20 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/DefaultBinaryFileEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/DefaultBinaryFileEditor.java
index 5d8bd85238a..28eadddbab5 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/DefaultBinaryFileEditor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/DefaultBinaryFileEditor.java
@@ -15,7 +15,12 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.content.IContentType;
@@ -30,6 +35,7 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.StorageDocumentProvider;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.ide.ResourceUtil;
+import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.cdt.core.IBinaryParser;
@@ -44,26 +50,25 @@ import org.eclipse.cdt.utils.Objdump;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/**
- * A readonly editor to view binary files. This default implementation displays
- * the GNU objdump output of the binary as plain text. If no objdump output can be
- * obtained, the binary content is displayed.
+ * A readonly editor to view binary files. This default implementation displays the GNU objdump output of the
+ * binary as plain text. If no objdump output can be obtained, the binary content is displayed.
*/
-public class DefaultBinaryFileEditor extends AbstractTextEditor {
+public class DefaultBinaryFileEditor extends AbstractTextEditor implements IResourceChangeListener {
/**
* A storage editor input for binary files.
*/
public static class BinaryFileEditorInput extends PlatformObject implements IStorageEditorInput {
-
private final IBinary fBinary;
private IStorage fStorage;
/**
* Create an editor input from the given binary.
+ *
* @param binary
*/
public BinaryFileEditorInput(IBinary binary) {
- fBinary= binary;
+ fBinary = binary;
}
/*
@@ -79,8 +84,8 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
*/
@Override
public ImageDescriptor getImageDescriptor() {
- IFile file= (IFile)fBinary.getResource();
- IContentType contentType= IDE.getContentType(file);
+ IFile file = (IFile) fBinary.getResource();
+ IContentType contentType = IDE.getContentType(file);
return PlatformUI.getWorkbench().getEditorRegistry()
.getImageDescriptor(file.getName(), contentType);
}
@@ -115,9 +120,11 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
@Override
public IStorage getStorage() throws CoreException {
if (fStorage == null) {
- IBinaryParser.IBinaryObject object= (IBinaryParser.IBinaryObject)fBinary.getAdapter(IBinaryParser.IBinaryObject.class);
+ IBinaryParser.IBinaryObject object = (IBinaryParser.IBinaryObject) fBinary
+ .getAdapter(IBinaryParser.IBinaryObject.class);
if (object != null) {
- IGnuToolFactory factory= (IGnuToolFactory) object.getBinaryParser().getAdapter(IGnuToolFactory.class);
+ IGnuToolFactory factory = (IGnuToolFactory) object.getBinaryParser().getAdapter(
+ IGnuToolFactory.class);
if (factory != null) {
Objdump objdump = factory.getObjdump(object.getPath());
if (objdump != null) {
@@ -143,37 +150,45 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
}
if (fStorage == null) {
// backwards compatibility
- fStorage= EditorUtility.getStorage(fBinary);
+ fStorage = EditorUtility.getStorage(fBinary);
if (fStorage == null) {
// fall back to binary content
- fStorage= (IFile)fBinary.getResource();
+ fStorage = (IFile) fBinary.getResource();
}
}
}
return fStorage;
}
-
}
/**
* A storage document provider for binary files.
*/
public static class BinaryFileDocumentProvider extends StorageDocumentProvider {
-
+
/*
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#createDocument(java.lang.Object)
*/
@Override
protected IDocument createDocument(Object element) throws CoreException {
- IFile file= ResourceUtil.getFile(element);
+ IFile file = ResourceUtil.getFile(element);
if (file != null) {
- ICElement cElement= CoreModel.getDefault().create(file);
+ ICElement cElement = CoreModel.getDefault().create(file);
if (cElement instanceof IBinary) {
- element= new BinaryFileEditorInput((IBinary)cElement);
+ element = new BinaryFileEditorInput((IBinary) cElement);
}
}
return super.createDocument(element);
}
+
+ @Override
+ public long getModificationStamp(Object element) {
+ if (element instanceof FileEditorInput) {
+ return ((FileEditorInput) element).getFile().getModificationStamp();
+ }
+ return 0;
+ }
+
/*
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isModifiable(java.lang.Object)
*/
@@ -181,6 +196,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
public boolean isModifiable(Object element) {
return false;
}
+
/*
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isReadOnly(java.lang.Object)
*/
@@ -188,22 +204,62 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
public boolean isReadOnly(Object element) {
return true;
}
-
+
}
public DefaultBinaryFileEditor() {
super();
setDocumentProvider(new BinaryFileDocumentProvider());
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
}
/*
- * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
+ * @see
+ * org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite
+ * , org.eclipse.jface.text.source.IVerticalRuler, int)
*/
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
- ISourceViewer sourceViewer= super.createSourceViewer(parent, ruler, styles);
+ ISourceViewer sourceViewer = super.createSourceViewer(parent, ruler, styles);
sourceViewer.setEditable(false);
return sourceViewer;
}
+ @Override
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ }
+
+ @Override
+ public void resourceChanged(final IResourceChangeEvent event) {
+ try {
+ if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
+ event.getDelta().accept(new IResourceDeltaVisitor() {
+ @Override
+ public boolean visit(IResourceDelta delta) {
+ if (delta.getResource().getName().equals(getEditorInput().getName())) {
+ refresh();
+ return false;
+ }
+ return true;
+ }
+ });
+ }
+ } catch (CoreException e) {
+ CUIPlugin.log(e);
+ }
+ }
+
+ protected void refresh() {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ doSetInput(getEditorInput());
+ } catch (CoreException e) {
+ CUIPlugin.log(e);
+ }
+ }
+ });
+ }
}

Back to the top