Fixed annotations problem.
authorp.ciardelli <p.ciardelli@localhost>
Wed, 9 Sep 2009 14:21:35 +0000 (14:21 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Wed, 9 Sep 2009 14:21:35 +0000 (14:21 +0000)
.gitattributes
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorAnnotation.java [new file with mode: 0644]
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameViewer.java

index 17220c913374d1d3f967f519ca4d6b3ca43d4f71..d21338a0a29271f18d9307bcc652fa0cdc78453e 100644 (file)
@@ -714,6 +714,7 @@ taxeditor-editor/pom.xml -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditor.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/CompositeBorderDecorator.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/DuplicateArbitrator.java -text
+taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorAnnotation.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/ErrorAnnotation.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/FreeTextElementFactory.java -text
diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorAnnotation.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorAnnotation.java
new file mode 100644 (file)
index 0000000..3471cfa
--- /dev/null
@@ -0,0 +1,119 @@
+package eu.etaxonomy.taxeditor.editor;\r
+\r
+import org.eclipse.core.resources.IMarker;\r
+import org.eclipse.jface.text.Position;\r
+import org.eclipse.jface.text.source.Annotation;\r
+import org.eclipse.jface.text.source.IAnnotationPresentation;\r
+import org.eclipse.swt.graphics.GC;\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.graphics.Rectangle;\r
+import org.eclipse.swt.widgets.Canvas;\r
+\r
+import eu.etaxonomy.taxeditor.model.ImageResources;\r
+\r
+public class EditorAnnotation extends Annotation implements IAnnotationPresentation {\r
+    private IMarker marker;\r
+    private String text;\r
+    private int line;\r
+    private Position position;\r
+\r
+    // error identifiers, images and colors\r
+    public static String ERROR_TYPE = "editor.error.type";\r
+    public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON);\r
+    public static final RGB ERROR_RGB = new RGB(255, 0, 0);    \r
+    \r
+    public static String WARNING_TYPE = "editor.warning.type";\r
+    public static Image WARNING_IMAGE = ImageResources.getImage(ImageResources.WARNING_ANNOTATION_ICON);\r
+    public static final RGB WARNING_RGB = new RGB(244, 200, 45); \r
+    \r
+    public EditorAnnotation(IMarker marker) {\r
+        this.marker = marker;\r
+    }\r
+\r
+    public EditorAnnotation(int line, String text) {\r
+       this(ERROR_TYPE, line, text);\r
+    }\r
+\r
+    public EditorAnnotation(String type, int line, String text) {\r
+       super(type, false, text);\r
+        this.marker = null;\r
+        this.line = line;\r
+        this.text = text;\r
+    }\r
+    \r
+    public IMarker getMarker() {\r
+        return marker;\r
+    }\r
+\r
+    public int getLine() {\r
+        return line;\r
+    }\r
+\r
+    public String getText() {\r
+       if (ERROR_TYPE.equals(getType())) {\r
+               return "Error: " + text;\r
+       }\r
+       if (WARNING_TYPE.equals(getType())) {\r
+               return "Warning: " + text;\r
+       }\r
+       return super.getText();\r
+    }\r
+\r
+       /**\r
+        * @return\r
+        */\r
+       private Image getImage() {\r
+       if (ERROR_TYPE.equals(getType())) {\r
+               return ERROR_IMAGE;\r
+       }\r
+       if (WARNING_TYPE.equals(getType())) {\r
+               return WARNING_IMAGE;\r
+       }\r
+               return null;\r
+       }\r
+    \r
+    public int getLayer() {\r
+        return 3;\r
+    }\r
+\r
+\r
+    public Position getPosition() {\r
+        return position;\r
+    }\r
+\r
+    public void setPosition(Position position) {\r
+        this.position = position;\r
+    }\r
+\r
+       \r
+       public void paint(GC gc, Canvas canvas, Rectangle bounds) {\r
+               Point canvasSize= canvas.getSize();\r
+\r
+               int x= 0;\r
+               int y= bounds.y;\r
+               int w= canvasSize.x;\r
+               int h= bounds.height;\r
+\r
+               if (y + h > canvasSize.y)\r
+                       h= canvasSize.y - y;\r
+\r
+               if (y < 0) {\r
+                       h= h + y;\r
+                       y= 0;\r
+               }\r
+\r
+               if (h <= 0)\r
+                       return;\r
+\r
+               Image image = getImage();\r
+               \r
+               Rectangle r = image.getBounds();\r
+               \r
+               int destX = x + w - r.width;\r
+               int destY = y + h - r.height;\r
+               \r
+               gc.drawImage(image, 0, 0, r.width, r.height, destX, destY, r.width, r.height);\r
+       }\r
+}
\ No newline at end of file
index bada0fdfa531d486db9593252afb41c78c2986b5..f7311c76b787dd127f335505a3b0d6b240c4ed74 100644 (file)
@@ -287,13 +287,12 @@ public abstract class NameComposite<T extends TaxonBase> extends GroupedComposit
        \r
        public abstract void setName(TaxonNameBase name);\r
        \r
