Project

General

Profile

Download (9.36 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.facade.DerivedUnitFacade;
14
import eu.etaxonomy.cdm.model.agent.AgentBase;
15
import eu.etaxonomy.cdm.model.agent.Institution;
16
import eu.etaxonomy.cdm.model.agent.Person;
17
import eu.etaxonomy.cdm.model.agent.Team;
18
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
19
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
20
import eu.etaxonomy.cdm.model.common.Group;
21
import eu.etaxonomy.cdm.model.common.ICdmBase;
22
import eu.etaxonomy.cdm.model.common.User;
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.description.FeatureTree;
25
import eu.etaxonomy.cdm.model.description.PolytomousKey;
26
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
27
import eu.etaxonomy.cdm.model.location.Country;
28
import eu.etaxonomy.cdm.model.location.NamedArea;
29
import eu.etaxonomy.cdm.model.media.Media;
30
import eu.etaxonomy.cdm.model.media.Rights;
31
import eu.etaxonomy.cdm.model.molecular.Amplification;
32
import eu.etaxonomy.cdm.model.molecular.Primer;
33
import eu.etaxonomy.cdm.model.name.TaxonName;
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.preference.PreferencesUtil;
46
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
47
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
48
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
49
import eu.etaxonomy.taxeditor.ui.section.description.CommonNameSourceElement;
50
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
51
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
52
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
53

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

    
61
    public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,
62
            T currentSelection){
63
        return getSelectionFromDialog(clazz, shell, //conversation,
64
                currentSelection, null);
65
    }
66

    
67
	public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,
68
	        T currentSelection, ICdmFormElement parentElement){
69

    
70
		if(clazz.equals(Taxon.class)){
71
			return (T) TaxonSelectionDialog.selectTaxon(shell, //conversation,
72
			        (Taxon) currentSelection);
73
		}
74
		if(clazz.equals(Synonym.class)){
75
			return (T) TaxonBaseSelectionDialog.selectSynonym(shell );//,conversation);
76
		}
77
		if(clazz.equals(TaxonBase.class)){
78
			return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell);//, conversation);
79
		}
80
		if(clazz.equals(Classification.class)){
81
			return (T) ClassificationSelectionDialog.select(shell, //conversation,
82
			        (Classification) currentSelection);
83
		}
84
		if(clazz.equals(TaxonNode.class)){
85
			return (T) TaxonNodeSelectionDialog.select(shell, //conversation,
86
			        null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid());
87
		}
88
		if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){
89
			return (T) NomenclaturalReferenceSelectionDialog.select(shell, //conversation,
90
			        (Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship());
91
		}
92
		if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){
93
            return (T) CommonNameReferenceSelectionDialog.select(shell, //conversation,
94
                    (Reference) currentSelection);
95
        }
96
		if(clazz.equals(Reference.class)){
97
		    if (parentElement instanceof ReferenceDetailElement){
98
		        return (T) ReferenceSelectionDialog.select(shell, //conversation,
99
		                ((ReferenceDetailElement) parentElement).getEntity(), true);
100
		    }
101
			return (T) ReferenceSelectionDialog.select(shell, //conversation,
102
			        (Reference) currentSelection);
103
		}
104

    
105
		if(clazz.equals(TaxonName.class)){
106
			return (T) NameSelectionDialog.select(shell, //conversation,
107
			        (TaxonName) currentSelection);
108
		}
109
		if(clazz.equals(Team.class)){
110
			return (T) TeamSelectionDialog.select(shell, //conversation,
111
			        (Team) currentSelection);
112
		}
113
		if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){
114
            return (T) NomenclaturalAuthorSelectionDialog.select(shell, //conversation,
115
                    (AgentBase) currentSelection, false);
116
        }else if(clazz.equals(TeamOrPersonBase.class)){
117
		    //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
118
		    return (T) AgentSelectionDialog.select(shell, //conversation,
119
		            (AgentBase) currentSelection, false);
120
		}
121
		if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){
122
		    return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, //conversation,
123
		            (AgentBase) currentSelection, true);
