Sunday, January 3, 2010

Eclipse : Tips - How to find an existing problem-marker ?

protected void removeMarkers(EObject target, IValidationContext ctx) {
IFile file = WorkspaceSynchronizer.getFile(target.eResource());
try {
IMarker[] markers = file.findMarkers(MARKER_ID, true, IFile.DEPTH_INFINITE);
for (IMarker marker : markers) {
String markerId = marker.getAttribute(IIssue.ID, "unknown");
if(markerId.equals(ctx.getCurrentConstraintId())){
marker.delete();
}
}
} catch (CoreException e) {
e.printStackTrace();
}
}

protected boolean markerExists(EObject target, IValidationContext ctx){
IFile file = WorkspaceSynchronizer.getFile(target.eResource());
try {
IMarker[] markers = file.findMarkers(MARKER_ID, true, IFile.DEPTH_INFINITE);
for (IMarker marker : markers) {
String markerId = marker.getAttribute(IIssue.ID, "unknown");
if(markerId.equals(ctx.getCurrentConstraintId())){
return true;
}
}
} catch (CoreException e) {
e.printStackTrace();
}
return false;
}

No comments: