1
|
package eu.etaxonomy.taxeditor.editor.name.container;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.eclipse.core.resources.IMarker;
|
5
|
import org.eclipse.jface.text.Position;
|
6
|
import org.eclipse.jface.text.source.Annotation;
|
7
|
import org.eclipse.jface.text.source.IAnnotationPresentation;
|
8
|
import org.eclipse.swt.graphics.GC;
|
9
|
import org.eclipse.swt.graphics.Image;
|
10
|
import org.eclipse.swt.graphics.Point;
|
11
|
import org.eclipse.swt.graphics.RGB;
|
12
|
import org.eclipse.swt.graphics.Rectangle;
|
13
|
import org.eclipse.swt.widgets.Canvas;
|
14
|
|
15
|
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
|
16
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
17
|
|
18
|
/**
|
19
|
* <p>EditorAnnotation class.</p>
|
20
|
*
|
21
|
* @author n.hoffmann
|
22
|
* @version $Id: $
|
23
|
*/
|
24
|
public class EditorAnnotation extends Annotation implements IAnnotationPresentation {
|
25
|
private static final Logger logger = Logger
|
26
|
.getLogger(EditorAnnotation.class);
|
27
|
private final IMarker marker;
|
28
|
private String text;
|
29
|
private int line;
|
30
|
private Position position;
|
31
|
|
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
|
}
|
79
|
|
80
|
|
81
|
/**
|
82
|
* <p>Constructor for EditorAnnotation.</p>
|
83
|
*
|
84
|
* @param marker a org.eclipse.core.resources.IMarker object.
|
85
|
*/
|
86
|
public EditorAnnotation(IMarker marker) {
|
87
|
this.marker = marker;
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* <p>Constructor for EditorAnnotation.</p>
|
92
|
*
|
93
|
* @param line a int.
|
94
|
* @param text a {@link java.lang.String} object.
|
95
|
*/
|
96
|
public EditorAnnotation(int line, String text) {
|
97
|
this(EditorAnnotationType.ERROR, line, text);
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* <p>Constructor for EditorAnnotation.</p>
|
102
|
*
|
103
|
* @param type a {@link java.lang.String} object.
|
104
|
* @param line a int.
|
105
|
* @param text a {@link java.lang.String} object.
|
106
|
*/
|
107
|
public EditorAnnotation(EditorAnnotationType type, int line, String text) {
|
108
|
super(type.name(), false, text);
|
109
|
this.marker = null;
|
110
|
this.line = line;
|
111
|
this.text = text;
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* <p>Getter for the field <code>marker</code>.</p>
|
116
|
*
|
117
|
* @return a org.eclipse.core.resources.IMarker object.
|
118
|
*/
|
119
|
public IMarker getMarker() {
|
120
|
return marker;
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* <p>Getter for the field <code>line</code>.</p>
|
125
|
*
|
126
|
* @return a int.
|
127
|
*/
|
128
|
public int getLine() {
|
129
|
return line;
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* <p>Getter for the field <code>text</code>.</p>
|
134
|
*
|
135
|
* @return a {@link java.lang.String} object.
|
136
|
*/
|
137
|
@Override
|
138
|
public String getText() {
|
139
|
if (EditorAnnotationType.ERROR.name().equals(getType())) {
|
140
|
return "Error: " + text;
|
141
|
}
|
142
|
if (EditorAnnotationType.WARNING.name().equals(getType())) {
|
143
|
return "Warning: " + text;
|
144
|
}
|
145
|
return super.getText();
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* @return
|
150
|
*/
|
151
|
private Image getImage() {
|
152
|
return EditorAnnotationType.valueOf(getType()).image;
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* <p>getLayer</p>
|
157
|
*
|
158
|
* @return a int.
|
159
|
*/
|
160
|
public int getLayer() {
|
161
|
return 3;
|
162
|
}
|
163
|
|
164
|
|
165
|
/**
|
166
|
* <p>Getter for the field <code>position</code>.</p>
|
167
|
*
|
168
|
* @return a {@link org.eclipse.jface.text.Position} object.
|
169
|
*/
|
170
|
public Position getPosition() {
|
171
|
return position;
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* <p>Setter for the field <code>position</code>.</p>
|
176
|
*
|
177
|
* @param position a {@link org.eclipse.jface.text.Position} object.
|
178
|
*/
|
179
|
public void setPosition(Position position) {
|
180
|
this.position = position;
|
181
|
}
|
182
|
|
183
|
|
184
|
/** {@inheritDoc} */
|
185
|
public void paint(GC gc, Canvas canvas, Rectangle bounds) {
|
186
|
Point canvasSize= canvas.getSize();
|
187
|
|
188
|
int x= 0;
|
189
|
int y= bounds.y;
|
190
|
int w= canvasSize.x;
|
191
|
int h= bounds.height;
|
192
|
|
193
|
if (y + h > canvasSize.y)
|
194
|
h= canvasSize.y - y;
|
195
|
|
196
|
if (y < 0) {
|
197
|
h= h + y;
|
198
|
y= 0;
|
199
|
}
|
200
|
|
201
|
if (h <= 0)
|
202
|
return;
|
203
|
|
204
|
Image image = getImage();
|
205
|
|
206
|
if (image == null) {
|
207
|
return;
|
208
|
}
|
209
|
|
210
|
Rectangle r = image.getBounds();
|
211
|
|
212
|
int destX = x + w - r.width;
|
213
|
int destY = y + h - r.height;
|
214
|
|
215
|
gc.drawImage(image, 0, 0, r.width, r.height, destX, destY, r.width, r.height);
|
216
|
}
|
217
|
}
|