2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import org
.eclipse
.swt
.widgets
.Shell
;
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
.reference
.NomenclaturalReferenceDetailElement
;
59 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.ReferenceDetailElement
;
60 import eu
.etaxonomy
.taxeditor
.ui
.section
.user
.GroupsByUserDetailElement
;
61 import eu
.etaxonomy
.taxeditor
.ui
.section
.user
.GroupsByUserDetailSection
;
68 public class SelectionDialogFactory
{
70 public static <T
extends ICdmBase
> T
getSelectionFromDialog(Class
<T
> clazz
, Shell shell
, //ConversationHolder conversation,
72 return getSelectionFromDialog(clazz
, shell
, //conversation,
73 currentSelection
, null);
76 public static <T
extends ICdmBase
> T
getSelectionFromDialog(Class
<T
> clazz
, Shell shell
, //ConversationHolder conversation,
77 T currentSelection
, ICdmFormElement parentElement
){
79 if(clazz
.equals(Taxon
.class)){
80 return (T
) TaxonSelectionDialog
.selectTaxon(shell
, //conversation,
81 (Taxon
) currentSelection
);
83 if(clazz
.equals(Synonym
.class)){
84 return (T
) TaxonBaseSelectionDialog
.selectSynonym(shell
);//,conversation);
86 if(clazz
.equals(TaxonBase
.class)){
87 return (T
) TaxonBaseSelectionDialog
.selectTaxonBase(shell
);//, conversation);
89 if(clazz
.equals(Classification
.class)){
90 return (T
) ClassificationSelectionDialog
.select(shell
, //conversation,
91 (Classification
) currentSelection
);
93 if(clazz
.equals(TaxonNode
.class)){
94 return (T
) TaxonNodeSelectionDialog
.select(shell
, //conversation,
95 null, null, (TaxonNode
) currentSelection
, ((TaxonNode
) currentSelection
).getClassification().getUuid());
97 if(clazz
.equals(Reference
.class) && parentElement
!= null && parentElement
.getParentElement() instanceof NomenclaturalReferenceDetailElement
){
98 return (T
) NomenclaturalReferenceSelectionDialog
.select(shell
, //conversation,
99 (Reference
) currentSelection
, ((NomenclaturalReferenceDetailElement
)parentElement
.getParentElement()).getEntity().getCombinationAuthorship());
101 if(clazz
.equals(Reference
.class) && parentElement
instanceof CommonNameSourceElement
&& PreferencesUtil
.getFilterCommonNameReferences()){
102 return (T
) CommonNameReferenceSelectionDialog
.select(shell
, //conversation,
103 (Reference
) currentSelection
);
105 if(clazz
.equals(Reference
.class)){
106 if (parentElement
instanceof ReferenceDetailElement
){
107 return (T
) ReferenceSelectionDialog
.select(shell
, //conversation,
108 ((ReferenceDetailElement
) parentElement
).getEntity(), true);
110 return (T
) ReferenceSelectionDialog
.select(shell
, //conversation,
111 (Reference
) currentSelection
);
114 if(clazz
.equals(TaxonName
.class)){
115 return (T
) NameSelectionDialog
.select(shell
, //conversation,
116 (TaxonName
) currentSelection
);
118 if(clazz
.equals(Team
.class)){
119 return (T
) TeamSelectionDialog
.select(shell
, //conversation,
120 (Team
) currentSelection
);
122 if(clazz
.equals(TeamOrPersonBase
.class) && parentElement
instanceof AuthorshipDetailElement
){
123 return (T
) NomenclaturalAuthorSelectionDialog
.select(shell
, //conversation,
124 (TeamOrPersonBase
) currentSelection
, false);
125 }else if(clazz
.equals(TeamOrPersonBase
.class)){
126 //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
127 return (T
) TeamOrPersonBaseSelectionDialog
.select(shell
, //conversation,
128 (TeamOrPersonBase
) currentSelection
, false);
130 if(clazz
.equals(Person
.class) && parentElement
instanceof TeamMemberElement
){
131 return (T
) NomenclaturalPersonAuthorSelectionDialog
.select(shell
, //conversation,
132 (TeamOrPersonBase
) currentSelection
, true);
134 if(clazz
.equals(AgentBase
.class)){
135 return (T
) AgentSelectionDialog
.select(shell
, //conversation,
136 (AgentBase
) currentSelection
, false);
138 if(clazz
.equals(Feature
.class)){
139 return (T
) FeatureSelectionDialog
.select(shell
, //conversation,
140 (Feature
) currentSelection
);
142 if(clazz
.equals(TermTree
.class)){
143 return (T
) FeatureTreeSelectionDialog
.select(shell
, //conversation,
144 (TermTree
) currentSelection
);
146 if(clazz
.equals(PolytomousKey
.class)){
147 return (T
) PolytomousKeySelectionDialog
.select(shell
, //conversation,
148 (PolytomousKey
) currentSelection
);
150 if(clazz
.equals(PolytomousKeyNode
.class)){
151 MessagingUtils
.warningDialog("Not implemented yet", SelectionDialogFactory
.class,
152 "This functionality is not implemented yet.");
155 if(clazz
.equals(DerivedUnit
.class)){
156 return (T
) DerivedUnitSelectionDialog
.select(shell
, //conversation,
157 (DerivedUnit
) currentSelection
);
159 if(clazz
.equals(FieldUnit
.class)){
160 return (T
) FieldUnitSelectionDialog
.select(shell
, //conversation,
161 (FieldUnit
) currentSelection
);
163 if(clazz
.equals(SpecimenOrObservationBase
.class)){
164 return (T
) SpecimenOrObservationBaseSelectionDialog
.select(shell
, //conversation,
165 (SpecimenOrObservationBase
) currentSelection
);
167 if(clazz
.equals(NamedArea
.class)){
168 if(parentElement
instanceof IEntityElement
&& ((IEntityElement
) parentElement
).getEntity() instanceof DerivedUnitFacade
){
169 return (T
) NamedAreaSelectionDialog
.select(shell
, //conversation,
170 (NamedArea
) currentSelection
, DerivedUnit
.class.getCanonicalName(), Country
.uuidCountryVocabulary
);
172 else if(parentElement
instanceof CommonNameDetailElement
){
173 return (T
) CommonNameNamedAreaSelectionDialog
.select(shell
, //conversation,
174 (NamedArea
) currentSelection
, parentElement
.getClass().getCanonicalName());
178 List
<UUID
> uuidList
= PreferencesUtil
.createUUIDListFromStringPref(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey(), false);
179 UUID
[] uuidArray
= null;
180 if (uuidList
!= null){
181 uuidArray
= new UUID
[uuidList
.size()];
182 uuidList
.toArray(uuidArray
);
185 return (T
)NamedAreaSelectionDialog
.select(shell
, (NamedArea
) currentSelection
, null, uuidArray
);
189 if(clazz
.equals(Collection
.class)){
190 return (T
) CollectionSelectionDialog
.select(shell
, //conversation,
191 (Collection
) currentSelection
);
193 if(clazz
.equals(User
.class) && parentElement
instanceof MemberDetailElement
){
194 MemberDetailSection section
= (MemberDetailSection
)((MemberDetailElement
)parentElement
).getParentElement();
195 return (T
) UserSelectionDialog
.select(shell
, //conversation,
196 (User
) currentSelection
, section
.getEntity());
198 if(clazz
.equals(GrantedAuthorityImpl
.class)){
199 return (T
) GrantedAuthoritySelectionDialog
.select(shell
, //conversation,
200 (GrantedAuthorityImpl
) currentSelection
);
202 if (clazz
.equals(Person
.class)){
203 return (T
) PersonSelectionDialog
.select(shell
, //conversation,
204 (Person
) currentSelection
);
206 if(clazz
.equals(Group
.class) && parentElement
instanceof GroupsByUserDetailElement
){
207 GroupsByUserDetailSection section
=(GroupsByUserDetailSection
)((GroupsByUserDetailElement
)parentElement
).getParentElement();
208 return (T
) GroupSelectionDialog
.select(shell
, //conversation,
209 (Group
) currentSelection
, section
.getEntity());
211 if(clazz
.equals(Institution
.class)){
212 return (T
) InstitutionSelectionDialog
.select(shell
, //conversation,
213 (Institution
) currentSelection
);
215 if(clazz
.equals(Primer
.class)){
216 return (T
) PrimerSelectionDialog
.select(shell
, //conversation,
217 (Primer
) currentSelection
);
219 if(clazz
.equals(Amplification
.class)){
220 return (T
) AmplificationSelectionDialog
.select(shell
, //conversation,
221 (Amplification
) currentSelection
);
223 if(clazz
.equals(Media
.class)){
224 return (T
) MediaSelectionDialog
.select(shell
, //conversation,
225 (Media
) currentSelection
);
227 if(clazz
.equals(Rights
.class)){
228 return (T
) RightsSelectionDialog
.select(shell
, //conversation,
229 (Rights
) currentSelection
);
235 public static <T
extends ICdmBase
> T
getSelectionFromExtDialog(Class
<T
> clazz
, Shell shell
, //ConversationHolder conversation,
236 ICdmFormElement parentElement
){
237 return (T
) ExtReferenceSelectionDialog
.select(shell
, //conversation,