-       synchronized protected void calculateErrors() {\r
+       protected void calculateErrors() {\r
                textViewer.clearErrors();\r
                \r
                TaxonNameBase name = getParsedName() != null ? getParsedName() : getName();\r
                \r
-//             textViewer.setShowParsingErrors(name);\r
-               textViewer.setShowParsingError(name);\r
+               textViewer.setShowParsingErrors(name);\r
        }\r
 \r
        protected void handleSplitText(String text) {\r
index a2856fbcf0f9bdbe45d1e6fb931f668160971053..76a4b7140e1006d033bbc9cafa10b8d03113e720 100644 (file)
@@ -46,10 +46,9 @@ import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;\r
-import eu.etaxonomy.taxeditor.editor.ErrorAnnotation;\r
+import eu.etaxonomy.taxeditor.editor.EditorAnnotation;\r
 import eu.etaxonomy.taxeditor.editor.LineWrapSquigglesStrategy;\r
 import eu.etaxonomy.taxeditor.editor.ViewerConfiguration;\r
-import eu.etaxonomy.taxeditor.editor.WarningAnnotation;\r
 import eu.etaxonomy.taxeditor.model.Resources;\r
 \r
 /**\r
@@ -146,14 +145,14 @@ public class NameViewer extends SourceViewer {
                annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());\r
                \r
                // Add ability to paint red squigglies\r
-               annotationPainter.addAnnotationType(ErrorAnnotation.ERROR_TYPE, LineWrapSquigglesStrategy.ID);\r
-               annotationPainter.setAnnotationTypeColor(ErrorAnnotation.ERROR_TYPE, \r
-                               new Color(Display.getDefault(), ErrorAnnotation.ERROR_RGB));\r
+               annotationPainter.addAnnotationType(EditorAnnotation.ERROR_TYPE, LineWrapSquigglesStrategy.ID);\r
+               annotationPainter.setAnnotationTypeColor(EditorAnnotation.ERROR_TYPE, \r
+                               new Color(Display.getDefault(), EditorAnnotation.ERROR_RGB));\r
 \r
                // Add ability to paint yellow squigglies\r
-               annotationPainter.addAnnotationType(WarningAnnotation.WARNING_TYPE, LineWrapSquigglesStrategy.ID);\r
-               annotationPainter.setAnnotationTypeColor(WarningAnnotation.WARNING_TYPE, \r
-                               new Color(Display.getDefault(), WarningAnnotation.WARNING_RGB));\r
+               annotationPainter.addAnnotationType(EditorAnnotation.WARNING_TYPE, LineWrapSquigglesStrategy.ID);\r
+               annotationPainter.setAnnotationTypeColor(EditorAnnotation.WARNING_TYPE, \r
+                               new Color(Display.getDefault(), EditorAnnotation.WARNING_RGB));\r
                \r
                this.addPainter(annotationPainter);\r
        }\r
@@ -163,7 +162,7 @@ public class NameViewer extends SourceViewer {
                Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();\r
                while (annotations.hasNext()) {\r
                        Annotation annotation = annotations.next(); \r
-                       if (annotation.getType().equals(ErrorAnnotation.ERROR_TYPE) || annotation.getType().equals(WarningAnnotation.WARNING_TYPE)) {\r
+                       if (annotation.getType().equals(EditorAnnotation.ERROR_TYPE) || annotation.getType().equals(EditorAnnotation.WARNING_TYPE)) {\r
                                this.getAnnotationModel().removeAnnotation(annotation);\r
                        }\r
                }\r
@@ -177,73 +176,14 @@ public class NameViewer extends SourceViewer {
         * @param name\r
         */\r
        public void setShowParsingErrors(TaxonNameBase<?, ?> name) {\r
-               \r
-//             testMarkers();\r
-               \r
-               if (0 == 0) {\r
-                       return;\r
-               }\r
-               \r
-               for (ParserProblem problem : name.getParsingProblems()) {\r
-                       \r
-//                     boolean hasProblem = name.getHasProblem();\r
-                       \r
-//                     if (!hasProblem) {\r
-//                             logger.debug(name.getProblemStarts());\r
-//                     }\r
-//                     \r
-                       String text = this.getTextWidget().getText();\r
-//                                                     \r
-//                     if (hasProblem && text.length() > 0) {\r
-                       \r
-                       int start = 0;\r
-                       int length = 0;\r
-                       if (text.length() >= 0) {                               \r
-                               start = name.getProblemStarts();\r
-                               length = name.getProblemEnds() - start;\r
-                       \r
-                               if (start == -1 || name.getProblemEnds() == -1) {\r
-                                       continue;\r
-                               }\r
                                \r
-                               // Don't let squigglies try to draw beyond the end of the text\r
-                               if (text.length() < start + length) {\r
-                                       length = text.length() - start;\r
-                               }\r
-                       }\r
-\r
-                       Annotation annotation = null;\r
-//                     if (problem.isWarning()) {\r
-//                             annotation = new WarningAnnotation(0, problem.toString());\r
-//                     }\r
-                       if (problem.isError()) {\r
-                               annotation = new ErrorAnnotation(0, problem.toString());\r
-                       }\r
-                       \r
-                       this.getAnnotationModel().addAnnotation(\r
-                                       annotation, \r
-                                       new Position(start, length));\r
-//                     }\r
-               }\r
-       }\r
-\r
-       public void setShowParsingError(TaxonNameBase<?, ?> name) {\r
-               \r
-//             testMarkers();\r
-               \r
-               if (!name.hasProblem()) {\r
-                       logger.debug(name.getProblemStarts());\r
-               }\r
-               \r
                String text = this.getTextWidget().getText();\r
                                                \r
                if (name.hasProblem() && text.length() > 0) {\r
-//                     logger.warn("Name: " + name.getTitleCache() + ", start: " + name.getProblemStarts()+ ", end: " + name.getProblemEnds());\r
                        int start = name.getProblemStarts();\r
                        int length = name.getProblemEnds() - start;\r
                        \r
                        if (start == -1 || name.getProblemEnds() == -1) {\r
-//                             logger.warn("Start: " + start + ", End " + name.getProblemEnds());\r
                                return;\r
                        }\r
                        \r
@@ -252,12 +192,26 @@ public class NameViewer extends SourceViewer {
                                length = text.length() - start;\r
                        }\r
                        \r
-                       this.getAnnotationModel().addAnnotation(\r
-                                       new ErrorAnnotation(0, "Error parsing string '" + text + "'"), \r
-                                       new Position(start, length));\r
+                       for (ParserProblem problem : name.getParsingProblems()) {\r
+                               \r
+                               String type = null;\r
+                               if (problem.isWarning()) {\r
+                                       type = EditorAnnotation.WARNING_TYPE;\r
+                               }\r
+                               if (problem.isError()) {\r
+                                       type = EditorAnnotation.ERROR_TYPE;\r
+                               }\r
+                               if (type == null) {\r
+                                       continue;\r
+                               }\r
+                               this.getAnnotationModel().addAnnotation(\r
+                                               new EditorAnnotation(type, 0, problem.toString()), \r
+                                               new Position(start, length));\r
+                       }\r
                }\r
        }\r
        \r
+       \r
        public void setShowSecError(Taxon taxon) {\r
                \r
                // If taxon has no sec, show an annotation\r
@@ -266,7 +220,7 @@ public class NameViewer extends SourceViewer {
                        String text = "This taxon requires a sec. reference.";\r
                        \r
                        this.getAnnotationModel().addAnnotation(\r
-                                       new ErrorAnnotation(0, text),\r
+                                       new EditorAnnotation(0, text),\r
                                        new Position(0, 0));\r
 //                                     new Position(0, getTextWidget().getText().length()));\r
                }\r