Monday, January 28, 2008

Fnding markers in a workspace : eclipse

If you have a marker or you know a marker id :

let the id be : org.my.marker

then all markers of that type can be easily found . The way to found those markers is :

IWorkspaceRoot root = ResourcePlugin.getWorkspace().getRoot();
root.findMarkers("org.my.marker",false,IResource.DEPTH_INFINITE);

To create a marker :

getProject().createMarker("org.my.marker",false,IResource.DEPTH_INFINITE);

generally since workspace changes are expensive , an IWorkspaceRunnable should be used
to batch many workspace operations together .

IWorkspaceRunnable runnable = new IWorkspaceRunnable(){
public void run(IProgressMonitor monitor) {
IMarker marker = resource.createMarker(markerId);
setAttributes(marker);

}

};


the setAttributes method sets the marker . This generally boild down to populating a hashtable
and setting it .

resource.getWorkspace().run(runnable , null);

An imageProvider can be specified in the marker definition to define an image for the marker .

No comments: