1 11 package org.eclipse.ant.internal.ui.editor.text; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.ant.internal.ui.AntUIPlugin; 18 import org.eclipse.ant.internal.ui.debug.IAntDebugConstants; 19 import org.eclipse.ant.internal.ui.editor.outline.AntEditorMarkerUpdater; 20 import org.eclipse.ant.internal.ui.model.IProblem; 21 import org.eclipse.ant.internal.ui.model.IProblemRequestor; 22 import org.eclipse.core.resources.IFile; 23 import org.eclipse.core.resources.IMarker; 24 import org.eclipse.jface.text.BadLocationException; 25 import org.eclipse.jface.text.Position; 26 import org.eclipse.jface.text.source.AnnotationModelEvent; 27 import org.eclipse.ui.editors.text.EditorsUI; 28 import org.eclipse.ui.texteditor.MarkerAnnotation; 29 import org.eclipse.ui.texteditor.MarkerUtilities; 30 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; 31 32 public class AntAnnotationModel extends ResourceMarkerAnnotationModel implements IProblemRequestor { 33 34 private List fGeneratedAnnotations= new ArrayList (); 35 private List fCollectedProblems= new ArrayList (); 36 37 public AntAnnotationModel(IFile file) { 38 super(file); 39 } 40 41 44 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) { 45 String markerType= MarkerUtilities.getMarkerType(marker); 46 if (AntEditorMarkerUpdater.BUILDFILE_PROBLEM_MARKER.equals(markerType)) { 47 return null; 51 } 52 return new MarkerAnnotation(EditorsUI.getAnnotationTypeLookup().getAnnotationType(marker), marker); 53 } 54 55 protected Position createPositionFromProblem(IProblem problem) { 56 int start= problem.getOffset(); 57 if (start >= 0) { 58 int length= problem.getLength(); 59 60 if (length >= 0) 61 return new Position(start, length); 62 } 63 64 return null; 65 } 66 67 70 public void acceptProblem(IProblem problem) { 71 fCollectedProblems.add(problem); 72 } 73 74 77 public void beginReporting() { 78 } 79 80 83 public void endReporting() { 84 boolean temporaryProblemsChanged= false; 85 86 synchronized (getAnnotationMap()) { 87 88 if (fGeneratedAnnotations.size() > 0) { 89 temporaryProblemsChanged= true; 90 removeAnnotations(fGeneratedAnnotations, false, true); 91 fGeneratedAnnotations.clear(); 92 } 93 94 if (fCollectedProblems != null && fCollectedProblems.size() > 0) { 95 Iterator e= fCollectedProblems.iterator(); 96 while (e.hasNext()) { 97 98 IProblem problem= (IProblem) e.next(); 99 100 Position position= createPositionFromProblem(problem); 101 if (position != null) { 102 103 XMLProblemAnnotation annotation= new XMLProblemAnnotation(problem); 104 fGeneratedAnnotations.add(annotation); 105 try { 106 addAnnotation(annotation, position, false); 107 } catch (BadLocationException ex) { 108 AntUIPlugin.log(ex); 109 } 110 111 temporaryProblemsChanged= true; 112 } 113 } 114 115 fCollectedProblems.clear(); 116 } 117 } 118 119 if (temporaryProblemsChanged) 120 fireModelChanged(new AnnotationModelEvent(this)); 121 } 122 123 126 protected boolean isAcceptable(IMarker marker) { 127 if (super.isAcceptable(marker)) { 128 return !marker.getAttribute(IAntDebugConstants.ANT_RUN_TO_LINE, false); 129 } 130 return false; 131 } 132 } 133 | Popular Tags |