1
|
package eu.etaxonomy.taxeditor.singlesource.editor.name.container;
|
2
|
|
3
|
import javax.naming.OperationNotSupportedException;
|
4
|
|
5
|
import org.apache.log4j.Logger;
|
6
|
import org.eclipse.core.resources.IMarker;
|
7
|
import org.eclipse.jface.text.Position;
|
8
|
import org.eclipse.jface.text.source.Annotation;
|
9
|
import org.eclipse.jface.text.source.IAnnotationPresentation;
|
10
|
import org.eclipse.swt.graphics.GC;
|
11
|
import org.eclipse.swt.graphics.Image;
|
12
|
import org.eclipse.swt.graphics.Point;
|
13
|
import org.eclipse.swt.graphics.Rectangle;
|
14
|
import org.eclipse.swt.widgets.Canvas;
|
15
|
|
16
|
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
|
17
|
import eu.etaxonomy.taxeditor.singlesource.editor.name.container.EditorAnnotationFacade.EditorAnnotationType;
|
18
|
|
19
|
/**
|
20
|
* <p>EditorAnnotation class.</p>
|
21
|
*
|
22
|
* @author n.hoffmann
|
23
|
* @version $Id: $
|
24
|
*/
|
25
|
public class EditorAnnotationFacadeImpl extends Annotation implements IAnnotationPresentation, IEditorAnnotation {
|
26
|
private static final Logger logger = Logger
|
27
|
.getLogger(EditorAnnotationFacadeImpl.class);
|
28
|
private IMarker marker;
|
29
|
private String text;
|
30
|
private int line;
|
31
|
private Position position;
|
32
|
|
33
|
public EditorAnnotationFacadeImpl(){
|
34
|
}
|
35
|
|
36
|
public EditorAnnotationFacadeImpl(EditorAnnotationFacade.EditorAnnotationType type, Integer line, String text) {
|
37
|
super(type.name(), false, text);
|
38
|
this.marker = null;
|
39
|
this.line = line;
|
40
|
this.text = text;
|
41
|
}
|
42
|
|
43
|
public EditorAnnotationFacadeImpl(Integer line, String text) {
|
44
|
this(EditorAnnotationType.ERROR, line, text);
|
45
|
}
|
46
|
|
47
|
public EditorAnnotationFacadeImpl(ParserProblem problem){
|
48
|
this(EditorAnnotationFacade.EditorAnnotationType.getTypeByProblem(problem), 0, problem.getMessage());
|
49
|
}
|
50
|
|
51
|
public EditorAnnotationFacadeImpl(IMarker marker) {
|
52
|
this.marker = marker;
|
53
|
}
|
54
|
|
55
|
public Object getInstanceInternal(EditorAnnotationFacade.EditorAnnotationType type, Integer line, String text) throws OperationNotSupportedException
|
56
|
{
|
57
|
return new EditorAnnotationFacadeImpl(type, line, text);
|
58
|
}
|
59
|
|
60
|
public Object getInstanceInternal(Integer line, String text) {
|
61
|
return new EditorAnnotationFacadeImpl(line, text);
|
62
|
}
|
63
|
|
64
|
public Object getInstanceInternal(ParserProblem problem) throws OperationNotSupportedException
|
65
|
{
|
66
|
return new EditorAnnotationFacadeImpl(EditorAnnotationType.getTypeByProblem(problem), 0, problem.getMessage());
|
67
|
}
|
68
|
|
69
|
public Object getInstanceInternal(Object marker) throws OperationNotSupportedException
|
70
|
{
|
71
|
return new EditorAnnotationFacadeImpl((IMarker)marker);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* <p>Getter for the field <code>marker</code>.</p>
|
76
|
*
|
77
|
* @return a org.eclipse.core.resources.IMarker object.
|
78
|
*/
|
79
|
public Object getMarker() {
|
80
|
return marker;
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* <p>Getter for the field <code>line</code>.</p>
|
85
|
*
|
86
|
* @return a int.
|
87
|
*/
|
88
|
public int getLine() {
|
89
|
return line;
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* <p>Getter for the field <code>text</code>.</p>
|
94
|
*
|
95
|
* @return a {@link java.lang.String} object.
|
96
|
*/
|
97
|
@Override
|
98
|
public String getText() {
|
99
|
if (EditorAnnotationFacade.EditorAnnotationType.ERROR.name().equals(getType())) {
|
100
|
return "Error: " + text;
|
101
|
}
|
102
|
if (EditorAnnotationFacade.EditorAnnotationType.WARNING.name().equals(getType())) {
|
103
|
return "Warning: " + text;
|
104
|
}
|
105
|
return super.getText();
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* @return
|
110
|
*/
|
111
|
private Image getImage() {
|
112
|
return EditorAnnotationFacade.EditorAnnotationType.valueOf(getType()).image;
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* <p>getLayer</p>
|
117
|
*
|
118
|
* @return a int.
|
119
|
*/
|
120
|
public int getLayer() {
|
121
|
return 3;
|
122
|
}
|
123
|
|
124
|
|
125
|
/**
|
126
|
* <p>Getter for the field <code>position</code>.</p>
|
127
|
*
|
128
|
* @return a {@link org.eclipse.jface.text.Position} object.
|
129
|
*/
|
130
|
public Position getPosition() {
|
131
|
return position;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* <p>Setter for the field <code>position</code>.</p>
|
136
|
*
|
137
|
* @param position a {@link org.eclipse.jface.text.Position} object.
|
138
|
*/
|
139
|
public void setPosition(Position position) {
|
140
|
this.position = position;
|
141
|
}
|
142
|
|
143
|
|
144
|
/** {@inheritDoc} */
|
145
|
public void paint(GC gc, Canvas canvas, Rectangle bounds) {
|
146
|
Point canvasSize= canvas.getSize();
|
147
|
|
148
|
int x= 0;
|
149
|
int y= bounds.y;
|
150
|
int w= canvasSize.x;
|
151
|
int h= bounds.height;
|
152
|
|
153
|
if (y + h > canvasSize.y)
|
154
|
h= canvasSize.y - y;
|
155
|
|
156
|
if (y < 0) {
|
157
|
h= h + y;
|
158
|
y= 0;
|
159
|
}
|
160
|
|
161
|
if (h <= 0)
|
162
|
return;
|
163
|
|
164
|
Image image = getImage();
|
165
|
|
166
|
if (image == null) {
|
167
|
return;
|
168
|
}
|
169
|
|
170
|
Rectangle r = image.getBounds();
|
171
|
|
172
|
int destX = x + w - r.width;
|
173
|
int destY = y + h - r.height;
|
174
|
|
175
|
gc.drawImage(image, 0, 0, r.width, r.height, destX, destY, r.width, r.height);
|
176
|
}
|
177
|
|
178
|
|
179
|
public void setMarker(Object marker) {
|
180
|
this.marker = (IMarker)marker;
|
181
|
}
|
182
|
|
183
|
public void setPosition(Object position) {
|
184
|
setPosition((Position)position);
|
185
|
}
|
186
|
}
|