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