KickJava   Java API By Example, From Geeks To Geeks.

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


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.model.IProblem;
19 import org.eclipse.ant.internal.ui.model.IProblemRequestor;
20 import org.eclipse.jface.text.BadLocationException;
21 import org.eclipse.jface.text.Position;
22 import org.eclipse.jface.text.source.AnnotationModel;
23 import org.eclipse.jface.text.source.AnnotationModelEvent;
24
25 public class AntExternalAnnotationModel extends AnnotationModel implements IProblemRequestor {
26
27     private List JavaDoc fGeneratedAnnotations= new ArrayList JavaDoc();
28     private List JavaDoc fCollectedProblems= new ArrayList JavaDoc();
29
30     /* (non-Javadoc)
31      * @see org.eclipse.ant.internal.ui.editor.outline.IProblemRequestor#acceptProblem(org.eclipse.ant.internal.ui.editor.outline.IProblem)
32      */

33     public void acceptProblem(IProblem problem) {
34         fCollectedProblems.add(problem);
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.ant.internal.ui.editor.outline.IProblemRequestor#acceptProblem(org.eclipse.ant.internal.ui.editor.outline.IProblem)
39      */

40     public void endReporting() {
41         boolean temporaryProblemsChanged= false;
42             
43         synchronized (getAnnotationMap()) {
44                 
45             if (fGeneratedAnnotations.size() > 0) {
46                 temporaryProblemsChanged= true;
47                 removeAnnotations(fGeneratedAnnotations, false, true);
48                 fGeneratedAnnotations.clear();
49             }
50                 
51             if (fCollectedProblems != null && fCollectedProblems.size() > 0) {
52                 Iterator JavaDoc e= fCollectedProblems.iterator();
53                 while (e.hasNext()) {
54                         
55                     IProblem problem= (IProblem) e.next();
56                         
57                     Position position= createPositionFromProblem(problem);
58                     if (position != null) {
59                             
60                         XMLProblemAnnotation annotation= new XMLProblemAnnotation(problem);
61                         fGeneratedAnnotations.add(annotation);
62                         try {
63                             addAnnotation(annotation, position, false);
64                         } catch (BadLocationException ex) {
65                             AntUIPlugin.log(ex);
66                         }
67                             
68                         temporaryProblemsChanged= true;
69                     }
70                 }
71                     
72                 fCollectedProblems.clear();
73             }
74         }
75                 
76         if (temporaryProblemsChanged)
77             fireModelChanged(new AnnotationModelEvent(this));
78     }
79                     
80     protected Position createPositionFromProblem(IProblem problem) {
81         int start= problem.getOffset();
82         if (start >= 0) {
83             int length= problem.getLength();
84                 
85             if (length >= 0)
86                 return new Position(start, length);
87         }
88
89         return null;
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.ant.internal.ui.model.IProblemRequestor#beginReporting()
94      */

95     public void beginReporting() {
96     }
97 }
98
Popular Tags