Project

General

Profile

Download (7.99 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.dialog.selection;
10

    
11
import org.eclipse.swt.widgets.Shell;
12

    
13
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
14
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
15
import eu.etaxonomy.cdm.model.agent.AgentBase;
16
import eu.etaxonomy.cdm.model.agent.Institution;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
20
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
21
import eu.etaxonomy.cdm.model.common.Group;
22
import eu.etaxonomy.cdm.model.common.ICdmBase;
23
import eu.etaxonomy.cdm.model.common.User;
24
import eu.etaxonomy.cdm.model.description.Feature;
25
import eu.etaxonomy.cdm.model.description.FeatureTree;
26
import eu.etaxonomy.cdm.model.description.PolytomousKey;
27
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
28
import eu.etaxonomy.cdm.model.location.Country;
29
import eu.etaxonomy.cdm.model.location.NamedArea;
30
import eu.etaxonomy.cdm.model.media.Media;
31
import eu.etaxonomy.cdm.model.molecular.Amplification;
32
import eu.etaxonomy.cdm.model.molecular.Primer;
33
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
34
import eu.etaxonomy.cdm.model.occurrence.Collection;
35
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
36
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
37
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.taxon.Classification;
40
import eu.etaxonomy.cdm.model.taxon.Synonym;
41
import eu.etaxonomy.cdm.model.taxon.Taxon;
42
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
43
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
44
import eu.etaxonomy.taxeditor.model.MessagingUtils;
45
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
46
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
47
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
48
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
49
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
50
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
51

    
52
/**
53
 * @author n.hoffmann
54
 * @date Jan 25, 2012
55
 *
56
 */
57
public class SelectionDialogFactory {
58

    
59
    public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
60
        return getSelectionFromDialog(clazz, shell, conversation, currentSelection, null);
61
    }
62

    
63
	public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection, ICdmFormElement parentElement){
64

    
65
		if(clazz.equals(Taxon.class)){
66
			return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
67
		}
68
		if(clazz.equals(Synonym.class)){
69
			return (T) TaxonBaseSelectionDialog.selectSynonym(shell, conversation);
70
		}
71
		if(clazz.equals(TaxonBase.class)){
72
			return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell, conversation);
73
		}
74
		if(clazz.equals(Classification.class)){
75
			return (T) ClassificationSelectionDialog.select(shell, conversation, (Classification) currentSelection);
76
		}
77
		if(clazz.equals(TaxonNode.class)){
78
			return (T) TaxonNodeSelectionDialog.select(shell, conversation, null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification());
79
		}
80
		if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){
81
			return (T) NomenclaturalReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection);
82
		}
83
		if(clazz.equals(Reference.class)){
84
		    if (parentElement instanceof ReferenceDetailElement){
85
		        return (T) ReferenceSelectionDialog.select(shell, conversation, ((ReferenceDetailElement) parentElement).getEntity(), true);
86
		    }
87
			return (T) ReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection);
88
		}
89

    
90
		if(clazz.equals(TaxonNameBase.class)){
91
			return (T) NameSelectionDialog.select(shell, conversation, (TaxonNameBase) currentSelection);
92
		}
93
		if(clazz.equals(Team.class)){
94
			return (T) TeamSelectionDialog.select(shell, conversation, (Team) currentSelection);
95
		}
96
		if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){
97
            return (T) NomenclaturalAuthorSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, false);
98
        }else if(clazz.equals(TeamOrPersonBase.class)){
99
		    //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
100
		    return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, false);
101
		}
102
		if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){
103
		    return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, true);
104
        }
105
		if(clazz.equals(AgentBase.class)){
106
			return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, false);
107
		}
108
		if(clazz.equals(Feature.class)){
109
			return (T) FeatureSelectionDialog.select(shell, conversation, (Feature) currentSelection);
110
		}
111
		if(clazz.equals(FeatureTree.class)){
112
			return (T) FeatureTreeSelectionDialog.select(shell, conversation, (FeatureTree) currentSelection);
113
		}
114
		if(clazz.equals(PolytomousKey.class)){
115
			return (T) PolytomousKeySelectionDialog.select(shell, conversation, (PolytomousKey) currentSelection);
116
		}
117
		if(clazz.equals(PolytomousKeyNode.class)){
118
			MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
119
					"This functionality is not implemented yet.");
120
			return null;
121
		}
122
		if(clazz.equals(DerivedUnit.class)){
123
		    return (T) DerivedUnitSelectionDialog.select(shell, conversation, (DerivedUnit) currentSelection);
124
		}
125
		if(clazz.equals(FieldUnit.class)){
126
		    return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
127
		}
128
		if(clazz.equals(SpecimenOrObservationBase.class)){
129
		    return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, conversation, (SpecimenOrObservationBase) currentSelection);
130
		}
131
		if(clazz.equals(NamedArea.class)){
132
		    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
133
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);
134
		    }
135
		    else{
136
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
137
		    }
138
		}
139
		if(clazz.equals(Collection.class)){
140
			return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
141
		}
142
		if(clazz.equals(User.class)){
143
			return (T) UserSelectionDialog.select(shell, conversation, (User) currentSelection);
144
		}
145
		if(clazz.equals(GrantedAuthorityImpl.class)){
146
			return (T) GrantedAuthoritySelectionDialog.select(shell, conversation, (GrantedAuthorityImpl) currentSelection);
147
		}
148
		if (clazz.equals(Person.class)){
149
			return (T) PersonSelectionDialog.select(shell, conversation, (Person) currentSelection);
150
		}
151
		if(clazz.equals(Group.class)){
152
			return (T) GroupSelectionDialog.select(shell, conversation, (Group) currentSelection);
153
		}
154
		if(clazz.equals(Institution.class)){
155
			return (T) InstitutionSelectionDialog.select(shell, conversation, (Institution) currentSelection);
156
		}
157
		if(clazz.equals(Primer.class)){
158
		    return (T) PrimerSelectionDialog.select(shell, conversation, (Primer) currentSelection);
159
		}
160
		if(clazz.equals(Amplification.class)){
161
		    return (T) AmplificationSelectionDialog.select(shell, conversation, (Amplification) currentSelection);
162
		}
163
		if(clazz.equals(Media.class)){
164
		    return (T) MediaSelectionDialog.select(shell, conversation, (Media) currentSelection);
165
		}
166

    
167
		return null;
168
	}
169

    
170
}
(27-27/34)