54a28eb90e8da393a1672ef28cd52aa29d2a9c58
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / SelectionDialogFactory.java
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.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.NamedArea;
29 import eu.etaxonomy.cdm.model.molecular.Amplification;
30 import eu.etaxonomy.cdm.model.molecular.Primer;
31 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
32 import eu.etaxonomy.cdm.model.occurrence.Collection;
33 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
34 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
35 import eu.etaxonomy.cdm.model.reference.Reference;
36 import eu.etaxonomy.cdm.model.taxon.Classification;
37 import eu.etaxonomy.cdm.model.taxon.Synonym;
38 import eu.etaxonomy.cdm.model.taxon.Taxon;
39 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
40 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
41 import eu.etaxonomy.taxeditor.model.MessagingUtils;
42
43 /**
44 * @author n.hoffmann
45 * @date Jan 25, 2012
46 *
47 */
48 public class SelectionDialogFactory {
49
50 public static <T extends ICdmBase> T getSelectionFromDialog(Class<T> clazz, Shell shell, ConversationHolder conversation, T currentSelection){
51
52 if(clazz.equals(Taxon.class)){
53 return (T) TaxonBaseSelectionDialog.selectTaxon(shell, conversation, (Taxon) currentSelection);
54 }
55 if(clazz.equals(Synonym.class)){
56 return (T) TaxonBaseSelectionDialog.selectSynonym(shell, conversation);
57 }
58 if(clazz.equals(TaxonBase.class)){
59 return (T) TaxonBaseSelectionDialog.selectTaxonBase(shell, conversation);
60 }
61 if(clazz.equals(Classification.class)){
62 return (T) ClassificationSelectionDialog.select(shell, conversation, (Classification) currentSelection);
63 }
64 if(clazz.equals(TaxonNode.class)){
65 return (T) TaxonNodeSelectionDialog.select(shell, conversation, null, null, (TaxonNode) currentSelection, null);
66 }
67 if(clazz.equals(Reference.class)){
68 return (T) ReferenceSelectionDialog.select(shell, conversation, (Reference) currentSelection);
69 }
70 if(clazz.equals(TaxonNameBase.class)){
71 return (T) NameSelectionDialog.select(shell, conversation, (TaxonNameBase) currentSelection);
72 }
73 if(clazz.equals(Team.class)){
74 return (T) TeamSelectionDialog.select(shell, conversation, (Team) currentSelection);
75 }
76 if(clazz.equals(TeamOrPersonBase.class)){
77 //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
78 return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection);
79 }
80 if(clazz.equals(AgentBase.class)){
81 return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection);
82 }
83 if(clazz.equals(Feature.class)){
84 return (T) FeatureSelectionDialog.select(shell, conversation, (Feature) currentSelection);
85 }
86 if(clazz.equals(FeatureTree.class)){
87 return (T) FeatureTreeSelectionDialog.select(shell, conversation, (FeatureTree) currentSelection);
88 }
89 if(clazz.equals(PolytomousKey.class)){
90 return (T) PolytomousKeySelectionDialog.select(shell, conversation, (PolytomousKey) currentSelection);
91 }
92 if(clazz.equals(PolytomousKeyNode.class)){
93 MessagingUtils.warningDialog("Not implemented yet", SelectionDialogFactory.class,
94 "This functionality is not implemented yet.");
95 return null;
96 }
97 if(clazz.equals(DerivedUnit.class)){
98 return (T) DerivedUnitSelectionDialog.select(shell, conversation, (DerivedUnit) currentSelection);
99 }
100 if(clazz.equals(FieldUnit.class)){
101 return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
102 }
103 if(clazz.equals(NamedArea.class)){
104 return (T) NamedAreaSelectionDialog.select(shell, conversation, (NamedArea) currentSelection);
105 }
106 if(clazz.equals(Collection.class)){
107 return (T) CollectionSelectionDialog.select(shell, conversation, (Collection) currentSelection);
108 }
109 if(clazz.equals(User.class)){
110 return (T) UserSelectionDialog.select(shell, conversation, (User) currentSelection);
111 }
112 if(clazz.equals(GrantedAuthorityImpl.class)){
113 return (T) GrantedAuthoritySelectionDialog.select(shell, conversation, (GrantedAuthorityImpl) currentSelection);
114 }
115 if (clazz.equals(Person.class)){
116 return (T) PersonSelectionDialog.select(shell, conversation, (Person) currentSelection);
117 }
118 if(clazz.equals(Group.class)){
119 return (T) GroupSelectionDialog.select(shell, conversation, (Group) currentSelection);
120 }
121 if(clazz.equals(Institution.class)){
122 return (T) InstitutionSelectionDialog.select(shell, conversation, (Institution) currentSelection);
123 }
124 if(clazz.equals(Primer.class)){
125 return (T) PrimerSelectionDialog.select(shell, conversation, (Primer) currentSelection);
126 }
127 if(clazz.equals(Amplification.class)){
128 return (T) AmplificationSelectionDialog.select(shell, conversation, (Amplification) currentSelection);
129 }
130
131 return null;
132 }
133
134 }