KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > text > AntAnnotationModel


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.editor.text;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
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 JavaDoc fGeneratedAnnotations= new ArrayList JavaDoc();
35     private List JavaDoc fCollectedProblems= new ArrayList JavaDoc();
36     
37     public AntAnnotationModel(IFile file) {
38         super(file);
39     }
40
41     /*
42      * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#createMarkerAnnotation(org.eclipse.core.resources.IMarker)
43      */

44     protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
45         String JavaDoc markerType= MarkerUtilities.getMarkerType(marker);
46         if (AntEditorMarkerUpdater.BUILDFILE_PROBLEM_MARKER.equals(markerType)) {
47             //we currently do not show Ant buildfile problem markers in the Ant editor as we have no notion of
48
//annotation overlays
49
//bug
50
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     /* (non-Javadoc)
68      * @see org.eclipse.ant.internal.ui.editor.outline.IProblemRequestor#acceptProblem(org.eclipse.ant.internal.ui.editor.outline.IProblem)
69      */

70     public void acceptProblem(IProblem problem) {
71         fCollectedProblems.add(problem);
72     }
73     
74     /* (non-Javadoc)
75      * @see org.eclipse.ant.internal.ui.editor.outline.IProblemRequestor#acceptProblem(org.eclipse.ant.internal.ui.editor.outline.IProblem)
76      */

77     public void beginReporting() {
78     }
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.ant.internal.ui.editor.outline.IProblemRequestor#acceptProblem(org.eclipse.ant.internal.ui.editor.outline.IProblem)
82      */

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 JavaDoc 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     /* (non-Javadoc)
124      * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#isAcceptable(org.eclipse.core.resources.IMarker)
125      */

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