1 package eu
.etaxonomy
.taxeditor
.prototype2
.view
;
3 import java
.util
.Iterator
;
5 import org
.eclipse
.jface
.text
.Document
;
6 import org
.eclipse
.jface
.text
.Position
;
7 import org
.eclipse
.jface
.text
.source
.Annotation
;
8 import org
.eclipse
.jface
.text
.source
.AnnotationModel
;
9 import org
.eclipse
.jface
.text
.source
.AnnotationPainter
;
10 import org
.eclipse
.jface
.text
.source
.IAnnotationAccess
;
11 import org
.eclipse
.jface
.text
.source
.SourceViewer
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.graphics
.Color
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Display
;
17 import eu
.etaxonomy
.taxeditor
.prototype2
.view
.nameviewersupport
.AnnotationMarkerAccess
;
18 import eu
.etaxonomy
.taxeditor
.prototype2
.view
.nameviewersupport
.ErrorAnnotation
;
19 import eu
.etaxonomy
.taxeditor
.prototype2
.view
.nameviewersupport
.WarningAnnotation
;
22 * SourceViewer implementation called by NameEditorView.
27 public class NameViewer
extends SourceViewer
{
29 public NameViewer(Composite parent
) {
30 super(parent
, null, SWT
.WRAP
| SWT
.MULTI
| SWT
.RESIZE
);
32 // Set name viewer's text to name cache
33 this.setDocument(new Document(""), new AnnotationModel());
35 // Annotations section
36 IAnnotationAccess fAnnotationAccess
= new AnnotationMarkerAccess();
38 // To paint the annotations
39 AnnotationPainter annotationPainter
= new AnnotationPainter(this, fAnnotationAccess
);
41 // Add ability to paint red squigglies
42 annotationPainter
.addAnnotationType(ErrorAnnotation
.ERROR_TYPE
);
43 annotationPainter
.setAnnotationTypeColor(ErrorAnnotation
.ERROR_TYPE
,
44 new Color(Display
.getDefault(), ErrorAnnotation
.ERROR_RGB
));
46 // Add ability to paint yellow squigglies
47 annotationPainter
.addAnnotationType(WarningAnnotation
.WARNING_TYPE
);
48 annotationPainter
.setAnnotationTypeColor(WarningAnnotation
.WARNING_TYPE
,
49 new Color(Display
.getDefault(), WarningAnnotation
.WARNING_RGB
));
51 this.addPainter(annotationPainter
);
54 public void setShowError(boolean hasProblem
) {
56 String text
= this.getTextWidget().getText();
58 Iterator
<Annotation
> annotations
= this.getAnnotationModel().getAnnotationIterator();
59 while (annotations
.hasNext()) {
60 Annotation annotation
= annotations
.next();
61 if (annotation
.getType().equals(ErrorAnnotation
.ERROR_TYPE
))
62 this.getAnnotationModel().removeAnnotation(annotation
);
65 // Failed attempt to get multi-line squigglies drawn
66 if (hasProblem
&& text
.length() > 0) {
67 for (int i
= 1; i
<= this.getTextWidget().getLineCount(); i
++) {
68 this.getAnnotationModel().addAnnotation(
69 new ErrorAnnotation(i
, "Could not parse name."),
70 new Position(0, text
.length()));