Project

General

Profile

Download (3.82 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.TaxonNameEditor;
13

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

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

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

    
32
	}
33

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

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

    
40
		if (heterotypicSynonymGroups != null) {
41

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

    
47
		for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
48
		    homotypicalGroup = HibernateProxyHelper.deproxy(homotypicalGroup, HomotypicalGroup.class);
49
		    HomotypicalSynonymGroup group = createOrUpdateHeterotypicSynonymyGroup(taxonNameEditor, homotypicalGroup);
50

    
51
			retainedGroups.remove(group);
52
		}
53

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

    
59

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

    
75
		return group;
76
	}
77

    
78
	public static void createOrUpdateMisapplicationsGroup(
79
	        TaxonNameEditor taxonNameEditor) {
80
		MisappliedGroup group = taxonNameEditor.getMisappliedGroup();
81
		Taxon taxon = HibernateProxyHelper.deproxy(taxonNameEditor.getTaxon(), Taxon.class);
82

    
83
		if(taxon.getMisappliedNames(true).isEmpty() && taxon.getProParteAndPartialSynonyms().isEmpty()){
84
			taxonNameEditor.removeGroup(group);
85
			taxonNameEditor.setMisapplicationsGroup(null);
86
		}else{
87
			if(group == null){
88
				taxonNameEditor.setMisapplicationsGroup(new MisappliedGroup(taxonNameEditor));
89
			}else{
90
				group.redraw();
91
			}
92
		}
93

    
94
	}
95

    
96
	public static void setMenuToAllContainers(TaxonNameEditor taxonNameEditor){
97
	    if (taxonNameEditor == null) {
98
            return;
99
        }
100
	    if (taxonNameEditor.getAcceptedGroup() != null){
101
	        taxonNameEditor.getAcceptedGroup().setMenuToGroup();
102
	    }
103
	    if (taxonNameEditor.getTaxon() != null){
104
    	    for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
105
                homotypicalGroup = HibernateProxyHelper.deproxy(homotypicalGroup, HomotypicalGroup.class);
106
                HomotypicalSynonymGroup group = taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup);
107
                if (group != null){
108
                    group.setMenuToGroup();
109
                }
110
            }
111
    	    if (taxonNameEditor.getMisappliedGroup() != null){
112
    	        taxonNameEditor.getMisappliedGroup().setMenuToGroup();
113
    	    }
114
	    }
115
	}
116

    
117
}
(7-7/11)