ref #6190 removing svn property place holder in first line of code - java files
[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 import java.util.ResourceBundle;
6
7 import org.eclipse.jface.action.IContributionItem;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.ui.IEditorInput;
10 import org.eclipse.ui.PlatformUI;
11 import org.eclipse.ui.menus.CommandContributionItem;
12 import org.eclipse.ui.menus.CommandContributionItemParameter;
13
14 import eu.etaxonomy.cdm.api.service.IAgentService;
15 import eu.etaxonomy.cdm.api.service.IGroupService;
16 import eu.etaxonomy.cdm.api.service.IMediaService;
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.media.Media;
26 import eu.etaxonomy.cdm.model.name.NameRelationship;
27 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
28 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
29 import eu.etaxonomy.cdm.model.reference.Reference;
30 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
31 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
32
33 public enum BulkEditorInputType {
34 AGENT(Messages.BulkEditorInputType_0, AgentEditorInput.ID),
35 REFERENCE(Messages.BulkEditorInputType_1, ReferenceEditorInput.ID),
36 NAME(Messages.BulkEditorInputType_2, NameEditorInput.ID),
37 NAME_RELATIONSHIP(Messages.BulkEditorInputType_3, NameRelationshipEditorInput.ID),
38 OCCURRENCE(Messages.BulkEditorInputType_4, OccurrenceEditorInput.ID),
39 USER(Messages.BulkEditorInputType_5, UserEditorInput.ID),
40 GROUP(Messages.BulkEditorInputType_6, GroupEditorInput.ID),
41 TAXON(Messages.BulkEditorInputType_7, TaxonEditorInput.ID),
42 MEDIA(Messages.BulkEditorInputType_8, MediaEditorInput.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 (TaxonBase.class.isAssignableFrom(clazz)){
104 return TAXON;
105 } else if (Media.class.isAssignableFrom(clazz)){
106 return MEDIA;
107 }
108 return null;
109 }
110
111 public static BulkEditorInputType getByInput(IEditorInput input) {
112 if (input instanceof ReferenceEditorInput) {
113 return REFERENCE;
114 } else if (input instanceof NameEditorInput) {
115 return NAME;
116 } else if (input instanceof AgentEditorInput) {
117 return AGENT;
118 } else if (input instanceof OccurrenceEditorInput) {
119 return OCCURRENCE;
120 } else if (input instanceof NameRelationshipEditorInput) {
121 return NAME_RELATIONSHIP;
122 } else if (input instanceof UserEditorInput) {
123 return USER;
124 } else if (input instanceof GroupEditorInput) {
125 return GROUP;
126 } else if (input instanceof TaxonEditorInput){
127 return TAXON;
128 }else if (input instanceof MediaEditorInput){
129 return MEDIA;
130 }
131 return null;
132 }
133
134 public static AbstractBulkEditorInput getInput(
135 BulkEditorInputType inputType) {
136 switch (inputType) {
137 case REFERENCE:
138 return new ReferenceEditorInput();
139 case NAME:
140 return new NameEditorInput();
141 case AGENT:
142 return new AgentEditorInput();
143 case OCCURRENCE:
144 return new OccurrenceEditorInput();
145 case NAME_RELATIONSHIP:
146 return new NameRelationshipEditorInput();
147 case USER:
148 return new UserEditorInput();
149 case GROUP:
150 return new GroupEditorInput();
151 case TAXON:
152 return new TaxonEditorInput();
153 case MEDIA:
154 return new MediaEditorInput();
155 default:
156 throw new IllegalStateException(
157 "No input class for the given input type defined."); //$NON-NLS-1$
158 }
159 }
160
161 public static Class getServiceClass(
162 BulkEditorInputType inputType) {
163 switch (inputType) {
164 case REFERENCE:
165 return IReferenceService.class;
166 case NAME:
167 return INameService.class;
168 case AGENT:
169 return IAgentService.class;
170 case OCCURRENCE:
171 return IOccurrenceService.class;
172 case NAME_RELATIONSHIP:
173 return INameService.class;
174 case USER:
175 return IUserService.class;
176 case GROUP:
177 return IGroupService.class;
178 case TAXON:
179 return ITaxonService.class;
180 case MEDIA:
181 return IMediaService.class;
182 default:
183 throw new IllegalStateException(
184 "No input class for the given input type defined."); //$NON-NLS-1$
185 }
186 }
187 }