Reputation: 715
I'm writing a custom editor in Eclipse and just integrated custom error recognition. Now I'm facing a strange issue: I can add Markers to my editor that get displayed all fine, I can also delete them while the editor is running.
What doesn't work: When I close my editor I want the markers to disappear/get deleted.
What I'm doing right now, is
creating the Markers with the transient property set like this: marker.setAttribute(IMarker.TRANSIENT, true);
This doesn't seem to change anything though.
trying to delete all Annotations via the source viewers annotation-model. This doesn't work, cause when I try to hook into my editors dispose()
method or add a DisposeListener
to my sourceviewers textwidget, the sourceviewer already has been disposed of and getSourceViewer().getAnnotationModel();
returns null
.
My deleteMarkers
method:
private void deleteMarkers() {
IAnnotationModel anmod = getSourceViewer().getAnnotationModel();
Iterator<Annotation> it = anmod.getAnnotationIterator();
while (it.hasNext()) {
SimpleMarkerAnnotation a = (SimpleMarkerAnnotation) it.next();
anmod.removeAnnotation(a);
try {
a.getMarker().delete();
} catch (CoreException e) {
e.printStackTrace();
}
}
}
Any help is appreciated ^^
Upvotes: 3
Views: 143
Reputation: 3502
Hook into your editor close event, get a reference to the IResource for the editor (i believe you get can that on IEditorInput) and call IResource#deleteMarkers() on the relevant resource which will delete them when you close your editor. By design eclipse does not delete markers when editors are closed.
Here is some reference: http://help.eclipse.org/kepler/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/resources/IResource.html#deleteMarkers(java.lang.String, boolean, int)
Upvotes: 3