added a readme file
[taxeditor.git] / 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.name.NameRelationship;
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
23 import eu.etaxonomy.cdm.model.reference.Reference;
24 import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
25 import eu.etaxonomy.taxeditor.bulkeditor.input.AgentEditorInput;
26 import eu.etaxonomy.taxeditor.bulkeditor.input.NameEditorInput;
27 import eu.etaxonomy.taxeditor.bulkeditor.input.NameRelationshipEditorInput;
28 import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
29 import eu.etaxonomy.taxeditor.bulkeditor.input.ReferenceEditorInput;
30
31 /**
32 * <p>BulkEditorInputTypeValues class.</p>
33 *
34 * @author p.ciardelli
35 * @created 20.08.2009
36 * @version 1.0
37 */
38 public class BulkEditorInputTypeValues implements IParameterValues {
39
40 public enum BulkEditorInputType{
41 REFERENCE("Reference", ReferenceEditorInput.ID),
42 NAME("Name", NameEditorInput.ID),
43 AGENT("Authors and Author Teams", AgentEditorInput.ID),
44 OCCURRENCE("Specimen or Observations", OccurrenceEditorInput.ID),
45 NAME_RELATIONSHIP("Name Relationship", NameRelationshipEditorInput.ID);
46
47 public String id;
48 public String label;
49
50 BulkEditorInputType(String label, String id){
51 this.id = id;
52 this.label = label;
53 }
54
55 public static BulkEditorInputType getById(String id){
56
57 for(BulkEditorInputType type : values()){
58 if(id.equals(type.id)){
59 return type;
60 }
61 }
62
63 return null;
64 }
65
66 public static BulkEditorInputType getByType(Class clazz){
67 if (Reference.class.isAssignableFrom(clazz)) {
68 return REFERENCE;
69 }
70 else if (TaxonNameBase.class.isAssignableFrom(clazz)) {
71 return NAME;
72 }
73 else if (AgentBase.class.isAssignableFrom(clazz)) {
74 return AGENT;
75 }
76 else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
77 return OCCURRENCE;
78 }
79 else if (NameRelationship.class.isAssignableFrom(clazz)){
80 return NAME_RELATIONSHIP;
81 }
82 return null;
83 }
84
85 public static BulkEditorInputType getByInput(IEditorInput input) {
86 if (input instanceof ReferenceEditorInput) {
87 return REFERENCE;
88 }
89 else if (input instanceof NameEditorInput) {
90 return NAME;
91 }
92 else if (input instanceof AgentEditorInput) {
93 return AGENT;
94 }
95 else if (input instanceof OccurrenceEditorInput) {
96 return OCCURRENCE;
97 }
98 else if (input instanceof NameRelationshipEditorInput) {
99 return NAME_RELATIONSHIP;
100 }
101 return null;
102 }
103
104 public static AbstractBulkEditorInput getInput(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 default:
117 return null;
118 }
119 }
120 }
121
122 /* (non-Javadoc)
123 * @see org.eclipse.core.commands.IParameterValues#getParameterValues()
124 */
125 /**
126 * <p>getParameterValues</p>
127 *
128 * @return a {@link java.util.Map} object.
129 */
130 public Map getParameterValues() {
131 final Map values = new HashMap();
132
133 // TODO user role determines which editor inputs are returned
134 for (BulkEditorInputType inputType : BulkEditorInputType.values()){
135 values.put(inputType.label, inputType.id);
136 }
137
138 return values;
139 }
140 }