Project

General

Profile

Download (5.71 KB) Statistics
| Branch: | Tag: | Revision:
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.permission.Group;
24
import eu.etaxonomy.cdm.model.permission.User;
25
import eu.etaxonomy.cdm.model.media.Media;
26
import eu.etaxonomy.cdm.model.name.NameRelationship;
27
import eu.etaxonomy.cdm.model.name.TaxonName;
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
import eu.etaxonomy.taxeditor.l10n.Messages;
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
	MEDIA(Messages.BulkEditorInputType_8, MediaEditorInput.ID);
44

    
45
	public String id;
46
	public String label;
47
	public ResourceBundle resourceBundle;
48

    
49
	BulkEditorInputType(String label, String id) {
50
		this.id = id;
51
		this.label = label;
52
	}
53

    
54
	public IContributionItem createContributionItem(){
55
		return createContributionItem(label, id);
56
	}
57

    
58
	private IContributionItem createContributionItem(String label,
59
			String inputType) {
60
		CommandContributionItemParameter parameter = new CommandContributionItemParameter(
61
				PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null,
62
				IBulkEditorConstants.DYNAMIC_OPEN_MENU_ID, SWT.NONE);
63

    
64
		parameter.label = label;
65

    
66
		Map parameters = new HashMap();
67
		parameters.put(IBulkEditorConstants.INPUT_TYPE_PARAMETER_ID, inputType);
68
		parameter.parameters = parameters;
69

    
70
		return new CommandContributionItem(parameter);
71
	}
72

    
73
	public static BulkEditorInputType getById(String id) {
74

    
75
		for (BulkEditorInputType type : values()) {
76
			if (id.equals(type.id)) {
77
				return type;
78
			}
79
		}
80

    
81
		return null;
82
	}
83

    
84
	public static BulkEditorInputType getByType(Class clazz) {
85
		if (Reference.class.isAssignableFrom(clazz)) {
86
			return REFERENCE;
87
		} else if (TaxonName.class.isAssignableFrom(clazz)) {
88
			return NAME;
89
		} else if (AgentBase.class.isAssignableFrom(clazz)) {
90
			return AGENT;
91
		} else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)) {
92
			return OCCURRENCE;
93
		} else if (NameRelationship.class.isAssignableFrom(clazz)) {
94
			return NAME_RELATIONSHIP;
95
		} else if (Group.class.isAssignableFrom(clazz)) {
96
			return GROUP;
97
		} else if (User.class.isAssignableFrom(clazz)) {
98
			return USER;
99
		} else if (TaxonBase.class.isAssignableFrom(clazz)){
100
			return TAXON;
101
		} else if (Media.class.isAssignableFrom(clazz)){
102
            return MEDIA;
103
        }
104
		return null;
105
	}
106

    
107
	public static BulkEditorInputType getByInput(IEditorInput input) {
108
		if (input instanceof ReferenceEditorInput) {
109
			return REFERENCE;
110
		} else if (input instanceof NameEditorInput) {
111
			return NAME;
112
		} else if (input instanceof AgentEditorInput) {
113
			return AGENT;
114
		} else if (input instanceof OccurrenceEditorInput) {
115
			return OCCURRENCE;
116
		} else if (input instanceof NameRelationshipEditorInput) {
117
			return NAME_RELATIONSHIP;
118
		} else if (input instanceof UserEditorInput) {
119
			return USER;
120
		} else if (input instanceof GroupEditorInput) {
121
			return GROUP;
122
		} else if (input instanceof TaxonEditorInput){
123
			return TAXON;
124
		}else if (input instanceof MediaEditorInput){
125
            return MEDIA;
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
		case MEDIA:
150
            return new MediaEditorInput();
151
		default:
152
			throw new IllegalStateException(
153
					"No input class for the given input type defined."); //$NON-NLS-1$
154
		}
155
	}
156

    
157
	public static Class getServiceClass(
158
			BulkEditorInputType inputType) {
159
		switch (inputType) {
160
		case REFERENCE:
161
			return IReferenceService.class;
162
		case NAME:
163
			return INameService.class;
164
		case AGENT:
165
			return IAgentService.class;
166
		case OCCURRENCE:
167
			return IOccurrenceService.class;
168
		case NAME_RELATIONSHIP:
169
			return INameService.class;
170
		case USER:
171
			return IUserService.class;
172
		case GROUP:
173
			return IGroupService.class;
174
		case TAXON:
175
			return ITaxonService.class;
176
		case MEDIA:
177
            return IMediaService.class;
178
		default:
179
			throw new IllegalStateException(
180
					"No input class for the given input type defined."); //$NON-NLS-1$
181
		}
182
	}
183
}
(3-3/11)