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