merging in latest changes from trunk
[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.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 List<HomotypicalSynonymGroup> heterotypicSynonymGroups = taxonNameEditor.getHeterotypicSynonymGroups();
47
48 if (heterotypicSynonymGroups != null) {
49
50 for(HomotypicalSynonymGroup group : heterotypicSynonymGroups){
51 retainedGroups.add(group);
52 }
53 }
54
55 for(HomotypicalGroup homotypicalGroup : taxonNameEditor.getTaxon().getHeterotypicSynonymyGroups()){
56 HomotypicalSynonymGroup group = createOrUpdateHeterotypicSynonymyGroup(taxonNameEditor, homotypicalGroup);
57
58 retainedGroups.remove(group);
59 }
60
61 for(HomotypicalSynonymGroup retainedGroup : retainedGroups){
62 taxonNameEditor.removeGroup(retainedGroup);
63 }
64 }
65
66
67 public static HomotypicalSynonymGroup createOrUpdateHeterotypicSynonymyGroup(
68 TaxonNameEditor taxonNameEditor, HomotypicalGroup homotypicalGroup){
69 HomotypicalSynonymGroup group = null;
70 if(taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup) == null){
71 group = new HomotypicalSynonymGroup(taxonNameEditor, homotypicalGroup);
72 taxonNameEditor.addHeterotypicSynonymGroup(group);
73 if(taxonNameEditor.getMisappliedGroup() != null){
74 group.getControl().moveAbove(taxonNameEditor.getMisappliedGroup().getControl());
75 }
76 }
77 else{
78 group = taxonNameEditor.getHomotypicalGroupContainer(homotypicalGroup);
79 group.redraw(homotypicalGroup);
80 }
81
82 return group;
83 }
84
85 /**
86 * @param taxonNameEditor
87 */
88 public static void createOrUpdateMisapplicationsGroup(
89 TaxonNameEditor taxonNameEditor) {
90 MisappliedGroup group = taxonNameEditor.getMisappliedGroup();
91 if(taxonNameEditor.getTaxon().getMisappliedNames().isEmpty()){
92 taxonNameEditor.removeGroup(group);
93 taxonNameEditor.setMisapplicationsGroup(null);
94 }else{
95 if(group == null){
96 taxonNameEditor.setMisapplicationsGroup(new MisappliedGroup(taxonNameEditor));
97 }else{
98 group.redraw();
99 }
100 }
101
102 }
103
104 }