Project

General

Profile

Download (3.45 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.editor.name.container;
5

    
6
import java.util.ArrayList;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Set;
10

    
11
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
12
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
13
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
14
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
15

    
16
/**
17
 * <p>ContainerFactory class.</p>
18
 *
19
 * @author n.hoffmann
20
 * @version $Id: $
21
 */
22
public class ContainerFactory {
23
		
24
	/**
25
	 * @param taxonNameEditor
26
	 */
27
	public static void createOrUpdateAcceptedTaxonsHomotypicGroup(
28
			TaxonNameEditor taxonNameEditor) {
29

    
30
		if(taxonNameEditor.getAcceptedGroup() == null){
31
			taxonNameEditor.setAcceptedGroup(new AcceptedGroup(taxonNameEditor, taxonNameEditor.getTaxon().getHomotypicGroup()));
32
		}
33
		else{
34
			taxonNameEditor.getAcceptedGroup().redraw(taxonNameEditor.getTaxon().getHomotypicGroup());
35
		}
36
		
37
	}
38

    
39
	/**
40
	 * @param taxonNameEditor
41
	 */
42
	public static void createOrUpdateHeterotypicSynonymyGroups(
43
			TaxonNameEditor taxonNameEditor) {
44
		List<HomotypicalSynonymGroup> retainedGroups = new ArrayList<HomotypicalSynonymGroup>();
45
		
46
		for(HomotypicalSynonymGroup group : taxonNameEditor.getHeterotypicSynonymGroups()){
47
			retainedGroups.add(group);
48
		}
49
		
50
		for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
51
			HomotypicalSynonymGroup group = createOrUpdateHeterotypicSynonymyGroup(taxonNameEditor, homotypicalGroup);
52
			
53
			retainedGroups.remove(group);
54
		}
55
		
56
		for(HomotypicalSynonymGroup retainedGroup : retainedGroups){
57
			taxonNameEditor.removeGroup(retainedGroup);
58
		}
59
	}
60

    
61

    
62
	public static HomotypicalSynonymGroup createOrUpdateHeterotypicSynonymyGroup(
63
			TaxonNameEditor taxonNameEditor, HomotypicalGroup homotypicalGroup){
64
		HomotypicalSynonymGroup group = null;
65
		if(taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup) == null){
66
			group = new HomotypicalSynonymGroup(taxonNameEditor, homotypicalGroup);
67
			taxonNameEditor.addHeterotypicSynonymGroup(group);
68
			if(taxonNameEditor.getMisappliedGroup() != null){
69
				group.getControl().moveAbove(taxonNameEditor.getMisappliedGroup().getControl());
70
			}
71
		}
72
		else{
73
			group = taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup);
74
			group.redraw(homotypicalGroup);
75
		}
76
		
77
		return group;
78
	}
79

    
80
	/**
81
	 * @param taxonNameEditor
82
	 */
83
	public static void createOrUpdateMisapplicationsGroup(
84
			TaxonNameEditor taxonNameEditor) {
85
		MisappliedGroup group = taxonNameEditor.getMisappliedGroup();
86
		if(taxonNameEditor.getTaxon().getMisappliedNames().isEmpty()){
87
			taxonNameEditor.removeGroup(group);		
88
			taxonNameEditor.setMisapplicationsGroup(null);
89
		}else{
90
			if(group == null){
91
				taxonNameEditor.setMisapplicationsGroup(new MisappliedGroup(taxonNameEditor));
92
			}else{
93
				group.redraw();
94
			}
95
		}
96
		
97
	}
98

    
99
	/**
100
	 * @param taxonNameEditor
101
	 */
102
	public static void createOrUpdateConceptGroup(
103
			TaxonNameEditor taxonNameEditor) {
104
		Set<TaxonRelationship> filteredTaxonRelations = new HashSet<TaxonRelationship>();
105
		
106
		for (TaxonRelationship relationship : taxonNameEditor.getTaxon().getTaxonRelations()) {
107
			if (! relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
108
					 relationship.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
109
				filteredTaxonRelations.add(relationship);
110
			}
111
		}
112
		
113
		if(! filteredTaxonRelations.isEmpty()){
114
			taxonNameEditor.setConceptGroup(new ConceptGroup(taxonNameEditor));
115
		}
116
	}
117

    
118
}
(8-8/19)