6fa85297dc6f3dd9578a403c2572bb32b187051e
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / BulkEditorInputTypeValues.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.bulkeditor.input;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.eclipse.core.commands.IParameterValues;
17 import org.eclipse.ui.IEditorInput;
18
19 import eu.etaxonomy.cdm.model.agent.AgentBase;
20 import eu.etaxonomy.cdm.model.common.Group;
21 import eu.etaxonomy.cdm.model.common.User;
22 import eu.etaxonomy.cdm.model.name.NameRelationship;
23 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
25 import eu.etaxonomy.cdm.model.reference.Reference;
26
27 /**
28 * <p>
29 * BulkEditorInputTypeValues class.
30 * </p>
31 *
32 * @author p.ciardelli
33 * @created 20.08.2009
34 * @version 1.0
35 */
36 public class BulkEditorInputTypeValues implements IParameterValues {
37
38 public enum BulkEditorInputType {
39 REFERENCE("Reference", ReferenceEditorInput.ID), NAME("Name",
40 NameEditorInput.ID), AGENT("Authors and Author Teams",
41 AgentEditorInput.ID), OCCURRENCE("Specimens and Observations",
42 OccurrenceEditorInput.ID), NAME_RELATIONSHIP(
43 "Name Relationship", NameRelationshipEditorInput.ID), USER(
44 "User", UserEditorInput.ID), GROUP("Group", GroupEditorInput.ID);
45
46 public String id;
47 public String label;
48
49 BulkEditorInputType(String label, String id) {
50 this.id = id;
51 this.label = label;
52 }
53
54 public static BulkEditorInputType getById(String id) {
55
56 for (BulkEditorInputType type : values()) {
57 if (id.equals(type.id)) {
58 return type;
59 }
60 }
61
62 return null;
63 }
64
65 public static BulkEditorInputType getByType(Class clazz) {
66 if (Reference.class.isAssignableFrom(clazz)) {
67 return REFERENCE;
68 } else if (TaxonNameBase.class.isAssignableFrom(clazz)) {
69 return NAME;
70 } else if (AgentBase.class.isAssignableFrom(clazz)) {
71 return AGENT;
72 } else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)) {
73 return OCCURRENCE;
74 } else if (NameRelationship.class.isAssignableFrom(clazz)) {
75 return NAME_RELATIONSHIP;
76 } else if (Group.class.isAssignableFrom(clazz)) {
77 return GROUP;
78 } else if (User.class.isAssignableFrom(clazz)) {
79 return USER;
80 }
81 return null;
82 }
83
84 public static BulkEditorInputType getByInput(IEditorInput input) {
85 if (input instanceof ReferenceEditorInput) {
86 return REFERENCE;
87 } else if (input instanceof NameEditorInput) {
88 return NAME;
89 } else if (input instanceof AgentEditorInput) {
90 return AGENT;
91 } else if (input instanceof OccurrenceEditorInput) {
92 return OCCURRENCE;
93 } else if (input instanceof NameRelationshipEditorInput) {
94 return NAME_RELATIONSHIP;
95 } else if (input instanceof UserEditorInput) {
96 return USER;
97 } else if (input instanceof GroupEditorInput) {
98 return GROUP;
99 }
100 return null;
101 }
102
103 public static AbstractBulkEditorInput getInput(
104 BulkEditorInputType inputType) {
105 switch (inputType) {
106 case REFERENCE:
107 return new ReferenceEditorInput();
108 case NAME:
109 return new NameEditorInput();
110 case AGENT:
111 return new AgentEditorInput();
112 case OCCURRENCE:
113 return new OccurrenceEditorInput();
114 case NAME_RELATIONSHIP:
115 return new NameRelationshipEditorInput();
116 case USER:
117 return new UserEditorInput();
118 case GROUP:
119 return new GroupEditorInput();
120 default:
121 throw new IllegalStateException(
122 "No input class for the given input type defined.");
123 }
124 }
125 }
126
127 /*
128 * (non-Javadoc)
129 *
130 * @see org.eclipse.core.commands.IParameterValues#getParameterValues()
131 */
132 /**
133 * <p>
134 * getParameterValues
135 * </p>
136 *
137 * @return a {@link java.util.Map} object.
138 */
139 @Override
140 public Map getParameterValues() {
141 final Map values = new HashMap();
142
143 // TODO user role determines which editor inputs are returned
144 for (BulkEditorInputType inputType : BulkEditorInputType.values()) {
145 values.put(inputType.label, inputType.id);
146 }
147
148 return values;
149 }
150 }