Project

General

Profile

« Previous | Next » 

Revision eea5c6dc

Added by Niels Hoffmann almost 13 years ago

Temporary fix for #2366; fixes #2368; Refactoring annotations in the name editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/AbstractGroupedContainer.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.editor.name.container;
11 11

  
12
import java.util.List;
12 13
import java.util.Set;
13 14

  
14 15
import org.eclipse.core.runtime.Assert;
15 16
import org.eclipse.jface.dialogs.Dialog;
16 17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.Position;
17 19
import org.eclipse.jface.window.DefaultToolTip;
18 20
import org.eclipse.swt.custom.StyledText;
19 21
import org.eclipse.swt.dnd.DND;
......
48 50
import eu.etaxonomy.cdm.model.name.NonViralName;
49 51
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
50 52
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
53
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
51 54
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
52 55
import eu.etaxonomy.taxeditor.editor.EditorUtil;
53 56
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
57
import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation.EditorAnnotationType;
54 58
import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDragListener;
55 59
import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDragSourceEffect;
56 60
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInNewGroupOperation;
......
165 169
				getTaxonBase().setTitleCache((getTaxonBase().generateTitle()));
166 170
				
167 171
				// show errors resulting from parsing
168
				calculateErrors();
172
				calculateAnnotations();
169 173
				// store the position of the cursor				
170 174
				storeCursor();
171 175
				// notify selection listener
......
265 269
			getNameViewer().setText(text);
266 270
			placeCursor();
267 271
		}
268
		calculateErrors();
272
		calculateAnnotations();
269 273
	}
270 274
	
271 275
	/**
272 276
	 * <p>calculateErrors</p>
273 277
	 */
274
	synchronized protected void calculateErrors() {
275
		getNameViewer().clearErrors();
276
		getNameViewer().setShowParsingErrors(getName());
278
	synchronized protected void calculateAnnotations() {
279
		getNameViewer().clearAnnotations();
280
		showAnnotations();
281
	}
282

  
283
	/**
284
	 * 
285
	 */
286
	public void showAnnotations() {
287
		
288
		if(getName().hasProblem()){
289
			showParsingProblems();
290
		}
291
		
292
		if(!isNameParsable()){
293
			getNameViewer().addAnnotation(
294
					new EditorAnnotation(EditorAnnotationType.WARNING, 0, "This name may only be edited in the details view."));
295
		}
296
		
297
		if(isNameUsedMultipleTimes()){
298
			getNameViewer().addAnnotation(new EditorAnnotation(EditorAnnotationType.WARNING, 0, "This taxons name is used multiple times."));
299
		}
300
		
301
		
302
	}
303

  
304
	/**
305
	 * 
306
	 */
307
	private void showParsingProblems() {
308
		String text = getNameViewer().getTextWidget().getText();
309
		
310
		List<ParserProblem> parsingProblems = getName().getParsingProblems();
311
		
312
		for (ParserProblem problem : parsingProblems) {
313
			getNameViewer().addAnnotation(new EditorAnnotation(problem), getParsingProblemPosition());
314
		}	
315
	}
316
	
317
	private Position getParsingProblemPosition(){
318
		String text = getNameViewer().getTextWidget().getText();
319
		
320
		if (getName().hasProblem() && text.length() > 0) {
321
			int start = getName().getProblemStarts();
322
			int length = getName().getProblemEnds() - start;
323
			
324
			if (start == -1 || getName().getProblemEnds() == -1) {
325
				return null;
326
			}
327
			
328
			// Don't let squigglies try to draw beyond the end of the text
329
			if (text.length() < start + length) {
330
				length = text.length() - start;
331
			}
332
			
333
			return new Position(start, length);
334
		}
335
		return null;
277 336
	}
278 337

  
279 338
	/**
......
365 424
		NonViralName name = (NonViralName) HibernateProxyHelper.deproxy(getName());
366 425
		boolean enableFreetext = true;
367 426

  
368
		enableFreetext &= isNameUsedMultipleTimes(name);
369
		enableFreetext &= isNameParsable(name);
370
		
371
		if(!enableFreetext){
372
			getNameViewer().setShowNameNotParsableWarning(name);
373
		}
427
		enableFreetext |= isNameUsedMultipleTimes();
428
		enableFreetext &= isNameParsable();
374 429
		
375 430
		return enableFreetext;
376 431
	}
377 432
	
378
	private boolean isNameUsedMultipleTimes(NonViralName name){
379
		if(name.getTaxonBases().size() != 1){
380
			getNameViewer().setShowMultipleNameUsageWarning(name);
381
			return false;
433
	private boolean isNameUsedMultipleTimes(){
434
		if(getName().getTaxonBases().size() > 1){
435
			return true;
382 436
		}
383
		return true;
437
		return false;
384 438
	}
385 439
	
386
	private boolean isNameParsable(NonViralName name){
440
	private boolean isNameParsable(){
441
		TaxonNameBase name = getName();
442
		
387 443
		boolean isParsable = true; 
388 444
		isParsable &= CdmUtils.isEmpty(name.getAppendedPhrase()); //taxonFieldsEmpty();
389 445
		
390
		isParsable &= ! name.isProtectedAuthorshipCache();
391
		isParsable &= ! name.isProtectedNameCache();
392
		
446
		if(name instanceof NonViralName){
447
			NonViralName nonViralName = (NonViralName) name;
448
			isParsable &= ! nonViralName.isProtectedAuthorshipCache();
449
			isParsable &= ! nonViralName.isProtectedNameCache();
450
		}
393 451
		
394 452
		return isParsable;
395 453
	}
......
397 455
	/**
398 456
	 * Parse the text and calculate errors
399 457
	 */
400
	public void parseAndCalculateErrors(){
458
	public void parseAndCalculateAnnotations(){
401 459
		removeListener();
402 460
		String unparsedNameString = getNameViewer().getTextWidget().getText();
403 461
		parseHandler.parse(unparsedNameString);
404 462
		addListener();
405
		calculateErrors();
463
		calculateAnnotations();
406 464
	}
407 465

  
408 466
	/**
......
894 952
		nonEditableInfoHover.setText(nonEditableHoverText);
895 953
		nonEditableInfoLabel.setText(nonEditableText);
896 954
		
897
		calculateErrors();
955
		calculateAnnotations();
898 956
	}
899 957
	
900 958
	/**

Also available in: Unified diff