Project

General

Profile

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

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

    
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);
62
    }
63

    
64
	public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection, ICdmFormElement parentElement){
65

    
66
		if(clazz.equals(Taxon.class)){
67
			return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
68
		}
69
		if(clazz.equals(Synonym.class)){
70
			return (T) TaxonBaseSelectionDialog.selectSynonym(shell, conversation);
71
		}
72
		if(clazz.equals(TaxonBase.class)){
73
			return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell, conversation);
74
		}
75
		if(clazz.equals(Classification.class)){
76
			return (T) ClassificationSelectionDialog.select(shell, conversation, (Classification) currentSelection);
77
		}
78
		if(clazz.equals(TaxonNode.class)){
79
			return (T) TaxonNodeSelectionDialog.select(shell, conversation, null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification());
80
		}
81
		if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){
82
			return (T) NomenclaturalReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship());
83
		}
84
		if(clazz.equals(Reference.class)){
85
		    if (parentElement instanceof ReferenceDetailElement){
86
		        return (T) ReferenceSelectionDialog.select(shell, conversation, ((ReferenceDetailElement) parentElement).getEntity(), true);
87
		    }
88
			return (T) ReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection);
89
		}
90

    
91
		if(clazz.equals(TaxonName.class)){
92
			return (T) NameSelectionDialog.select(shell, conversation, (TaxonName) currentSelection);
93
		}
94
		if(clazz.equals(Team.class)){
95
			return (T) TeamSelectionDialog.select(shell, conversation, (Team) currentSelection);
96
		}
97
		if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){
98
            return (T) NomenclaturalAuthorSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, false);
99
        }else if(clazz.equals(TeamOrPersonBase.class)){
100
		    //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
101
		    return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, false);
102
		}
103
		if(clazz.equals(Person.class) && parentElement instanceof TeamMemberElement){
104
		    return (T) NomenclaturalPersonAuthorSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, true);
105
        }
106
		if(clazz.equals(AgentBase.class)){
107
			return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection, false);
108
		}
109
		if(clazz.equals(Feature.class)){
110
			return (T) FeatureSelectionDialog.select(shell, conversation, (Feature) currentSelection);
111
		}
112
		if(clazz.equals(FeatureTree.class)){
113
			return (T) FeatureTreeSelectionDialog.select(shell, conversation, (FeatureTree) currentSelection);
114
		}
115
		if(clazz.equals(PolytomousKey.class)){
116
			return (T) PolytomousKeySelectionDialog.select(shell, conversation, (PolytomousKey) currentSelection);
117
		}
118
		if(clazz.equals(PolytomousKeyNode.class)){
119
			MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
120
					"This functionality is not implemented yet.");
121
			return null;
122
		}
123
		if(clazz.equals(DerivedUnit.class)){
124
		    return (T) DerivedUnitSelectionDialog.select(shell, conversation, (DerivedUnit) currentSelection);
125
		}
126
		if(clazz.equals(FieldUnit.class)){
127
		    return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
128
		}
129
		if(clazz.equals(SpecimenOrObservationBase.class)){
130
		    return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, conversation, (SpecimenOrObservationBase) currentSelection);
131
		}
132
		if(clazz.equals(NamedArea.class)){
133
		    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
134
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, DerivedUnit.class.getCanonicalName(), Country.uuidCountryVocabulary);
135
		    }
136
		    else{
137
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, parentElement.getClass().getCanonicalName());
138
		    }
139
		}
140
		if(clazz.equals(Collection.class)){
141
			return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
142
		}
143
		if(clazz.equals(User.class)){
144
			return (T) UserSelectionDialog.select(shell, conversation, (User) currentSelection);
145
		}
146
		if(clazz.equals(GrantedAuthorityImpl.class)){
147
			return (T) GrantedAuthoritySelectionDialog.select(shell, conversation, (GrantedAuthorityImpl) currentSelection);
148
		}
149
		if (clazz.equals(Person.class)){
150
			return (T) PersonSelectionDialog.select(shell, conversation, (Person) currentSelection);
151
		}
152
		if(clazz.equals(Group.class)){
153
			return (T) GroupSelectionDialog.select(shell, conversation, (Group) currentSelection);
154
		}
155
		if(clazz.equals(Institution.class)){
156
			return (T) InstitutionSelectionDialog.select(shell, conversation, (Institution) currentSelection);
157
		}
158
		if(clazz.equals(Primer.class)){
159
		    return (T) PrimerSelectionDialog.select(shell, conversation, (Primer) currentSelection);
160
		}
161
		if(clazz.equals(Amplification.class)){
162
		    return (T) AmplificationSelectionDialog.select(shell, conversation, (Amplification) currentSelection);
163
		}
164
		if(clazz.equals(Media.class)){
165
		    return (T) MediaSelectionDialog.select(shell, conversation, (Media) currentSelection);
166
		}
167
		if(clazz.equals(Rights.class)){
168
            return (T) RightsSelectionDialog.select(shell, conversation, (Rights) currentSelection);
169
        }
170

    
171
		return null;
172
	}
173

    
174
	public static <T extends ICdmBase> T getSelectionFromExtDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, ICdmFormElement parentElement){
175
	    return (T) ExtReferenceSelectionDialog.select(shell, conversation, null);
176
	}
177

    
178

    
179
}
(32-32/40)