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 java.util.List;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.eclipse.swt.widgets.Shell;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
17
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
18
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
19
|
import eu.etaxonomy.cdm.model.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.agent.Team;
|
21
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
22
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
23
|
import eu.etaxonomy.cdm.model.description.Feature;
|
24
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
25
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
26
|
import eu.etaxonomy.cdm.model.location.Country;
|
27
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
28
|
import eu.etaxonomy.cdm.model.media.Media;
|
29
|
import eu.etaxonomy.cdm.model.media.Rights;
|
30
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
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.permission.GrantedAuthorityImpl;
|
39
|
import eu.etaxonomy.cdm.model.permission.Group;
|
40
|
import eu.etaxonomy.cdm.model.permission.User;
|
41
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
42
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
45
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
46
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
47
|
import eu.etaxonomy.cdm.model.term.TermTree;
|
48
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
49
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
50
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
51
|
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
|
52
|
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
|
53
|
import eu.etaxonomy.taxeditor.ui.section.description.CommonNameSourceElement;
|
54
|
import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;
|
55
|
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;
|
56
|
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;
|
57
|
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
|
58
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralDetailElement;
|
59
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitFacadeGeneralDetailElement;
|
60
|
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
|
61
|
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
|
62
|
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
|
63
|
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
|
64
|
|
65
|
/**
|
66
|
* @author n.hoffmann
|
67
|
* @date Jan 25, 2012
|
68
|
*/
|
69
|
public class SelectionDialogFactory {
|
70
|
|
71
|
public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell,
|
72
|
T currentSelection){
|
73
|
return getSelectionFromDialog(clazz, shell, //conversation,
|
74
|
currentSelection, null);
|
75
|
}
|
76
|
|
77
|
public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell,
|
78
|
T currentSelection, ICdmFormElement parentElement){
|
79
|
|
80
|
if(clazz.equals(Taxon.class)){
|
81
|
return (T) TaxonSelectionDialog.selectTaxon(shell, (Taxon) currentSelection);
|
82
|
}
|
83
|
if(clazz.equals(Synonym.class)){
|
84
|
return (T) TaxonBaseSelectionDialog.selectSynonym(shell );
|
85
|
}
|
86
|
if(clazz.equals(TaxonBase.class)){
|
87
|
return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell);
|
88
|
}
|
89
|
if(clazz.equals(Classification.class)){
|
90
|
return (T) ClassificationSelectionDialog.select(shell, (Classification) currentSelection);
|
91
|
}
|
92
|
if(clazz.equals(TaxonNode.class)){
|
93
|
return (T) TaxonNodeSelectionDialog.select(shell,
|
94
|
null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid());
|
95
|
}
|
96
|
if(clazz.equals(Reference.class) && parentElement != null && parentElement.getParentElement() instanceof NomenclaturalReferenceDetailElement){
|
97
|
return (T) NomenclaturalReferenceSelectionDialog.select(shell,
|
98
|
(Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement.getParentElement()).getEntity().getCombinationAuthorship());
|
99
|
}
|
100
|
if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){
|
101
|
return (T) CommonNameReferenceSelectionDialog.select(shell,
|
102
|
(Reference) currentSelection);
|
103
|
}
|
104
|
if(clazz.equals(Reference.class)){
|
105
|
if (parentElement instanceof ReferenceDetailElement){
|
106
|
return (T) ReferenceSelectionDialog.select(shell,
|
107
|
((ReferenceDetailElement) parentElement).getEntity(), true);
|
108
|
}
|
109
|
return (T) ReferenceSelectionDialog.select(shell, (Reference) currentSelection);
|
110
|
}
|
111
|
|
112
|
if(clazz.equals(TaxonName.class)){
|
113
|
return (T) NameSelectionDialog.select(shell, (TaxonName)currentSelection);
|
114
|
}
|
115
|
if(clazz.equals(Team.class)){
|
116
|
return (T) TeamSelectionDialog.select(shell, (Team)currentSelection);
|
117
|
}
|
118
|
if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){
|
119
|
return (T) NomenclaturalAuthorSelectionDialog.select(shell,
|
120
|
(TeamOrPersonBase) currentSelection, false);
|
121
|
}else if(clazz.equals(AgentBase.class) && (parentElement instanceof FieldUnitFacadeGeneralDetailElement || parentElement instanceof DerivedUnitGeneralDetailElement)){
|
122
|
return (T) CollectorSelectionDialog.select(shell,
|
123
|
(TeamOrPersonBase) currentSelection, false);
|
124
|
}else if(clazz.equals(TeamOrPersonBase.class)){
|
125
|
//TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
|
126
|
return (T) TeamOrPersonBaseSelectionDialog.select(shell,
|
127
|
(TeamOrPersonBase) currentSelection, false);
|
128
|
}
|
129
|
if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){
|
130
|
return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell,
|
131
|
(TeamOrPersonBase) currentSelection, true);
|
132
|
}
|
133
|
if(clazz.equals(AgentBase.class)){
|
134
|
return (T) AgentSelectionDialog.select(shell, (AgentBase)currentSelection, false);
|
135
|
}
|
136
|
if(clazz.equals(Feature.class)){
|
137
|
return (T) FeatureSelectionDialog.select(shell, (Feature)currentSelection);
|
138
|
}
|
139
|
if(clazz.equals(TermTree.class)){
|
140
|
return (T) FeatureTreeSelectionDialog.select(shell, (TermTree)currentSelection);
|
141
|
}
|
142
|
if(clazz.equals(PolytomousKey.class)){
|
143
|
return (T) PolytomousKeySelectionDialog.select(shell, (PolytomousKey)currentSelection);
|
144
|
}
|
145
|
if(clazz.equals(PolytomousKeyNode.class)){
|
146
|
MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
|
147
|
"This functionality is not implemented yet.");
|
148
|
return null;
|
149
|
}
|
150
|
if(clazz.equals(DerivedUnit.class)){
|
151
|
return (T) DerivedUnitSelectionDialog.select(shell, (DerivedUnit) currentSelection);
|
152
|
}
|
153
|
if(clazz.equals(FieldUnit.class)){
|
154
|
return (T) FieldUnitSelectionDialog.select(shell, (FieldUnit) currentSelection);
|
155
|
}
|
156
|
if(clazz.equals(SpecimenOrObservationBase.class)){
|
157
|
return (T) SpecimenOrObservationBaseSelectionDialog.select(shell,
|
158
|
(SpecimenOrObservationBase) currentSelection);
|
159
|
}
|
160
|
if(clazz.equals(NamedArea.class)){
|
161
|
if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
|
162
|
return (T) NamedAreaSelectionDialog.select(shell,
|
163
|
(NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);
|
164
|
}
|
165
|
else if(parentElement instanceof CommonNameDetailElement ){
|
166
|
return (T) CommonNameNamedAreaSelectionDialog.select(shell,
|
167
|
(NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
|
168
|
}
|
169
|
else{
|
170
|
List<UUID> uuidList = PreferencesUtil.createUUIDListFromStringPref(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), false);
|
171
|
UUID[] uuidArray = null;
|
172
|
if (uuidList != null){
|
173
|
uuidArray = new UUID[uuidList.size()];
|
174
|
uuidList.toArray(uuidArray);
|
175
|
}
|
176
|
return (T)NamedAreaSelectionDialog.select(shell, (NamedArea) currentSelection, null, uuidArray);
|
177
|
}
|
178
|
}
|
179
|
if(clazz.equals(Collection.class)){
|
180
|
return (T) CollectionSelectionDialog.select(shell, (Collection) currentSelection);
|
181
|
}
|
182
|
if(clazz.equals(User.class) && parentElement instanceof MemberDetailElement){
|
183
|
MemberDetailSection section = (MemberDetailSection)((MemberDetailElement)parentElement).getParentElement();
|
184
|
return (T) UserSelectionDialog.select(shell,(User) currentSelection, section.getEntity());
|
185
|
}
|
186
|
if(clazz.equals(GrantedAuthorityImpl.class)){
|
187
|
return (T) GrantedAuthoritySelectionDialog.select(shell, (GrantedAuthorityImpl)currentSelection);
|
188
|
}
|
189
|
if (clazz.equals(Person.class)){
|
190
|
return (T) PersonSelectionDialog.select(shell, (Person)currentSelection);
|
191
|
}
|
192
|
if(clazz.equals(Group.class) && parentElement instanceof GroupsByUserDetailElement){
|
193
|
GroupsByUserDetailSection section =(GroupsByUserDetailSection)((GroupsByUserDetailElement)parentElement).getParentElement();
|
194
|
return (T) GroupSelectionDialog.select(shell, (Group)currentSelection, section.getEntity());
|
195
|
}
|
196
|
if(clazz.equals(Institution.class)){
|
197
|
return (T) InstitutionSelectionDialog.select(shell, (Institution)currentSelection);
|
198
|
}
|
199
|
if(clazz.equals(Primer.class)){
|
200
|
return (T) PrimerSelectionDialog.select(shell, (Primer)currentSelection);
|
201
|
}
|
202
|
if(clazz.equals(Amplification.class)){
|
203
|
return (T) AmplificationSelectionDialog.select(shell, (Amplification)currentSelection);
|
204
|
}
|
205
|
if(clazz.equals(Media.class)){
|
206
|
return (T) MediaSelectionDialog.select(shell, (Media)currentSelection);
|
207
|
}
|
208
|
if(clazz.equals(Rights.class)){
|
209
|
return (T) RightsSelectionDialog.select(shell, (Rights)currentSelection);
|
210
|
}
|
211
|
|
212
|
return null;
|
213
|
}
|
214
|
|
215
|
public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell,
|
216
|
ICdmFormElement parentElement){
|
217
|
return (T) ExtReferenceSelectionDialog.select(shell, null);
|
218
|
}
|
219
|
}
|