Revision 707b6237
Added by Niels Hoffmann over 12 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/EditorAnnotation.java | ||
---|---|---|
12 | 12 |
import org.eclipse.swt.graphics.Rectangle; |
13 | 13 |
import org.eclipse.swt.widgets.Canvas; |
14 | 14 |
|
15 |
import eu.etaxonomy.cdm.strategy.parser.ParserProblem; |
|
15 | 16 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
16 | 17 |
|
17 | 18 |
/** |
... | ... | |
23 | 24 |
public class EditorAnnotation extends Annotation implements IAnnotationPresentation { |
24 | 25 |
private static final Logger logger = Logger |
25 | 26 |
.getLogger(EditorAnnotation.class); |
26 |
private IMarker marker; |
|
27 |
private final IMarker marker;
|
|
27 | 28 |
private String text; |
28 | 29 |
private int line; |
29 | 30 |
private Position position; |
30 | 31 |
|
31 |
// error identifiers, images and colors |
|
32 |
/** Constant <code>ERROR_TYPE="editor.error.type"</code> */ |
|
33 |
public static String ERROR_TYPE = "editor.error.type"; |
|
34 |
/** Constant <code>ERROR_IMAGE</code> */ |
|
35 |
public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON); |
|
36 |
/** Constant <code>ERROR_RGB</code> */ |
|
37 |
public static final RGB ERROR_RGB = new RGB(255, 0, 0); |
|
32 |
public enum EditorAnnotationType{ |
|
33 |
WARNING(ImageResources.WARNING_ANNOTATION_ICON, 244, 200, 45), |
|
34 |
ERROR(ImageResources.ERROR_ANNOTATION_ICON, 255, 0, 0); |
|
35 |
|
|
36 |
public Image image; |
|
37 |
public RGB color; |
|
38 |
|
|
39 |
EditorAnnotationType(String imageResource, int r, int g, int b){ |
|
40 |
image = ImageResources.getImage(imageResource); |
|
41 |
color = new RGB(r, g, b); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* @param problem |
|
46 |
* @return |
|
47 |
*/ |
|
48 |
public static EditorAnnotationType getTypeByProblem( |
|
49 |
ParserProblem problem) { |
|
50 |
if (problem.isWarning()) { |
|
51 |
return WARNING; |
|
52 |
}else if (problem.isError()) { |
|
53 |
return ERROR; |
|
54 |
} |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
// // error identifiers, images and colors |
|
61 |
// /** Constant <code>ERROR_TYPE="editor.error.type"</code> */ |
|
62 |
// public static String ERROR_TYPE = "editor.error.type"; |
|
63 |
// /** Constant <code>ERROR_IMAGE</code> */ |
|
64 |
// public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON); |
|
65 |
// /** Constant <code>ERROR_RGB</code> */ |
|
66 |
// public static final RGB ERROR_RGB = new RGB(255, 0, 0); |
|
67 |
// |
|
68 |
// /** Constant <code>WARNING_TYPE="editor.warning.type"</code> */ |
|
69 |
// public static String WARNING_TYPE = "editor.warning.type"; |
|
70 |
// /** Constant <code>WARNING_IMAGE</code> */ |
|
71 |
// public static Image WARNING_IMAGE = ImageResources.getImage(ImageResources.WARNING_ANNOTATION_ICON); |
|
72 |
// /** Constant <code>WARNING_RGB</code> */ |
|
73 |
// public static final RGB WARNING_RGB = new RGB(244, 200, 45); |
|
74 |
|
|
75 |
|
|
76 |
public EditorAnnotation(ParserProblem problem){ |
|
77 |
this(EditorAnnotationType.getTypeByProblem(problem), 0, problem.getMessage()); |
|
78 |
} |
|
38 | 79 |
|
39 |
/** Constant <code>WARNING_TYPE="editor.warning.type"</code> */ |
|
40 |
public static String WARNING_TYPE = "editor.warning.type"; |
|
41 |
/** Constant <code>WARNING_IMAGE</code> */ |
|
42 |
public static Image WARNING_IMAGE = ImageResources.getImage(ImageResources.WARNING_ANNOTATION_ICON); |
|
43 |
/** Constant <code>WARNING_RGB</code> */ |
|
44 |
public static final RGB WARNING_RGB = new RGB(244, 200, 45); |
|
45 | 80 |
|
46 | 81 |
/** |
47 | 82 |
* <p>Constructor for EditorAnnotation.</p> |
... | ... | |
59 | 94 |
* @param text a {@link java.lang.String} object. |
60 | 95 |
*/ |
61 | 96 |
public EditorAnnotation(int line, String text) { |
62 |
this(ERROR_TYPE, line, text);
|
|
97 |
this(EditorAnnotationType.ERROR, line, text);
|
|
63 | 98 |
} |
64 | 99 |
|
65 | 100 |
/** |
... | ... | |
69 | 104 |
* @param line a int. |
70 | 105 |
* @param text a {@link java.lang.String} object. |
71 | 106 |
*/ |
72 |
public EditorAnnotation(String type, int line, String text) {
|
|
73 |
super(type, false, text); |
|
107 |
public EditorAnnotation(EditorAnnotationType type, int line, String text) {
|
|
108 |
super(type.name(), false, text);
|
|
74 | 109 |
this.marker = null; |
75 | 110 |
this.line = line; |
76 | 111 |
this.text = text; |
... | ... | |
99 | 134 |
* |
100 | 135 |
* @return a {@link java.lang.String} object. |
101 | 136 |
*/ |
102 |
public String getText() { |
|
103 |
if (ERROR_TYPE.equals(getType())) { |
|
137 |
@Override |
|
138 |
public String getText() { |
|
139 |
if (EditorAnnotationType.ERROR.name().equals(getType())) { |
|
104 | 140 |
return "Error: " + text; |
105 | 141 |
} |
106 |
if (WARNING_TYPE.equals(getType())) {
|
|
142 |
if (EditorAnnotationType.WARNING.name().equals(getType())) {
|
|
107 | 143 |
return "Warning: " + text; |
108 | 144 |
} |
109 | 145 |
return super.getText(); |
... | ... | |
113 | 149 |
* @return |
114 | 150 |
*/ |
115 | 151 |
private Image getImage() { |
116 |
if (ERROR_TYPE.equals(getType())) { |
|
117 |
return ERROR_IMAGE; |
|
118 |
} |
|
119 |
if (WARNING_TYPE.equals(getType())) { |
|
120 |
return WARNING_IMAGE; |
|
121 |
} |
|
122 |
logger.warn("No image for type " + getType()); |
|
123 |
return null; |
|
152 |
return EditorAnnotationType.valueOf(getType()).image; |
|
124 | 153 |
} |
125 | 154 |
|
126 | 155 |
/** |
Also available in: Unified diff
Merged with trunk