Jakob Sachs
Jakob Sachs

Reputation: 715

How to delete IMarkers after editor closed ( or why isnt the IMarker.TRANSIENT property working)?

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

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

Answers (1)

Duncan Krebs
Duncan Krebs

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

Related Questions