Project

General

Profile

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

    
6
import java.util.ArrayList;
7
import java.util.List;
8

    
9
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
10
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
11
import eu.etaxonomy.cdm.model.taxon.Taxon;
12
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
13

    
14
/**
15
 *
16
 * @author pplitzner
17
 * @date Aug 24, 2017
18
 *
19
 */
20
public class ContainerFactoryE4 {
21

    
22
	public static void createOrUpdateAcceptedTaxonsHomotypicGroup(
23
	        TaxonNameEditorE4 taxonNameEditor) {
24

    
25
		if(taxonNameEditor.getAcceptedGroup() == null){
26
			taxonNameEditor.setAcceptedGroup(new AcceptedGroupE4(taxonNameEditor, taxonNameEditor.getTaxon().getHomotypicGroup()));
27
		}
28
		else{
29
			taxonNameEditor.getAcceptedGroup().redraw(taxonNameEditor.getTaxon().getHomotypicGroup());
30
		}
31

    
32
	}
33

    
34
	public static void createOrUpdateHeterotypicSynonymyGroups(
35
			TaxonNameEditorE4 taxonNameEditor) {
36
		List<HomotypicalSynonymGroupE4> retainedGroups = new ArrayList<>();
37

    
38
		List<HomotypicalSynonymGroupE4> heterotypicSynonymGroups = taxonNameEditor.getHeterotypicSynonymGroups();
39

    
40
		if (heterotypicSynonymGroups != null) {
41

    
42
			for(HomotypicalSynonymGroupE4 group : heterotypicSynonymGroups){
43
				retainedGroups.add(group);
44
			}
45
		}
46

    
47
		for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
48
		    HomotypicalSynonymGroupE4 group = createOrUpdateHeterotypicSynonymyGroup(taxonNameEditor, homotypicalGroup);
49

    
50
			retainedGroups.remove(group);
51
		}
52

    
53
		for(HomotypicalSynonymGroupE4 retainedGroup : retainedGroups){
54
			taxonNameEditor.removeGroup(retainedGroup);
55
		}
56
	}
57

    
58

    
59
	public static HomotypicalSynonymGroupE4 createOrUpdateHeterotypicSynonymyGroup(
60
	        TaxonNameEditorE4 taxonNameEditor, HomotypicalGroup homotypicalGroup){
61
	    HomotypicalSynonymGroupE4 group = null;
62
		if(taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup) == null){
63
			group = new HomotypicalSynonymGroupE4(taxonNameEditor, homotypicalGroup);
64
			taxonNameEditor.addHeterotypicSynonymGroup(group);
65
			if(taxonNameEditor.getMisappliedGroup() != null){
66
				group.getControl().moveAbove(taxonNameEditor.getMisappliedGroup().getControl());
67
			}
68
		}
69
		else{
70
			group = taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup);
71
			group.redraw(homotypicalGroup);
72
		}
73

    
74
		return group;
75
	}
76

    
77
	public static void createOrUpdateMisapplicationsGroup(
78
	        TaxonNameEditorE4 taxonNameEditor) {
79
		MisappliedGroupE4 group = taxonNameEditor.getMisappliedGroup();
80
		Taxon taxon = HibernateProxyHelper.deproxy(taxonNameEditor.getTaxon(), Taxon.class);
81
		if(taxon.getMisappliedNames().isEmpty()){
82
			taxonNameEditor.removeGroup(group);
83
			taxonNameEditor.setMisapplicationsGroup(null);
84
		}else{
85
			if(group == null){
86
				taxonNameEditor.setMisapplicationsGroup(new MisappliedGroupE4(taxonNameEditor));
87
			}else{
88
				group.redraw();
89
			}
90
		}
91

    
92
	}
93

    
94
}
(6-6/11)