3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
12 import org
.eclipse
.swt
.widgets
.Shell
;
14 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
15 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
16 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.GrantedAuthorityImpl
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
23 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
25 import eu
.etaxonomy
.cdm
.model
.common
.User
;
26 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
27 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
28 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
29 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
30 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
31 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
32 import eu
.etaxonomy
.cdm
.model
.molecular
.Amplification
;
33 import eu
.etaxonomy
.cdm
.model
.molecular
.Primer
;
34 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
38 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
45 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
46 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
47 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
48 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEntityElement
;
49 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.TeamMemberElement
;
50 import eu
.etaxonomy
.taxeditor
.ui
.section
.description
.detail
.DistributionDetailElement
;
51 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.AuthorshipDetailElement
;
58 public class SelectionDialogFactory
{
60 public static <T
extends ICdmBase
> T
getSelectionFromDialog(Class
<T
> clazz
, Shell shell
, ConversationHolder conversation
, T currentSelection
){
61 return getSelectionFromDialog(clazz
, shell
, conversation
, currentSelection
, null);
64 public static <T
extends ICdmBase
> T
getSelectionFromDialog(Class
<T
> clazz
, Shell shell
, ConversationHolder conversation
, T currentSelection
, ICdmFormElement parentElement
){
66 if(clazz
.equals(Taxon
.class)){
67 return (T
) TaxonBaseSelectionDialog
.selectTaxon(shell
, conversation
, (Taxon
) currentSelection
);
69 if(clazz
.equals(Synonym
.class)){
70 return (T
) TaxonBaseSelectionDialog
.selectSynonym(shell
, conversation
);
72 if(clazz
.equals(TaxonBase
.class)){
73 return (T
) TaxonBaseSelectionDialog
.selectTaxonBase(shell
, conversation
);
75 if(clazz
.equals(Classification
.class)){
76 return (T
) ClassificationSelectionDialog
.select(shell
, conversation
, (Classification
) currentSelection
);
78 if(clazz
.equals(TaxonNode
.class)){
79 return (T
) TaxonNodeSelectionDialog
.select(shell
, conversation
, null, null, (TaxonNode
) currentSelection
, ((TaxonNode
) currentSelection
).getClassification());
81 if(clazz
.equals(Reference
.class)){
82 return (T
) ReferenceSelectionDialog
.select(shell
, conversation
, (Reference
) currentSelection
);
84 if(clazz
.equals(TaxonNameBase
.class)){
85 return (T
) NameSelectionDialog
.select(shell
, conversation
, (TaxonNameBase
) currentSelection
);
87 if(clazz
.equals(Team
.class)){
88 return (T
) TeamSelectionDialog
.select(shell
, conversation
, (Team
) currentSelection
);
90 if(clazz
.equals(TeamOrPersonBase
.class) && parentElement
instanceof AuthorshipDetailElement
){
91 return (T
) NomenclaturalAuthorSelectionDialog
.select(shell
, conversation
, (AgentBase
) currentSelection
);
92 }else if(clazz
.equals(TeamOrPersonBase
.class)){
93 //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
94 return (T
) AgentSelectionDialog
.select(shell
, conversation
, (AgentBase
) currentSelection
);
96 if(clazz
.equals(Person
.class) && parentElement
instanceof TeamMemberElement
){
97 return (T
) NomenclaturalAuthorSelectionDialog
.select(shell
, conversation
, (AgentBase
) currentSelection
);
99 if(clazz
.equals(AgentBase
.class)){
100 return (T
) AgentSelectionDialog
.select(shell
, conversation
, (AgentBase
) currentSelection
);
102 if(clazz
.equals(Feature
.class)){
103 return (T
) FeatureSelectionDialog
.select(shell
, conversation
, (Feature
) currentSelection
);
105 if(clazz
.equals(FeatureTree
.class)){
106 return (T
) FeatureTreeSelectionDialog
.select(shell
, conversation
, (FeatureTree
) currentSelection
);
108 if(clazz
.equals(PolytomousKey
.class)){
109 return (T
) PolytomousKeySelectionDialog
.select(shell
, conversation
, (PolytomousKey
) currentSelection
);
111 if(clazz
.equals(PolytomousKeyNode
.class)){
112 MessagingUtils
.warningDialog("Not implemented yet", SelectionDialogFactory
.class,
113 "This functionality is not implemented yet.");
116 if(clazz
.equals(DerivedUnit
.class)){
117 return (T
) DerivedUnitSelectionDialog
.select(shell
, conversation
, (DerivedUnit
) currentSelection
);
119 if(clazz
.equals(FieldUnit
.class)){
120 return (T
) FieldUnitSelectionDialog
.select(shell
, conversation
, (FieldUnit
) currentSelection
);
122 if(clazz
.equals(SpecimenOrObservationBase
.class)){
123 return (T
) SpecimenOrObservationBaseSelectionDialog
.select(shell
, conversation
, (SpecimenOrObservationBase
) currentSelection
);
125 if(clazz
.equals(NamedArea
.class)){
126 if(parentElement
instanceof DistributionDetailElement
){
127 return (T
) NamedAreaSelectionForDistributionDialog
.select(shell
, conversation
, (NamedArea
) currentSelection
, CdmStore
.getTermManager().getPreferredVocabulary(TermType
.NamedArea
));
128 }else if(parentElement
instanceof IEntityElement
&& ((IEntityElement
) parentElement
).getEntity() instanceof DerivedUnitFacade
){
129 return (T
) NamedAreaSelectionDialog
.select(shell
, conversation
, (NamedArea
) currentSelection
, Country
.uuidCountryVocabulary
);
132 return (T
) NamedAreaSelectionDialog
.select(shell
, conversation
, (NamedArea
) currentSelection
);
135 if(clazz
.equals(Collection
.class)){
136 return (T
) CollectionSelectionDialog
.select(shell
, conversation
, (Collection
) currentSelection
);
138 if(clazz
.equals(User
.class)){
139 return (T
) UserSelectionDialog
.select(shell
, conversation
, (User
) currentSelection
);
141 if(clazz
.equals(GrantedAuthorityImpl
.class)){
142 return (T
) GrantedAuthoritySelectionDialog
.select(shell
, conversation
, (GrantedAuthorityImpl
) currentSelection
);
144 if (clazz
.equals(Person
.class)){
145 return (T
) PersonSelectionDialog
.select(shell
, conversation
, (Person
) currentSelection
);
147 if(clazz
.equals(Group
.class)){
148 return (T
) GroupSelectionDialog
.select(shell
, conversation
, (Group
) currentSelection
);
150 if(clazz
.equals(Institution
.class)){
151 return (T
) InstitutionSelectionDialog
.select(shell
, conversation
, (Institution
) currentSelection
);
153 if(clazz
.equals(Primer
.class)){
154 return (T
) PrimerSelectionDialog
.select(shell
, conversation
, (Primer
) currentSelection
);
156 if(clazz
.equals(Amplification
.class)){
157 return (T
) AmplificationSelectionDialog
.select(shell
, conversation
, (Amplification
) currentSelection
);