Project

General

Profile

« Previous | Next » 

Revision 707b6237

Added by Niels Hoffmann over 12 years ago

Merged with trunk

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/NameViewer.java
44 44
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
45 45
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
46 46

  
47
import eu.etaxonomy.cdm.model.name.NonViralName;
48
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
49
import eu.etaxonomy.cdm.model.taxon.Taxon;
50
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
51 47
import eu.etaxonomy.taxeditor.editor.EditorUtil;
52 48
import eu.etaxonomy.taxeditor.editor.ViewerConfiguration;
49
import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation.EditorAnnotationType;
53 50
import eu.etaxonomy.taxeditor.preference.Resources;
54 51

  
55 52
/**
......
64 61
	/** Constant <code>RULER_WIDTH=16</code> */
65 62
	public static final int RULER_WIDTH = 16;
66 63
	
67
	private IVerticalRuler ruler;
68
	private AnnotationModel annotationModel;
64
	private final IVerticalRuler ruler;
65
	private final AnnotationModel annotationModel;
69 66

  
70 67
	/**
71 68
	 * <p>Constructor for NameViewer.</p>
......
166 163
	 *
167 164
	 * @return a {@link org.eclipse.swt.widgets.Layout} object.
168 165
	 */
166
	@Override
169 167
	protected Layout createLayout() {
170 168
		TableWrapLayout layout = new TableWrapLayout();
171 169
		layout.numColumns = 2;
......
184 182
		annotationPainter.addDrawingStrategy(LineWrapSquigglesStrategy.ID, new LineWrapSquigglesStrategy());
185 183
		
186 184
		// Add ability to paint red squigglies
187
		annotationPainter.addAnnotationType(EditorAnnotation.ERROR_TYPE, LineWrapSquigglesStrategy.ID);
188
		annotationPainter.setAnnotationTypeColor(EditorAnnotation.ERROR_TYPE, 
189
				new Color(Display.getDefault(), EditorAnnotation.ERROR_RGB));
185
		annotationPainter.addAnnotationType(EditorAnnotationType.ERROR.name(), LineWrapSquigglesStrategy.ID);
186
		annotationPainter.setAnnotationTypeColor(EditorAnnotationType.ERROR.image, 
187
				new Color(Display.getDefault(), EditorAnnotationType.ERROR.color));
190 188

  
191 189
		// Add ability to paint yellow squigglies
192
		annotationPainter.addAnnotationType(EditorAnnotation.WARNING_TYPE, LineWrapSquigglesStrategy.ID);
193
		annotationPainter.setAnnotationTypeColor(EditorAnnotation.WARNING_TYPE, 
194
				new Color(Display.getDefault(), EditorAnnotation.WARNING_RGB));
190
		annotationPainter.addAnnotationType(EditorAnnotationType.WARNING.name(), LineWrapSquigglesStrategy.ID);
191
		annotationPainter.setAnnotationTypeColor(EditorAnnotationType.WARNING.image, 
192
				new Color(Display.getDefault(), EditorAnnotationType.WARNING.color));
195 193
		
196 194
		this.addPainter(annotationPainter);
197 195
	}
198 196

  
199 197

  
200 198
	/**
201
	 * <p>clearErrors</p>
199
	 * <p>clearAnnotations</p>
202 200
	 */
