1
|
package eu.etaxonomy.taxeditor.bulkeditor.input;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import org.eclipse.jface.action.IContributionItem;
|
7
|
import org.eclipse.swt.SWT;
|
8
|
import org.eclipse.ui.IEditorInput;
|
9
|
import org.eclipse.ui.PlatformUI;
|
10
|
import org.eclipse.ui.menus.CommandContributionItem;
|
11
|
import org.eclipse.ui.menus.CommandContributionItemParameter;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
14
|
import eu.etaxonomy.cdm.model.common.Group;
|
15
|
import eu.etaxonomy.cdm.model.common.User;
|
16
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
17
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
18
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
19
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
20
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
|
21
|
|
22
|
public enum BulkEditorInputType {
|
23
|
AGENT("Authors and Author Teams", AgentEditorInput.ID),
|
24
|
REFERENCE("Reference", ReferenceEditorInput.ID),
|
25
|
NAME("Name", NameEditorInput.ID),
|
26
|
NAME_RELATIONSHIP("Name Relationship", NameRelationshipEditorInput.ID),
|
27
|
OCCURRENCE("Specimens and Observations", OccurrenceEditorInput.ID),
|
28
|
USER("User", UserEditorInput.ID),
|
29
|
GROUP("Group", GroupEditorInput.ID);
|
30
|
|
31
|
public String id;
|
32
|
public String label;
|
33
|
|
34
|
BulkEditorInputType(String label, String id) {
|
35
|
this.id = id;
|
36
|
this.label = label;
|
37
|
}
|
38
|
|
39
|
public IContributionItem createContributionItem(){
|
40
|
return createContributionItem(label, id);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* @param key
|
45
|
* @param object
|
46
|
* @return
|
47
|
*/
|
48
|
private IContributionItem createContributionItem(String label,
|
49
|
String inputType) {
|
50
|
CommandContributionItemParameter parameter = new CommandContributionItemParameter(
|
51
|
PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null,
|
52
|
IBulkEditorConstants.DYNAMIC_OPEN_MENU_ID, SWT.NONE);
|
53
|
|
54
|
parameter.label = label;
|
55
|
|
56
|
Map parameters = new HashMap();
|
57
|
parameters.put(IBulkEditorConstants.INPUT_TYPE_PARAMETER_ID, inputType);
|
58
|
parameter.parameters = parameters;
|
59
|
|
60
|
return new CommandContributionItem(parameter);
|
61
|
}
|
62
|
|
63
|
public static BulkEditorInputType getById(String id) {
|
64
|
|
65
|
for (BulkEditorInputType type : values()) {
|
66
|
if (id.equals(type.id)) {
|
67
|
return type;
|
68
|
}
|
69
|
}
|
70
|
|
71
|
return null;
|
72
|
}
|
73
|
|
74
|
public static BulkEditorInputType getByType(Class clazz) {
|
75
|
if (Reference.class.isAssignableFrom(clazz)) {
|
76
|
return REFERENCE;
|
77
|
} else if (TaxonNameBase.class.isAssignableFrom(clazz)) {
|
78
|
return NAME;
|
79
|
} else if (AgentBase.class.isAssignableFrom(clazz)) {
|
80
|
return AGENT;
|
81
|
} else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)) {
|
82
|
return OCCURRENCE;
|
83
|
} else if (NameRelationship.class.isAssignableFrom(clazz)) {
|
84
|
return NAME_RELATIONSHIP;
|
85
|
} else if (Group.class.isAssignableFrom(clazz)) {
|
86
|
return GROUP;
|
87
|
} else if (User.class.isAssignableFrom(clazz)) {
|
88
|
return USER;
|
89
|
}
|
90
|
return null;
|
91
|
}
|
92
|
|
93
|
public static BulkEditorInputType getByInput(IEditorInput input) {
|
94
|
if (input instanceof ReferenceEditorInput) {
|
95
|
return REFERENCE;
|
96
|
} else if (input instanceof NameEditorInput) {
|
97
|
return NAME;
|
98
|
} else if (input instanceof AgentEditorInput) {
|
99
|
return AGENT;
|
100
|
} else if (input instanceof OccurrenceEditorInput) {
|
101
|
return OCCURRENCE;
|
102
|
} else if (input instanceof NameRelationshipEditorInput) {
|
103
|
return NAME_RELATIONSHIP;
|
104
|
} else if (input instanceof UserEditorInput) {
|
105
|
return USER;
|
106
|
} else if (input instanceof GroupEditorInput) {
|
107
|
return GROUP;
|
108
|
}
|
109
|
return null;
|
110
|
}
|
111
|
|
112
|
public static AbstractBulkEditorInput getInput(
|
113
|
BulkEditorInputType inputType) {
|
114
|
switch (inputType) {
|
115
|
case REFERENCE:
|
116
|
return new ReferenceEditorInput();
|
117
|
case NAME:
|
118
|
return new NameEditorInput();
|
119
|
case AGENT:
|
120
|
return new AgentEditorInput();
|
121
|
case OCCURRENCE:
|
122
|
return new OccurrenceEditorInput();
|
123
|
case NAME_RELATIONSHIP:
|
124
|
return new NameRelationshipEditorInput();
|
125
|
case USER:
|
126
|
return new UserEditorInput();
|
127
|
case GROUP:
|
128
|
return new GroupEditorInput();
|
129
|
default:
|
130
|
throw new IllegalStateException(
|
131
|
"No input class for the given input type defined.");
|
132
|
}
|
133
|
}
|
134
|
}
|