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