124
        }
125
		if(clazz.equals(AgentBase.class)){
126
			return (T) AgentSelectionDialog.select(shell, //conversation,
127
			        (AgentBase) currentSelection, false);
128
		}
129
		if(clazz.equals(Feature.class)){
130
			return (T) FeatureSelectionDialog.select(shell, //conversation,
131
			        (Feature) currentSelection);
132
		}
133
		if(clazz.equals(FeatureTree.class)){
134
			return (T) FeatureTreeSelectionDialog.select(shell, //conversation,
135
			        (FeatureTree) currentSelection);
136
		}
137
		if(clazz.equals(PolytomousKey.class)){
138
			return (T) PolytomousKeySelectionDialog.select(shell, //conversation,
139
			        (PolytomousKey) currentSelection);
140
		}
141
		if(clazz.equals(PolytomousKeyNode.class)){
142
			MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
143
					"This functionality is not implemented yet.");
144
			return null;
145
		}
146
		if(clazz.equals(DerivedUnit.class)){
147
		    return (T) DerivedUnitSelectionDialog.select(shell, //conversation,
148
		            (DerivedUnit) currentSelection);
149
		}
150
		if(clazz.equals(FieldUnit.class)){
151
		    return (T) FieldUnitSelectionDialog.select(shell, //conversation,
152
		            (FieldUnit) currentSelection);
153
		}
154
		if(clazz.equals(SpecimenOrObservationBase.class)){
155
		    return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, //conversation,
156
		            (SpecimenOrObservationBase) currentSelection);
157
		}
158
		if(clazz.equals(NamedArea.class)){
159
		    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
160
		        return (T) NamedAreaSelectionDialog.select(shell, //conversation,
161
		                (NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);
162
		    }
163
		    else{
164
		        return (T) NamedAreaSelectionDialog.select(shell, //conversation,
165
		                (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
166
		    }
167
		}
168
		if(clazz.equals(Collection.class)){
169
			return (T) CollectionSelectionDialog.select(shell, //conversation,
170
			        (Collection) currentSelection);
171
		}
172
		if(clazz.equals(User.class)){
173
			return (T) UserSelectionDialog.select(shell, //conversation,
174
			        (User) currentSelection);
175
		}
176
		if(clazz.equals(GrantedAuthorityImpl.class)){
177
			return (T) GrantedAuthoritySelectionDialog.select(shell, //conversation,
178
			        (GrantedAuthorityImpl) currentSelection);
179
		}
180
		if (clazz.equals(Person.class)){
181
			return (T) PersonSelectionDialog.select(shell, //conversation,
182
			        (Person) currentSelection);
183
		}
184
		if(clazz.equals(Group.class)){
185
			return (T) GroupSelectionDialog.select(shell, //conversation,
186
			        (Group) currentSelection);
187
		}
188
		if(clazz.equals(Institution.class)){
189
			return (T) InstitutionSelectionDialog.select(shell, //conversation,
190
			        (Institution) currentSelection);
191
		}
192
		if(clazz.equals(Primer.class)){
193
		    return (T) PrimerSelectionDialog.select(shell, //conversation,
194
		            (Primer) currentSelection);
195
		}
196
		if(clazz.equals(Amplification.class)){
197
		    return (T) AmplificationSelectionDialog.select(shell, //conversation,
198
		            (Amplification) currentSelection);
199
		}
200
		if(clazz.equals(Media.class)){
201
		    return (T) MediaSelectionDialog.select(shell, //conversation,
202
		            (Media) currentSelection);
203
		}
204
		if(clazz.equals(Rights.class)){
205
            return (T) RightsSelectionDialog.select(shell, //conversation,
206
                    (Rights) currentSelection);
207
        }
208

    
209
		return null;
210
	}
211

    
212
	public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,
213
	        ICdmFormElement parentElement){
214
	    return (T) ExtReferenceSelectionDialog.select(shell, //conversation,
215
	            null);
216
	}
217

    
218

    
219
}
(34-34/43)