Project

General

Profile

Download (4.53 KB) Statistics
| Branch: | Tag: | Revision:
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>BulkEditorInputTypeValues class.</p>
37
 *
38
 * @author p.ciardelli
39
 * @created 20.08.2009
40
 * @version 1.0
41
 */
42
public class BulkEditorInputTypeValues implements IParameterValues {
43

    
44
	public enum BulkEditorInputType{
45
		REFERENCE("Reference", ReferenceEditorInput.ID),
46
		NAME("Name", NameEditorInput.ID),
47
		AGENT("Authors and Author Teams", AgentEditorInput.ID),
48
		OCCURRENCE("Specimens or Observations", OccurrenceEditorInput.ID), 
49
		NAME_RELATIONSHIP("Name Relationship", NameRelationshipEditorInput.ID),
50
		USER("User", UserEditorInput.ID), 
51
		GROUP("Group", GroupEditorInput.ID);
52
		
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
			}
77
			else if (TaxonNameBase.class.isAssignableFrom(clazz)) {
78
				return NAME;
79
			}
80
			else if (AgentBase.class.isAssignableFrom(clazz)) {
81
				return AGENT;
82
			}
83
			else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
84
				return OCCURRENCE;
85
			}
86
			else if (NameRelationship.class.isAssignableFrom(clazz)){
87
				return NAME_RELATIONSHIP;
88
			}
89
			else if (Group.class.isAssignableFrom(clazz)){
90
				return GROUP;
91
			}
92
			else if (User.class.isAssignableFrom(clazz)){
93
				return USER;
94
			}
95
			return null;
96
		}
97
		
98
		public static BulkEditorInputType getByInput(IEditorInput input) {
99
			if (input instanceof ReferenceEditorInput) {
100
				return REFERENCE;
101
			}
102
			else if (input instanceof NameEditorInput) {
103
				return NAME;
104
			}
105
			else if (input instanceof AgentEditorInput) {
106
				return AGENT;
107
			}
108
			else if (input instanceof OccurrenceEditorInput) {
109
				return OCCURRENCE;
110
			}
111
			else if (input instanceof NameRelationshipEditorInput) {
112
				return NAME_RELATIONSHIP;
113
			}
114
			else if(input instanceof UserEditorInput){
115
				return USER;
116
			}
117
			else if(input instanceof GroupEditorInput){
118
				return GROUP;
119
			}
120
			return null;
121
		}
122
		
123
		public static AbstractBulkEditorInput getInput(BulkEditorInputType inputType){
124
			switch (inputType) {
125
			case REFERENCE:
126
				return new ReferenceEditorInput();
127
			case NAME:
128
				return new NameEditorInput();
129
			case AGENT:
130
				return new AgentEditorInput();
131
			case OCCURRENCE:
132
				return new OccurrenceEditorInput();
133
			case NAME_RELATIONSHIP:
134
				return new NameRelationshipEditorInput();
135
			case USER:
136
				return new UserEditorInput();
137
			case GROUP:
138
				return new GroupEditorInput();
139
			default:
140
				throw new IllegalStateException("No input class for the given input type defined.");
141
			}
142
		}
143
	}
144
	
145
	/* (non-Javadoc)
146
	 * @see org.eclipse.core.commands.IParameterValues#getParameterValues()
147
	 */
148
	/**
149
	 * <p>getParameterValues</p>
150
	 *
151
	 * @return a {@link java.util.Map} object.
152
	 */
153
	public Map getParameterValues() {
154
		final Map values = new HashMap();
155
		
156
		// TODO user role determines which editor inputs are returned
157
		for (BulkEditorInputType inputType : BulkEditorInputType.values()){
158
			values.put(inputType.label, inputType.id);
159
		}		
160
		
161
		return values;
162
	}
163
}
(1-1/6)