1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.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.gmf.usage.edit.parts.AbstractUserActionSuccessorEditPart; |
23 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.BranchEditPart; |
24 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.BranchTransitionEditPart; |
25 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.ClosedWorkloadEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.DelayEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.EntryLevelSystemCallEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.LoopEditPart; |
29 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.OpenWorkloadEditPart; |
30 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.ScenarioBehaviour2EditPart; |
31 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.ScenarioBehaviour3EditPart; |
32 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.ScenarioBehaviourEditPart; |
33 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.StartEditPart; |
34 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.StopEditPart; |
35 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.UsageScenario2EditPart; |
36 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.UsageScenarioEditPart; |
37 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.VariableCharacterisationEditPart; |
38 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.VariableUsageEditPart; |
39 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelUsageDiagramEditorPlugin; |
40 | import de.uka.ipd.sdq.pcm.parameter.ParameterPackage; |
41 | import de.uka.ipd.sdq.pcm.usagemodel.UsagemodelPackage; |
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 UsageModel_1000 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.UsageModel_1000"); //$NON-NLS-1$ |
73 | |
74 | /** |
75 | * @generated |
76 | */ |
77 | public static final IElementType UsageScenario_2004 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.UsageScenario_2004"); //$NON-NLS-1$ |
78 | |
79 | /** |
80 | * @generated |
81 | */ |
82 | public static final IElementType ScenarioBehaviour_3014 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.ScenarioBehaviour_3014"); //$NON-NLS-1$ |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | public static final IElementType Start_3001 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.Start_3001"); //$NON-NLS-1$ |
88 | |
89 | /** |
90 | * @generated |
91 | */ |
92 | public static final IElementType Stop_3002 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.Stop_3002"); //$NON-NLS-1$ |
93 | |
94 | /** |
95 | * @generated |
96 | */ |
97 | public static final IElementType EntryLevelSystemCall_3003 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.EntryLevelSystemCall_3003"); //$NON-NLS-1$ |
98 | |
99 | /** |
100 | * @generated |
101 | */ |
102 | public static final IElementType VariableUsage_3012 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.VariableUsage_3012"); //$NON-NLS-1$ |
103 | |
104 | /** |
105 | * @generated |
106 | */ |
107 | public static final IElementType VariableCharacterisation_3013 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.VariableCharacterisation_3013"); //$NON-NLS-1$ |
108 | |
109 | /** |
110 | * @generated |
111 | */ |
112 | public static final IElementType Loop_3005 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.Loop_3005"); //$NON-NLS-1$ |
113 | |
114 | /** |
115 | * @generated |
116 | */ |
117 | public static final IElementType ScenarioBehaviour_3007 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.ScenarioBehaviour_3007"); //$NON-NLS-1$ |
118 | |
119 | /** |
120 | * @generated |
121 | */ |
122 | public static final IElementType Branch_3008 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.Branch_3008"); //$NON-NLS-1$ |
123 | |
124 | /** |
125 | * @generated |
126 | */ |
127 | public static final IElementType BranchTransition_3009 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.BranchTransition_3009"); //$NON-NLS-1$ |
128 | |
129 | /** |
130 | * @generated |
131 | */ |
132 | public static final IElementType ScenarioBehaviour_3010 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.ScenarioBehaviour_3010"); //$NON-NLS-1$ |
133 | |
134 | /** |
135 | * @generated |
136 | */ |
137 | public static final IElementType Delay_3017 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.Delay_3017"); //$NON-NLS-1$ |
138 | |
139 | /** |
140 | * @generated |
141 | */ |
142 | public static final IElementType ClosedWorkload_3015 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.ClosedWorkload_3015"); //$NON-NLS-1$ |
143 | |
144 | /** |
145 | * @generated |
146 | */ |
147 | public static final IElementType OpenWorkload_3016 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.OpenWorkload_3016"); //$NON-NLS-1$ |
148 | |
149 | /** |
150 | * @generated |
151 | */ |
152 | public static final IElementType AbstractUserActionSuccessor_4002 = getElementType("de.uka.ipd.sdq.pcm.gmf.usage.AbstractUserActionSuccessor_4002"); //$NON-NLS-1$ |
153 | |
154 | /** |
155 | * @generated |
156 | */ |
157 | private static ImageRegistry getImageRegistry() { |
158 | if (imageRegistry == null) { |
159 | imageRegistry = new ImageRegistry(); |
160 | } |
161 | return imageRegistry; |
162 | } |
163 | |
164 | /** |
165 | * @generated |
166 | */ |
167 | private static String getImageRegistryKey(ENamedElement element) { |
168 | return element.getName(); |
169 | } |
170 | |
171 | /** |
172 | * @generated |
173 | */ |
174 | private static ImageDescriptor getProvidedImageDescriptor( |
175 | ENamedElement element) { |
176 | if (element instanceof EStructuralFeature) { |
177 | EStructuralFeature feature = ((EStructuralFeature) element); |
178 | EClass eContainingClass = feature.getEContainingClass(); |
179 | EClassifier eType = feature.getEType(); |
180 | if (eContainingClass != null && !eContainingClass.isAbstract()) { |
181 | element = eContainingClass; |
182 | } else if (eType instanceof EClass |
183 | && !((EClass) eType).isAbstract()) { |
184 | element = eType; |
185 | } |
186 | } |
187 | if (element instanceof EClass) { |
188 | EClass eClass = (EClass) element; |
189 | if (!eClass.isAbstract()) { |
190 | return PalladioComponentModelUsageDiagramEditorPlugin |
191 | .getInstance().getItemImageDescriptor( |
192 | eClass.getEPackage().getEFactoryInstance() |
193 | .create(eClass)); |
194 | } |
195 | } |
196 | // TODO : support structural features |
197 | return null; |
198 | } |
199 | |
200 | /** |
201 | * @generated |
202 | */ |
203 | public static ImageDescriptor getImageDescriptor(ENamedElement element) { |
204 | String key = getImageRegistryKey(element); |
205 | ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key); |
206 | if (imageDescriptor == null) { |
207 | imageDescriptor = getProvidedImageDescriptor(element); |
208 | if (imageDescriptor == null) { |
209 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
210 | } |
211 | getImageRegistry().put(key, imageDescriptor); |
212 | } |
213 | return imageDescriptor; |
214 | } |
215 | |
216 | /** |
217 | * @generated |
218 | */ |
219 | public static Image getImage(ENamedElement element) { |
220 | String key = getImageRegistryKey(element); |
221 | Image image = getImageRegistry().get(key); |
222 | if (image == null) { |
223 | ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element); |
224 | if (imageDescriptor == null) { |
225 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
226 | } |
227 | getImageRegistry().put(key, imageDescriptor); |
228 | image = getImageRegistry().get(key); |
229 | } |
230 | return image; |
231 | } |
232 | |
233 | /** |
234 | * @generated |
235 | */ |
236 | public static ImageDescriptor getImageDescriptor(IAdaptable hint) { |
237 | ENamedElement element = getElement(hint); |
238 | if (element == null) { |
239 | return null; |
240 | } |
241 | return getImageDescriptor(element); |
242 | } |
243 | |
244 | /** |
245 | * @generated |
246 | */ |
247 | public static Image getImage(IAdaptable hint) { |
248 | ENamedElement element = getElement(hint); |
249 | if (element == null) { |
250 | return null; |
251 | } |
252 | return getImage(element); |
253 | } |
254 | |
255 | /** |
256 | * Returns 'type' of the ecore object associated with the hint. |
257 | * |
258 | * @generated |
259 | */ |
260 | public static ENamedElement getElement(IAdaptable hint) { |
261 | Object type = hint.getAdapter(IElementType.class); |
262 | if (elements == null) { |
263 | elements = new IdentityHashMap(); |
264 | |
265 | elements.put(UsageModel_1000, UsagemodelPackage.eINSTANCE |
266 | .getUsageModel()); |
267 | |
268 | elements.put(UsageScenario_2004, UsagemodelPackage.eINSTANCE |
269 | .getUsageScenario()); |
270 | |
271 | elements.put(ScenarioBehaviour_3014, UsagemodelPackage.eINSTANCE |
272 | .getScenarioBehaviour()); |
273 | |
274 | elements.put(Start_3001, UsagemodelPackage.eINSTANCE.getStart()); |
275 | |
276 | elements.put(Stop_3002, UsagemodelPackage.eINSTANCE.getStop()); |
277 | |
278 | elements.put(EntryLevelSystemCall_3003, UsagemodelPackage.eINSTANCE |
279 | .getEntryLevelSystemCall()); |
280 | |
281 | elements.put(VariableUsage_3012, ParameterPackage.eINSTANCE |
282 | .getVariableUsage()); |
283 | |
284 | elements.put(VariableCharacterisation_3013, |
285 | ParameterPackage.eINSTANCE.getVariableCharacterisation()); |
286 | |
287 | elements.put(Loop_3005, UsagemodelPackage.eINSTANCE.getLoop()); |
288 | |
289 | elements.put(ScenarioBehaviour_3007, UsagemodelPackage.eINSTANCE |
290 | .getScenarioBehaviour()); |
291 | |
292 | elements.put(Branch_3008, UsagemodelPackage.eINSTANCE.getBranch()); |
293 | |
294 | elements.put(BranchTransition_3009, UsagemodelPackage.eINSTANCE |
295 | .getBranchTransition()); |
296 | |
297 | elements.put(ScenarioBehaviour_3010, UsagemodelPackage.eINSTANCE |
298 | .getScenarioBehaviour()); |
299 | |
300 | elements.put(Delay_3017, UsagemodelPackage.eINSTANCE.getDelay()); |
301 | |
302 | elements.put(ClosedWorkload_3015, UsagemodelPackage.eINSTANCE |
303 | .getClosedWorkload()); |
304 | |
305 | elements.put(OpenWorkload_3016, UsagemodelPackage.eINSTANCE |
306 | .getOpenWorkload()); |
307 | |
308 | elements.put(AbstractUserActionSuccessor_4002, |
309 | UsagemodelPackage.eINSTANCE |
310 | .getAbstractUserAction_Successor()); |
311 | } |
312 | return (ENamedElement) elements.get(type); |
313 | } |
314 | |
315 | /** |
316 | * @generated |
317 | */ |
318 | private static IElementType getElementType(String id) { |
319 | return ElementTypeRegistry.getInstance().getType(id); |
320 | } |
321 | |
322 | /** |
323 | * @generated |
324 | */ |
325 | public static boolean isKnownElementType(IElementType elementType) { |
326 | if (KNOWN_ELEMENT_TYPES == null) { |
327 | KNOWN_ELEMENT_TYPES = new HashSet(); |
328 | KNOWN_ELEMENT_TYPES.add(UsageModel_1000); |
329 | KNOWN_ELEMENT_TYPES.add(UsageScenario_2004); |
330 | KNOWN_ELEMENT_TYPES.add(ScenarioBehaviour_3014); |
331 | KNOWN_ELEMENT_TYPES.add(Start_3001); |
332 | KNOWN_ELEMENT_TYPES.add(Stop_3002); |
333 | KNOWN_ELEMENT_TYPES.add(EntryLevelSystemCall_3003); |
334 | KNOWN_ELEMENT_TYPES.add(VariableUsage_3012); |
335 | KNOWN_ELEMENT_TYPES.add(VariableCharacterisation_3013); |
336 | KNOWN_ELEMENT_TYPES.add(Loop_3005); |
337 | KNOWN_ELEMENT_TYPES.add(ScenarioBehaviour_3007); |
338 | KNOWN_ELEMENT_TYPES.add(Branch_3008); |
339 | KNOWN_ELEMENT_TYPES.add(BranchTransition_3009); |
340 | KNOWN_ELEMENT_TYPES.add(ScenarioBehaviour_3010); |
341 | KNOWN_ELEMENT_TYPES.add(Delay_3017); |
342 | KNOWN_ELEMENT_TYPES.add(ClosedWorkload_3015); |
343 | KNOWN_ELEMENT_TYPES.add(OpenWorkload_3016); |
344 | KNOWN_ELEMENT_TYPES.add(AbstractUserActionSuccessor_4002); |
345 | } |
346 | return KNOWN_ELEMENT_TYPES.contains(elementType); |
347 | } |
348 | |
349 | /** |
350 | * @generated |
351 | */ |
352 | public static IElementType getElementType(int visualID) { |
353 | switch (visualID) { |
354 | case UsageScenarioEditPart.VISUAL_ID: |
355 | return UsageModel_1000; |
356 | case UsageScenario2EditPart.VISUAL_ID: |
357 | return UsageScenario_2004; |
358 | case ScenarioBehaviourEditPart.VISUAL_ID: |
359 | return ScenarioBehaviour_3014; |
360 | case StartEditPart.VISUAL_ID: |
361 | return Start_3001; |
362 | case StopEditPart.VISUAL_ID: |
363 | return Stop_3002; |
364 | case EntryLevelSystemCallEditPart.VISUAL_ID: |
365 | return EntryLevelSystemCall_3003; |
366 | case VariableUsageEditPart.VISUAL_ID: |
367 | return VariableUsage_3012; |
368 | case VariableCharacterisationEditPart.VISUAL_ID: |
369 | return VariableCharacterisation_3013; |
370 | case LoopEditPart.VISUAL_ID: |
371 | return Loop_3005; |
372 | case ScenarioBehaviour2EditPart.VISUAL_ID: |
373 | return ScenarioBehaviour_3007; |
374 | case BranchEditPart.VISUAL_ID: |
375 | return Branch_3008; |
376 | case BranchTransitionEditPart.VISUAL_ID: |
377 | return BranchTransition_3009; |
378 | case ScenarioBehaviour3EditPart.VISUAL_ID: |
379 | return ScenarioBehaviour_3010; |
380 | case DelayEditPart.VISUAL_ID: |
381 | return Delay_3017; |
382 | case ClosedWorkloadEditPart.VISUAL_ID: |
383 | return ClosedWorkload_3015; |
384 | case OpenWorkloadEditPart.VISUAL_ID: |
385 | return OpenWorkload_3016; |
386 | case AbstractUserActionSuccessorEditPart.VISUAL_ID: |
387 | return AbstractUserActionSuccessor_4002; |
388 | } |
389 | return null; |
390 | } |
391 | |
392 | } |