203
	public void clearErrors() {
201
	public void clearAnnotations() {
204 202
		Iterator<Annotation> annotations = this.getAnnotationModel().getAnnotationIterator();
205 203
		while (annotations.hasNext()) {
206 204
			Annotation annotation = annotations.next(); 
207
			if (annotation.getType().equals(EditorAnnotation.ERROR_TYPE) || annotation.getType().equals(EditorAnnotation.WARNING_TYPE)) {
208
				this.getAnnotationModel().removeAnnotation(annotation);
209
			}
205
			this.getAnnotationModel().removeAnnotation(annotation);
210 206
		}
211 207
	}
212 208
	
......
217 213
	 *
218 214
	 * @param name a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
219 215
	 */
220
	public void setShowParsingErrors(TaxonNameBase<?, ?> name) {
221
				
222
		String text = this.getTextWidget().getText();
223
						
224
		if (name.hasProblem() && text.length() > 0) {
225
			int start = name.getProblemStarts();
226
			int length = name.getProblemEnds() - start;
227
			
228
			if (start == -1 || name.getProblemEnds() == -1) {
229
				return;
230
			}
231
			
232
			// Don't let squigglies try to draw beyond the end of the text
233
			if (text.length() < start + length) {
234
				length = text.length() - start;
235
			}
236
			
237
			for (ParserProblem problem : name.getParsingProblems()) {
238
				
239
				String type = null;
240
				if (problem.isWarning()) {
241
					type = EditorAnnotation.WARNING_TYPE;
242
				}
243
				if (problem.isError()) {
244
					type = EditorAnnotation.ERROR_TYPE;
245
				}
246
				if (type == null) {
247
					continue;
248
				}
249
				this.getAnnotationModel().addAnnotation(
250
						new EditorAnnotation(type, 0, problem.getMessage()), 
251
						new Position(start, length));
252
			}
253
		}
254
	}
216
//	public void setShowParsingErrors(TaxonNameBase<?, ?> name) {
217
//				
218
//		String text = this.getTextWidget().getText();
219
//						
220
//		if (name.hasProblem() && text.length() > 0) {
221
//			int start = name.getProblemStarts();
222
//			int length = name.getProblemEnds() - start;
223
//			
224
//			if (start == -1 || name.getProblemEnds() == -1) {
225
//				return;
226
//			}
227
//			
228
//			// Don't let squigglies try to draw beyond the end of the text
229
//			if (text.length() < start + length) {
230
//				length = text.length() - start;
231
//			}
232
//			
233
//			for (ParserProblem problem : name.getParsingProblems()) {
234
//				
235
//				String type = null;
236
//				if (problem.isWarning()) {
237
//					type = EditorAnnotation.WARNING_TYPE;
238
//				}
239
//				if (problem.isError()) {
240
//					type = EditorAnnotation.ERROR_TYPE;
241
//				}
242
//				if (type == null) {
243
//					continue;
244
//				}
245
//				this.getAnnotationModel().addAnnotation(
246
//						new EditorAnnotation(type, 0, problem.getMessage()), 
247
//						new Position(start, length));
248
//			}
249
//			
250
//		}
251
//	}
255 252
	
256
	
257
	/**
258
	 * <p>setShowSecError</p>
259
	 *
260
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
261
	 */
262
	public void setShowSecError(Taxon taxon) {
263
		
264
		// If taxon has no sec, show an annotation
265
		if (taxon.getSec() == null) {
266
			
267
			String text = "This taxon requires a sec. reference.";
268
			
269
			this.getAnnotationModel().addAnnotation(
270
					new EditorAnnotation(0, text),
271
					new Position(0, 0));
272
		}
253
	public void addAnnotation(EditorAnnotation annotation){
254
		addAnnotation(annotation, null);
273 255
	}
274

  
275
	public void setShowMultipleNameUsageWarning(TaxonNameBase name){
276
		if(name.getTaxonBases().size() > 1){
277
			String text = "This taxons name is used multiple times.";
278
			
279
			this.getAnnotationModel().addAnnotation(
280
					new EditorAnnotation(EditorAnnotation.WARNING_TYPE, 0, text),
281
					new Position(0, 0));
256
	
257
	public void addAnnotation(EditorAnnotation annotation, Position position){
258
		if(position == null){
259
			position = new Position(0, 0);
282 260
		}
283
	}
284
			
285
	/**
286
	 * @param name
287
	 */
288
	public void setShowNameNotParsableWarning(NonViralName name) {
289
		String text = "This name may only be edited in the details view.";
290
		
291
		this.getAnnotationModel().addAnnotation(
292
				new EditorAnnotation(EditorAnnotation.WARNING_TYPE, 0, text),
293
				new Position(0, 0));
294 261
		
262
		this.getAnnotationModel().addAnnotation(annotation, position);
295 263
	}
296
	
264
		
297 265
	/**
298 266
	 * <p>setText</p>
299 267
	 *

Also available in: Unified diff