Project

General

Profile

Download (6.59 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11

    
12
import org.eclipse.swt.widgets.Shell;
13

    
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.User;
25
import eu.etaxonomy.cdm.model.description.Feature;
26
import eu.etaxonomy.cdm.model.description.FeatureTree;
27
import eu.etaxonomy.cdm.model.description.PolytomousKey;
28
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
29
import eu.etaxonomy.cdm.model.location.Country;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.model.molecular.Amplification;
32
import eu.etaxonomy.cdm.model.molecular.Primer;
33
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
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.ui.element.ICdmFormElement;
46
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
47

    
48
/**
49
 * @author n.hoffmann
50
 * @date Jan 25, 2012
51
 *
52
 */
53
public class SelectionDialogFactory {
54

    
55
    public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
56
        return getSelectionFromDialog(clazz, shell, conversation, currentSelection, null);
57
    }
58

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

    
61
		if(clazz.equals(Taxon.class)){
62
			return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
63
		}
64
		if(clazz.equals(Synonym.class)){
65
			return (T) TaxonBaseSelectionDialog.selectSynonym(shell, conversation);
66
		}
67
		if(clazz.equals(TaxonBase.class)){
68
			return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell, conversation);
69
		}
70
		if(clazz.equals(Classification.class)){
71
			return (T) ClassificationSelectionDialog.select(shell, conversation, (Classification) currentSelection);
72
		}
73
		if(clazz.equals(TaxonNode.class)){
74
			return (T) TaxonNodeSelectionDialog.select(shell, conversation, null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification());
75
		}
76
		if(clazz.equals(Reference.class)){
77
			return (T) ReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection);
78
		}
79
		if(clazz.equals(TaxonNameBase.class)){
80
			return (T) NameSelectionDialog.select(shell, conversation, (TaxonNameBase) currentSelection);
81
		}
82
		if(clazz.equals(Team.class)){
83
			return (T) TeamSelectionDialog.select(shell, conversation, (Team) currentSelection);
84
		}
85
		if(clazz.equals(TeamOrPersonBase.class)){
86
		    //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
87
		    return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection);
88
		}
89
		if(clazz.equals(AgentBase.class)){
90
			return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection);
91
		}
92
		if(clazz.equals(Feature.class)){
93
			return (T) FeatureSelectionDialog.select(shell, conversation, (Feature) currentSelection);
94
		}
95
		if(clazz.equals(FeatureTree.class)){
96
			return (T) FeatureTreeSelectionDialog.select(shell, conversation, (FeatureTree) currentSelection);
97
		}
98
		if(clazz.equals(PolytomousKey.class)){
99
			return (T) PolytomousKeySelectionDialog.select(shell, conversation, (PolytomousKey) currentSelection);
100
		}
101
		if(clazz.equals(PolytomousKeyNode.class)){
102
			MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
103
					"This functionality is not implemented yet.");
104
			return null;
105
		}
106
		if(clazz.equals(DerivedUnit.class)){
107
		    return (T) DerivedUnitSelectionDialog.select(shell, conversation, (DerivedUnit) currentSelection);
108
		}
109
		if(clazz.equals(FieldUnit.class)){
110
		    return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
111
		}
112
		if(clazz.equals(SpecimenOrObservationBase.class)){
113
		    return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, conversation, (SpecimenOrObservationBase) currentSelection);
114
		}
115
		if(clazz.equals(NamedArea.class)){
116
		    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
117
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection, Country.uuidCountryVocabulary);
118
		    }
119
		    else{
120
		        return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
121
		    }
122
		}
123
		if(clazz.equals(Collection.class)){
124
			return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
125
		}
126
		if(clazz.equals(User.class)){
127
			return (T) UserSelectionDialog.select(shell, conversation, (User) currentSelection);
128
		}
129
		if(clazz.equals(GrantedAuthorityImpl.class)){
130
			return (T) GrantedAuthoritySelectionDialog.select(shell, conversation, (GrantedAuthorityImpl) currentSelection);
131
		}
132
		if (clazz.equals(Person.class)){
133
			return (T) PersonSelectionDialog.select(shell, conversation, (Person) currentSelection);
134
		}
135
		if(clazz.equals(Group.class)){
136
			return (T) GroupSelectionDialog.select(shell, conversation, (Group) currentSelection);
137
		}
138
		if(clazz.equals(Institution.class)){
139
			return (T) InstitutionSelectionDialog.select(shell, conversation, (Institution) currentSelection);
140
		}
141
		if(clazz.equals(Primer.class)){
142
		    return (T) PrimerSelectionDialog.select(shell, conversation, (Primer) currentSelection);
143
		}
144
		if(clazz.equals(Amplification.class)){
145
		    return (T) AmplificationSelectionDialog.select(shell, conversation, (Amplification) currentSelection);
146
		}
147

    
148
		return null;
149
	}
150

    
151
}
(23-23/30)