Posts Tagged markers

Eclipse Plugin: Listening to Marker Deletions

Today I was desperately trying to figure out how to get eclipse to tell me when a Bookmark had been deleted, so that I could update my plugins internal data representation.

I found lots of api’s which was all well and good but finding a code example was a lot harder. Also the guys on the irc channel were too busy to help, so I kept searching.

It turns out that you need to fiddle with the IResourceChangeListener and IResourceDeltaVisitor to traverse a delta (basically a tree representation of all the changes that have just occurred) and look for your bookmarks.

Below is example code for creating a listener, visitor and how to attach it to the workspace as a change listener.

	// this listener deals with handling changes to markers.
	private static IResourceChangeListener markerListener =  new IResourceChangeListener() {
				private MarkerChangeVisitor fVisitor = new MarkerChangeVisitor();

				public void resourceChanged(IResourceChangeEvent event) {
		           IResourceDelta delta= event.getDelta();
		           if (delta != null)
		           {
		                try {
		                    delta.accept(fVisitor);
		                } catch (CoreException ce) {

		                }
				   }
				   }
		   };

Read the rest of this entry »

, , , , ,

2 Comments