niedziela, 13 grudnia 2015

Eclipse Plugin - How to add error validation markers for

Register org.eclipse.core.resources.markers extension point
 
  
  
  
  
 
Declare constant (optional)
interface Constants {
     String MARKER_VALIDATION_ERROR = "org.myapp.validation.problem";
}
Delete all validation markers for assigned to processed file.

 private static boolean deleteMarkers(IFile file) {
  int markersCount = 0;
  try {
   markersCount = file.findMarkers(Constants.MARKER_VALIDATION_ERROR, false, IResource.DEPTH_ZERO).length;
   file.deleteMarkers(Constants.MARKER_VALIDATION_ERROR, false, IResource.DEPTH_ZERO);
  } catch (CoreException e) {
   throw Throwables.propagate(e);
  }
  return markersCount > 0;
 }

Compute and add new validation marker:
 private static void addMarker(IFile file, String message, int severity, ModelObject model, Expression expression) throws CoreException {
  IMarker marker = file.createMarker(Constants.MARKER_VALIDATION_ERROR);
  marker.setAttribute(IMarker.MESSAGE, message);
  marker.setAttribute(IMarker.SEVERITY, severity);
  marker.setAttribute(IMarker.SOURCE_ID, model.getId());
  logger.debug("Marker created: " + file + ", attr: " + marker.getAttributes().keySet());
 }

Brak komentarzy:

Prześlij komentarz