Project

General

Profile

Download (9.71 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.description.detail.CommonNameDetailElement;
51
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
52
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
53
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
54

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

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

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

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

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

    
214
		return null;
215
	}
216

    
217
	public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, //ConversationHolder conversation,
218
	        ICdmFormElement parentElement){
219
	    return (T) ExtReferenceSelectionDialog.select(shell, //conversation,
220
	            null);
221
	}
222

    
223

    
224
}
(35-35/44)