Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / container / ContainerFactory.java
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.hibernate.HibernateProxyHelper;
12 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
13 import eu.etaxonomy.cdm.model.taxon.Taxon;
14 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
15 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
16 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
17
18 /**
19 * <p>ContainerFactory class.</p>
20 *
21 * @author n.hoffmann
22 * @version $Id: $
23 */
24 public class ContainerFactory {
25
26 /**
27 * @param taxonNameEditor
28 */
29 public static void createOrUpdateAcceptedTaxonsHomotypicGroup(
30 TaxonNameEditor taxonNameEditor) {
31
32 if(taxonNameEditor.getAcceptedGroup() == null){
33 taxonNameEditor.setAcceptedGroup(new AcceptedGroup(taxonNameEditor, taxonNameEditor.getTaxon().getHomotypicGroup()));
34 }
35 else{
36 taxonNameEditor.getAcceptedGroup().redraw(taxonNameEditor.getTaxon().getHomotypicGroup());
37 }
38
39 }
40
41 /**
42 * @param taxonNameEditor
43 */
44 public static void createOrUpdateHeterotypicSynonymyGroups(
45 TaxonNameEditor taxonNameEditor) {
46 List<HomotypicalSynonymGroup> retainedGroups = new ArrayList<HomotypicalSynonymGroup>();
47
48 List<HomotypicalSynonymGroup> heterotypicSynonymGroups = taxonNameEditor.getHeterotypicSynonymGroups();
49
50 if (heterotypicSynonymGroups != null) {
51
52 for(HomotypicalSynonymGroup group : heterotypicSynonymGroups){
53 retainedGroups.add(group);
54 }
55 }
56
57 for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
58 HomotypicalSynonymGroup group = createOrUpdateHeterotypicSynonymyGroup(taxonNameEditor, homotypicalGroup);
59
60 retainedGroups.remove(group);
61 }
62
63 for(HomotypicalSynonymGroup retainedGroup : retainedGroups){
64 taxonNameEditor.removeGroup(retainedGroup);
65 }
66 }
67
68
69 public static HomotypicalSynonymGroup createOrUpdateHeterotypicSynonymyGroup(
70 TaxonNameEditor taxonNameEditor, HomotypicalGroup homotypicalGroup){
71 HomotypicalSynonymGroup group = null;
72 if(taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup) == null){
73 group = new HomotypicalSynonymGroup(taxonNameEditor, homotypicalGroup);
74 taxonNameEditor.addHeterotypicSynonymGroup(group);
75 if(taxonNameEditor.getMisappliedGroup() != null){
76 group.getControl().moveAbove(taxonNameEditor.getMisappliedGroup().getControl());
77 }
78 }
79 else{
80 group = taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup);
81 group.redraw(homotypicalGroup);
82 }
83
84 return group;
85 }
86
87 /**
88 * @param taxonNameEditor
89 */
90 public static void createOrUpdateMisapplicationsGroup(
91 TaxonNameEditor taxonNameEditor) {
92 MisappliedGroup group = taxonNameEditor.getMisappliedGroup();
93 Taxon taxon = HibernateProxyHelper.deproxy(taxonNameEditor.getTaxon(), Taxon.class);
94 if(taxon.getMisappliedNames().isEmpty()){
95 taxonNameEditor.removeGroup(group);
96 taxonNameEditor.setMisapplicationsGroup(null);
97 }else{
98 if(group == null){
99 taxonNameEditor.setMisapplicationsGroup(new MisappliedGroup(taxonNameEditor));
100 }else{
101 group.redraw();
102 }
103 }
104
105 }
106
107 }