1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.providers; |
5 | |
6 | import java.util.HashSet; |
7 | import java.util.IdentityHashMap; |
8 | import java.util.Map; |
9 | import java.util.Set; |
10 | |
11 | import org.eclipse.core.runtime.IAdaptable; |
12 | import org.eclipse.emf.ecore.EClass; |
13 | import org.eclipse.emf.ecore.EClassifier; |
14 | import org.eclipse.emf.ecore.ENamedElement; |
15 | import org.eclipse.emf.ecore.EStructuralFeature; |
16 | import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; |
17 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
18 | import org.eclipse.jface.resource.ImageDescriptor; |
19 | import org.eclipse.jface.resource.ImageRegistry; |
20 | import org.eclipse.swt.graphics.Image; |
21 | |
22 | import de.uka.ipd.sdq.pcm.core.composition.CompositionPackage; |
23 | import de.uka.ipd.sdq.pcm.core.entity.EntityPackage; |
24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyConnectorEditPart; |
25 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyContextEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyEventConnectorEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyInfrastructureConnectorEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ComposedProvidingRequiringEntity2EditPart; |
29 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ComposedProvidingRequiringEntityEditPart; |
30 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.InfrastructureProvidedRoleEditPart; |
31 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.InfrastructureRequiredRoleEditPart; |
32 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationProvidedRole2EditPart; |
33 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationProvidedRoleEditPart; |
34 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationRequiredRole2EditPart; |
35 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationRequiredRoleEditPart; |
36 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ProvidedDelegationConnectorEditPart; |
37 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.RequiredDelegationConnectorEditPart; |
38 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.SinkRoleEditPart; |
39 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.SourceRoleEditPart; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelComposedStructureDiagramEditorPlugin; |
41 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
42 | |
43 | /** |
44 | * @generated |
45 | */ |
46 | public class PalladioComponentModelElementTypes extends ElementInitializers { |
47 | |
48 | /** |
49 | * @generated |
50 | */ |
51 | private PalladioComponentModelElementTypes() { |
52 | } |
53 | |
54 | /** |
55 | * @generated |
56 | */ |
57 | private static Map elements; |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | private static ImageRegistry imageRegistry; |
63 | |
64 | /** |
65 | * @generated |
66 | */ |
67 | private static Set KNOWN_ELEMENT_TYPES; |
68 | |
69 | /** |
70 | * @generated |
71 | */ |
72 | public static final IElementType ComposedProvidingRequiringEntity_1000 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.ComposedProvidingRequiringEntity_1000"); //$NON-NLS-1$ |
73 | /** |
74 | * @generated |
75 | */ |
76 | public static final IElementType ComposedProvidingRequiringEntity_2002 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.ComposedProvidingRequiringEntity_2002"); //$NON-NLS-1$ |
77 | |
78 | /** |
79 | * @generated |
80 | */ |
81 | public static final IElementType AssemblyContext_3006 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.AssemblyContext_3006"); //$NON-NLS-1$ |
82 | |
83 | /** |
84 | * @generated |
85 | */ |
86 | public static final IElementType OperationProvidedRole_3007 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.OperationProvidedRole_3007"); //$NON-NLS-1$ |
87 | |
88 | /** |
89 | * @generated |
90 | */ |
91 | public static final IElementType OperationRequiredRole_3008 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.OperationRequiredRole_3008"); //$NON-NLS-1$ |
92 | |
93 | /** |
94 | * @generated |
95 | */ |
96 | public static final IElementType SourceRole_3013 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.SourceRole_3013"); //$NON-NLS-1$ |
97 | |
98 | /** |
99 | * @generated |
100 | */ |
101 | public static final IElementType SinkRole_3014 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.SinkRole_3014"); //$NON-NLS-1$ |
102 | |
103 | /** |
104 | * @generated |
105 | */ |
106 | public static final IElementType InfrastructureProvidedRole_3015 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.InfrastructureProvidedRole_3015"); //$NON-NLS-1$ |
107 | |
108 | /** |
109 | * @generated |
110 | */ |
111 | public static final IElementType InfrastructureRequiredRole_3016 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.InfrastructureRequiredRole_3016"); //$NON-NLS-1$ |
112 | |
113 | /** |
114 | * @generated |
115 | */ |
116 | public static final IElementType OperationProvidedRole_3011 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.OperationProvidedRole_3011"); //$NON-NLS-1$ |
117 | |
118 | /** |
119 | * @generated |
120 | */ |
121 | public static final IElementType OperationRequiredRole_3012 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.OperationRequiredRole_3012"); //$NON-NLS-1$ |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | public static final IElementType AssemblyConnector_4004 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.AssemblyConnector_4004"); //$NON-NLS-1$ |
127 | |
128 | /** |
129 | * @generated |
130 | */ |
131 | public static final IElementType AssemblyEventConnector_4007 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.AssemblyEventConnector_4007"); //$NON-NLS-1$ |
132 | |
133 | /** |
134 | * @generated |
135 | */ |
136 | public static final IElementType RequiredDelegationConnector_4005 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.RequiredDelegationConnector_4005"); //$NON-NLS-1$ |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | public static final IElementType ProvidedDelegationConnector_4006 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.ProvidedDelegationConnector_4006"); //$NON-NLS-1$ |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | public static final IElementType AssemblyInfrastructureConnector_4008 = getElementType("de.uka.ipd.sdq.pcm.gmf.composite.AssemblyInfrastructureConnector_4008"); //$NON-NLS-1$ |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | private static ImageRegistry getImageRegistry() { |
152 | if (imageRegistry == null) { |
153 | imageRegistry = new ImageRegistry(); |
154 | } |
155 | return imageRegistry; |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | private static String getImageRegistryKey(ENamedElement element) { |
162 | return element.getName(); |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | private static ImageDescriptor getProvidedImageDescriptor( |
169 | ENamedElement element) { |
170 | if (element instanceof EStructuralFeature) { |
171 | EStructuralFeature feature = ((EStructuralFeature) element); |
172 | EClass eContainingClass = feature.getEContainingClass(); |
173 | EClassifier eType = feature.getEType(); |
174 | if (eContainingClass != null && !eContainingClass.isAbstract()) { |
175 | element = eContainingClass; |
176 | } else if (eType instanceof EClass |
177 | && !((EClass) eType).isAbstract()) { |
178 | element = eType; |
179 | } |
180 | } |
181 | if (element instanceof EClass) { |
182 | EClass eClass = (EClass) element; |
183 | if (!eClass.isAbstract()) { |
184 | return PalladioComponentModelComposedStructureDiagramEditorPlugin |
185 | .getInstance().getItemImageDescriptor( |
186 | eClass.getEPackage().getEFactoryInstance() |
187 | .create(eClass)); |
188 | } |
189 | } |
190 | // TODO : support structural features |
191 | return null; |
192 | } |
193 | |
194 | /** |
195 | * @generated |
196 | */ |
197 | public static ImageDescriptor getImageDescriptor(ENamedElement element) { |
198 | String key = getImageRegistryKey(element); |
199 | ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key); |
200 | if (imageDescriptor == null) { |
201 | imageDescriptor = getProvidedImageDescriptor(element); |
202 | if (imageDescriptor == null) { |
203 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
204 | } |
205 | getImageRegistry().put(key, imageDescriptor); |
206 | } |
207 | return imageDescriptor; |
208 | } |
209 | |
210 | /** |
211 | * @generated |
212 | */ |
213 | public static Image getImage(ENamedElement element) { |
214 | String key = getImageRegistryKey(element); |
215 | Image image = getImageRegistry().get(key); |
216 | if (image == null) { |
217 | ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element); |
218 | if (imageDescriptor == null) { |
219 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
220 | } |
221 | getImageRegistry().put(key, imageDescriptor); |
222 | image = getImageRegistry().get(key); |
223 | } |
224 | return image; |
225 | } |
226 | |
227 | /** |
228 | * @generated |
229 | */ |
230 | public static ImageDescriptor getImageDescriptor(IAdaptable hint) { |
231 | ENamedElement element = getElement(hint); |
232 | if (element == null) { |
233 | return null; |
234 | } |
235 | return getImageDescriptor(element); |
236 | } |
237 | |
238 | /** |
239 | * @generated |
240 | */ |
241 | public static Image getImage(IAdaptable hint) { |
242 | ENamedElement element = getElement(hint); |
243 | if (element == null) { |
244 | return null; |
245 | } |
246 | return getImage(element); |
247 | } |
248 | |
249 | /** |
250 | * Returns 'type' of the ecore object associated with the hint. |
251 | * |
252 | * @generated |
253 | */ |
254 | public static ENamedElement getElement(IAdaptable hint) { |
255 | Object type = hint.getAdapter(IElementType.class); |
256 | if (elements == null) { |
257 | elements = new IdentityHashMap(); |
258 | |
259 | elements.put(ComposedProvidingRequiringEntity_1000, |
260 | EntityPackage.eINSTANCE |
261 | .getComposedProvidingRequiringEntity()); |
262 | |
263 | elements.put(ComposedProvidingRequiringEntity_2002, |
264 | EntityPackage.eINSTANCE |
265 | .getComposedProvidingRequiringEntity()); |
266 | |
267 | elements.put(AssemblyContext_3006, CompositionPackage.eINSTANCE |
268 | .getAssemblyContext()); |
269 | |
270 | elements.put(OperationProvidedRole_3007, |
271 | RepositoryPackage.eINSTANCE.getOperationProvidedRole()); |
272 | |
273 | elements.put(OperationRequiredRole_3008, |
274 | RepositoryPackage.eINSTANCE.getOperationRequiredRole()); |
275 | |
276 | elements.put(SourceRole_3013, RepositoryPackage.eINSTANCE |
277 | .getSourceRole()); |
278 | |
279 | elements.put(SinkRole_3014, RepositoryPackage.eINSTANCE |
280 | .getSinkRole()); |
281 | |
282 | elements |
283 | .put(InfrastructureProvidedRole_3015, |
284 | RepositoryPackage.eINSTANCE |
285 | .getInfrastructureProvidedRole()); |
286 | |
287 | elements |
288 | .put(InfrastructureRequiredRole_3016, |
289 | RepositoryPackage.eINSTANCE |
290 | .getInfrastructureRequiredRole()); |
291 | |
292 | elements.put(OperationProvidedRole_3011, |
293 | RepositoryPackage.eINSTANCE.getOperationProvidedRole()); |
294 | |
295 | elements.put(OperationRequiredRole_3012, |
296 | RepositoryPackage.eINSTANCE.getOperationRequiredRole()); |
297 | |
298 | elements.put(AssemblyConnector_4004, CompositionPackage.eINSTANCE |
299 | .getAssemblyConnector()); |
300 | |
301 | elements.put(AssemblyEventConnector_4007, |
302 | CompositionPackage.eINSTANCE.getAssemblyEventConnector()); |
303 | |
304 | elements.put(RequiredDelegationConnector_4005, |
305 | CompositionPackage.eINSTANCE |
306 | .getRequiredDelegationConnector()); |
307 | |
308 | elements.put(ProvidedDelegationConnector_4006, |
309 | CompositionPackage.eINSTANCE |
310 | .getProvidedDelegationConnector()); |
311 | |
312 | elements.put(AssemblyInfrastructureConnector_4008, |
313 | CompositionPackage.eINSTANCE |
314 | .getAssemblyInfrastructureConnector()); |
315 | } |
316 | return (ENamedElement) elements.get(type); |
317 | } |
318 | |
319 | /** |
320 | * @generated |
321 | */ |
322 | private static IElementType getElementType(String id) { |
323 | return ElementTypeRegistry.getInstance().getType(id); |
324 | } |
325 | |
326 | /** |
327 | * @generated |
328 | */ |
329 | public static boolean isKnownElementType(IElementType elementType) { |
330 | if (KNOWN_ELEMENT_TYPES == null) { |
331 | KNOWN_ELEMENT_TYPES = new HashSet(); |
332 | KNOWN_ELEMENT_TYPES.add(ComposedProvidingRequiringEntity_1000); |
333 | KNOWN_ELEMENT_TYPES.add(ComposedProvidingRequiringEntity_2002); |
334 | KNOWN_ELEMENT_TYPES.add(AssemblyContext_3006); |
335 | KNOWN_ELEMENT_TYPES.add(OperationProvidedRole_3007); |
336 | KNOWN_ELEMENT_TYPES.add(OperationRequiredRole_3008); |
337 | KNOWN_ELEMENT_TYPES.add(SourceRole_3013); |
338 | KNOWN_ELEMENT_TYPES.add(SinkRole_3014); |
339 | KNOWN_ELEMENT_TYPES.add(InfrastructureProvidedRole_3015); |
340 | KNOWN_ELEMENT_TYPES.add(InfrastructureRequiredRole_3016); |
341 | KNOWN_ELEMENT_TYPES.add(OperationProvidedRole_3011); |
342 | KNOWN_ELEMENT_TYPES.add(OperationRequiredRole_3012); |
343 | KNOWN_ELEMENT_TYPES.add(AssemblyConnector_4004); |
344 | KNOWN_ELEMENT_TYPES.add(AssemblyEventConnector_4007); |
345 | KNOWN_ELEMENT_TYPES.add(RequiredDelegationConnector_4005); |
346 | KNOWN_ELEMENT_TYPES.add(ProvidedDelegationConnector_4006); |
347 | KNOWN_ELEMENT_TYPES.add(AssemblyInfrastructureConnector_4008); |
348 | } |
349 | return KNOWN_ELEMENT_TYPES.contains(elementType); |
350 | } |
351 | |
352 | /** |
353 | * @generated |
354 | */ |
355 | public static IElementType getElementType(int visualID) { |
356 | switch (visualID) { |
357 | case ComposedProvidingRequiringEntityEditPart.VISUAL_ID: |
358 | return ComposedProvidingRequiringEntity_1000; |
359 | case ComposedProvidingRequiringEntity2EditPart.VISUAL_ID: |
360 | return ComposedProvidingRequiringEntity_2002; |
361 | case AssemblyContextEditPart.VISUAL_ID: |
362 | return AssemblyContext_3006; |
363 | case OperationProvidedRoleEditPart.VISUAL_ID: |
364 | return OperationProvidedRole_3007; |
365 | case OperationRequiredRoleEditPart.VISUAL_ID: |
366 | return OperationRequiredRole_3008; |
367 | case SourceRoleEditPart.VISUAL_ID: |
368 | return SourceRole_3013; |
369 | case SinkRoleEditPart.VISUAL_ID: |
370 | return SinkRole_3014; |
371 | case InfrastructureProvidedRoleEditPart.VISUAL_ID: |
372 | return InfrastructureProvidedRole_3015; |
373 | case InfrastructureRequiredRoleEditPart.VISUAL_ID: |
374 | return InfrastructureRequiredRole_3016; |
375 | case OperationProvidedRole2EditPart.VISUAL_ID: |
376 | return OperationProvidedRole_3011; |
377 | case OperationRequiredRole2EditPart.VISUAL_ID: |
378 | return OperationRequiredRole_3012; |
379 | case AssemblyConnectorEditPart.VISUAL_ID: |
380 | return AssemblyConnector_4004; |
381 | case AssemblyEventConnectorEditPart.VISUAL_ID: |
382 | return AssemblyEventConnector_4007; |
383 | case RequiredDelegationConnectorEditPart.VISUAL_ID: |
384 | return RequiredDelegationConnector_4005; |
385 | case ProvidedDelegationConnectorEditPart.VISUAL_ID: |
386 | return ProvidedDelegationConnector_4006; |
387 | case AssemblyInfrastructureConnectorEditPart.VISUAL_ID: |
388 | return AssemblyInfrastructureConnector_4008; |
389 | } |
390 | return null; |
391 | } |
392 | |
393 | } |