--- /dev/null
+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
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
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
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
* @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
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
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