1
|
package eu.etaxonomy.taxeditor.bulkeditor.input;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Locale;
|
5
|
import java.util.Map;
|
6
|
import java.util.ResourceBundle;
|
7
|
|
8
|
import org.eclipse.jface.action.IContributionItem;
|
9
|
import org.eclipse.swt.SWT;
|
10
|
import org.eclipse.ui.IEditorInput;
|
11
|
import org.eclipse.ui.PlatformUI;
|
12
|
import org.eclipse.ui.menus.CommandContributionItem;
|
13
|
import org.eclipse.ui.menus.CommandContributionItemParameter;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
16
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
17
|
import eu.etaxonomy.cdm.api.service.INameService;
|
18
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
19
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
20
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
21
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
22
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
23
|
import eu.etaxonomy.cdm.model.common.Group;
|
24
|
import eu.etaxonomy.cdm.model.common.User;
|
25
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
27
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
|
31
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
32
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
33
|
|
34
|
public enum BulkEditorInputType {
|
35
|
AGENT(Messages.BulkEditorInputType_0, AgentEditorInput.ID),
|
36
|
REFERENCE(Messages.BulkEditorInputType_1, ReferenceEditorInput.ID),
|
37
|
NAME(Messages.BulkEditorInputType_2, NameEditorInput.ID),
|
38
|
NAME_RELATIONSHIP(Messages.BulkEditorInputType_3, NameRelationshipEditorInput.ID),
|
39
|
OCCURRENCE(Messages.BulkEditorInputType_4, OccurrenceEditorInput.ID),
|
40
|
USER(Messages.BulkEditorInputType_5, UserEditorInput.ID),
|
41
|
GROUP(Messages.BulkEditorInputType_6, GroupEditorInput.ID),
|
42
|
TAXON(Messages.BulkEditorInputType_7, TaxonEditorInput.ID);
|
43
|
|
44
|
public String id;
|
45
|
public String label;
|
46
|
public ResourceBundle resourceBundle;
|
47
|
|
48
|
BulkEditorInputType(String label, String id) {
|
49
|
this.id = id;
|
50
|
this.label = label;
|
51
|
}
|
52
|
|
53
|
public IContributionItem createContributionItem(){
|
54
|
return createContributionItem(label, id);
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* @param key
|
59
|
* @param object
|
60
|
* @return
|
61
|
*/
|
62
|
private IContributionItem createContributionItem(String label,
|
63
|
String inputType) {
|
64
|
CommandContributionItemParameter parameter = new CommandContributionItemParameter(
|
65
|
PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null,
|
66
|
IBulkEditorConstants.DYNAMIC_OPEN_MENU_ID, SWT.NONE);
|
67
|
|
68
|
parameter.label = label;
|
69
|
|
70
|
Map parameters = new HashMap();
|
71
|
parameters.put(IBulkEditorConstants.INPUT_TYPE_PARAMETER_ID, inputType);
|
72
|
parameter.parameters = parameters;
|
73
|
|
74
|
return new CommandContributionItem(parameter);
|
75
|
}
|
76
|
|
77
|
public static BulkEditorInputType getById(String id) {
|
78
|
|
79
|
for (BulkEditorInputType type : values()) {
|
80
|
if (id.equals(type.id)) {
|
81
|
return type;
|
82
|
}
|
83
|
}
|
84
|
|
85
|
return null;
|
86
|
}
|
87
|
|
88
|
public static BulkEditorInputType getByType(Class clazz) {
|
89
|
if (Reference.class.isAssignableFrom(clazz)) {
|
90
|
return REFERENCE;
|
91
|
} else if (TaxonNameBase.class.isAssignableFrom(clazz)) {
|
92
|
return NAME;
|
93
|
} else if (AgentBase.class.isAssignableFrom(clazz)) {
|
94
|
return AGENT;
|
95
|
} else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)) {
|
96
|
return OCCURRENCE;
|
97
|
} else if (NameRelationship.class.isAssignableFrom(clazz)) {
|
98
|
return NAME_RELATIONSHIP;
|
99
|
} else if (Group.class.isAssignableFrom(clazz)) {
|
100
|
return GROUP;
|
101
|
} else if (User.class.isAssignableFrom(clazz)) {
|
102
|
return USER;
|
103
|
} else if (Taxon.class.isAssignableFrom(clazz)){
|
104
|
return TAXON;
|
105
|
}
|
106
|
return null;
|
107
|
}
|
108
|
|
109
|
public static BulkEditorInputType getByInput(IEditorInput input) {
|
110
|
if (input instanceof ReferenceEditorInput) {
|
111
|
return REFERENCE;
|
112
|
} else if (input instanceof NameEditorInput) {
|
113
|
return NAME;
|
114
|
} else if (input instanceof AgentEditorInput) {
|
115
|
return AGENT;
|
116
|
} else if (input instanceof OccurrenceEditorInput) {
|
117
|
return OCCURRENCE;
|
118
|
} else if (input instanceof NameRelationshipEditorInput) {
|
119
|
return NAME_RELATIONSHIP;
|
120
|
} else if (input instanceof UserEditorInput) {
|
121
|
return USER;
|
122
|
} else if (input instanceof GroupEditorInput) {
|
123
|
return GROUP;
|
124
|
} else if (input instanceof TaxonEditorInput){
|
125
|
return TAXON;
|
126
|
}
|
127
|
return null;
|
128
|
}
|
129
|
|
130
|
public static AbstractBulkEditorInput getInput(
|
131
|
BulkEditorInputType inputType) {
|
132
|
switch (inputType) {
|
133
|
case REFERENCE:
|
134
|
return new ReferenceEditorInput();
|
135
|
case NAME:
|
136
|
return new NameEditorInput();
|
137
|
case AGENT:
|
138
|
return new AgentEditorInput();
|
139
|
case OCCURRENCE:
|
140
|
return new OccurrenceEditorInput();
|
141
|
case NAME_RELATIONSHIP:
|
142
|
return new NameRelationshipEditorInput();
|
143
|
case USER:
|
144
|
return new UserEditorInput();
|
145
|
case GROUP:
|
146
|
return new GroupEditorInput();
|
147
|
case TAXON:
|
148
|
return new TaxonEditorInput();
|
149
|
default:
|
150
|
throw new IllegalStateException(
|
151
|
"No input class for the given input type defined."); //$NON-NLS-1$
|
152
|
}
|
153
|
}
|
154
|
|
155
|
public static Class getServiceClass(
|
156
|
BulkEditorInputType inputType) {
|
157
|
switch (inputType) {
|
158
|
case REFERENCE:
|
159
|
return IReferenceService.class;
|
160
|
case NAME:
|
161
|
return INameService.class;
|
162
|
case AGENT:
|
163
|
return IAgentService.class;
|
164
|
case OCCURRENCE:
|
165
|
return IOccurrenceService.class;
|
166
|
case NAME_RELATIONSHIP:
|
167
|
return INameService.class;
|
168
|
case USER:
|
169
|
return IUserService.class;
|
170
|
case GROUP:
|
171
|
return IGroupService.class;
|
172
|
case TAXON:
|
173
|
return ITaxonService.class;
|
174
|
default:
|
175
|
throw new IllegalStateException(
|
176
|
"No input class for the given input type defined."); //$NON-NLS-1$
|
177
|
}
|
178
|
}
|
179
|
}
|