1 | /* |
2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.resource.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.resource.edit.parts.CommunicationLinkResourceSpecificationEditPart; |
23 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResource2EditPart; |
24 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceConnectedResourceContainers_LinkingResourceEditPart; |
25 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceEnvironmentEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelDiagramEditorPlugin; |
29 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage; |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | public class PalladioComponentModelElementTypes extends ElementInitializers { |
35 | |
36 | /** |
37 | * @generated |
38 | */ |
39 | private PalladioComponentModelElementTypes() { |
40 | } |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | private static Map elements; |
46 | |
47 | /** |
48 | * @generated |
49 | */ |
50 | private static ImageRegistry imageRegistry; |
51 | |
52 | /** |
53 | * @generated |
54 | */ |
55 | private static Set KNOWN_ELEMENT_TYPES; |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | public static final IElementType ResourceEnvironment_1000 = getElementType("de.uka.ipd.sdq.pcm.gmf.resource.ResourceEnvironment_1000"); //$NON-NLS-1$ |
61 | /** |
62 | * @generated |
63 | */ |
64 | public static final IElementType ResourceContainer_2001 = getElementType("de.uka.ipd.sdq.pcm.gmf.resource.ResourceContainer_2001"); //$NON-NLS-1$ |
65 | /** |
66 | * @generated |
67 | */ |
68 | public static final IElementType LinkingResource_2003 = getElementType("de.uka.ipd.sdq.pcm.gmf.resource.LinkingResource_2003"); //$NON-NLS-1$ |
69 | |
70 | /** |
71 | * @generated |
72 | */ |
73 | public static final IElementType ProcessingResourceSpecification_3001 = getElementType("de.uka.ipd.sdq.pcm.gmf.resource.ProcessingResourceSpecification_3001"); //$NON-NLS-1$ |
74 | |
75 | /** |
76 | * @generated |
77 | */ |
78 | public static final IElementType CommunicationLinkResourceSpecification_3002 = getElementType("de.uka.ipd.sdq.pcm.gmf.resource.CommunicationLinkResourceSpecification_3002"); //$NON-NLS-1$ |
79 | |
80 | /** |
81 | * @generated |
82 | */ |
83 | public static final IElementType LinkingResourceConnectedResourceContainers_LinkingResource_4002 = getElementType("de.uka.ipd.sdq.pcm.gmf.resource.LinkingResourceConnectedResourceContainers_LinkingResource_4002"); //$NON-NLS-1$ |
84 | |
85 | /** |
86 | * @generated |
87 | */ |
88 | private static ImageRegistry getImageRegistry() { |
89 | if (imageRegistry == null) { |
90 | imageRegistry = new ImageRegistry(); |
91 | } |
92 | return imageRegistry; |
93 | } |
94 | |
95 | /** |
96 | * @generated |
97 | */ |
98 | private static String getImageRegistryKey(ENamedElement element) { |
99 | return element.getName(); |
100 | } |
101 | |
102 | /** |
103 | * @generated |
104 | */ |
105 | private static ImageDescriptor getProvidedImageDescriptor( |
106 | ENamedElement element) { |
107 | if (element instanceof EStructuralFeature) { |
108 | EStructuralFeature feature = ((EStructuralFeature) element); |
109 | EClass eContainingClass = feature.getEContainingClass(); |
110 | EClassifier eType = feature.getEType(); |
111 | if (eContainingClass != null && !eContainingClass.isAbstract()) { |
112 | element = eContainingClass; |
113 | } else if (eType instanceof EClass |
114 | && !((EClass) eType).isAbstract()) { |
115 | element = eType; |
116 | } |
117 | } |
118 | if (element instanceof EClass) { |
119 | EClass eClass = (EClass) element; |
120 | if (!eClass.isAbstract()) { |
121 | return PalladioComponentModelDiagramEditorPlugin.getInstance() |
122 | .getItemImageDescriptor( |
123 | eClass.getEPackage().getEFactoryInstance() |
124 | .create(eClass)); |
125 | } |
126 | } |
127 | // TODO : support structural features |
128 | return null; |
129 | } |
130 | |
131 | /** |
132 | * @generated |
133 | */ |
134 | public static ImageDescriptor getImageDescriptor(ENamedElement element) { |
135 | String key = getImageRegistryKey(element); |
136 | ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key); |
137 | if (imageDescriptor == null) { |
138 | imageDescriptor = getProvidedImageDescriptor(element); |
139 | if (imageDescriptor == null) { |
140 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
141 | } |
142 | getImageRegistry().put(key, imageDescriptor); |
143 | } |
144 | return imageDescriptor; |
145 | } |
146 | |
147 | /** |
148 | * @generated |
149 | */ |
150 | public static Image getImage(ENamedElement element) { |
151 | String key = getImageRegistryKey(element); |
152 | Image image = getImageRegistry().get(key); |
153 | if (image == null) { |
154 | ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element); |
155 | if (imageDescriptor == null) { |
156 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
157 | } |
158 | getImageRegistry().put(key, imageDescriptor); |
159 | image = getImageRegistry().get(key); |
160 | } |
161 | return image; |
162 | } |
163 | |
164 | /** |
165 | * @generated |
166 | */ |
167 | public static ImageDescriptor getImageDescriptor(IAdaptable hint) { |
168 | ENamedElement element = getElement(hint); |
169 | if (element == null) { |
170 | return null; |
171 | } |
172 | return getImageDescriptor(element); |
173 | } |
174 | |
175 | /** |
176 | * @generated |
177 | */ |
178 | public static Image getImage(IAdaptable hint) { |
179 | ENamedElement element = getElement(hint); |
180 | if (element == null) { |
181 | return null; |
182 | } |
183 | return getImage(element); |
184 | } |
185 | |
186 | /** |
187 | * Returns 'type' of the ecore object associated with the hint. |
188 | * |
189 | * @generated |
190 | */ |
191 | public static ENamedElement getElement(IAdaptable hint) { |
192 | Object type = hint.getAdapter(IElementType.class); |
193 | if (elements == null) { |
194 | elements = new IdentityHashMap(); |
195 | |
196 | elements.put(ResourceEnvironment_1000, |
197 | ResourceenvironmentPackage.eINSTANCE |
198 | .getResourceEnvironment()); |
199 | |
200 | elements |
201 | .put(ResourceContainer_2001, |
202 | ResourceenvironmentPackage.eINSTANCE |
203 | .getResourceContainer()); |
204 | |
205 | elements.put(LinkingResource_2003, |
206 | ResourceenvironmentPackage.eINSTANCE.getLinkingResource()); |
207 | |
208 | elements.put(ProcessingResourceSpecification_3001, |
209 | ResourceenvironmentPackage.eINSTANCE |
210 | .getProcessingResourceSpecification()); |
211 | |
212 | elements.put(CommunicationLinkResourceSpecification_3002, |
213 | ResourceenvironmentPackage.eINSTANCE |
214 | .getCommunicationLinkResourceSpecification()); |
215 | |
216 | elements |
217 | .put( |
218 | LinkingResourceConnectedResourceContainers_LinkingResource_4002, |
219 | ResourceenvironmentPackage.eINSTANCE |
220 | .getLinkingResource_ConnectedResourceContainers_LinkingResource()); |
221 | } |
222 | return (ENamedElement) elements.get(type); |
223 | } |
224 | |
225 | /** |
226 | * @generated |
227 | */ |
228 | private static IElementType getElementType(String id) { |
229 | return ElementTypeRegistry.getInstance().getType(id); |
230 | } |
231 | |
232 | /** |
233 | * @generated |
234 | */ |
235 | public static boolean isKnownElementType(IElementType elementType) { |
236 | if (KNOWN_ELEMENT_TYPES == null) { |
237 | KNOWN_ELEMENT_TYPES = new HashSet(); |
238 | KNOWN_ELEMENT_TYPES.add(ResourceEnvironment_1000); |
239 | KNOWN_ELEMENT_TYPES.add(ResourceContainer_2001); |
240 | KNOWN_ELEMENT_TYPES.add(LinkingResource_2003); |
241 | KNOWN_ELEMENT_TYPES.add(ProcessingResourceSpecification_3001); |
242 | KNOWN_ELEMENT_TYPES |
243 | .add(CommunicationLinkResourceSpecification_3002); |
244 | KNOWN_ELEMENT_TYPES |
245 | .add(LinkingResourceConnectedResourceContainers_LinkingResource_4002); |
246 | } |
247 | return KNOWN_ELEMENT_TYPES.contains(elementType); |
248 | } |
249 | |
250 | /** |
251 | * @generated |
252 | */ |
253 | public static IElementType getElementType(int visualID) { |
254 | switch (visualID) { |
255 | case ResourceEnvironmentEditPart.VISUAL_ID: |
256 | return ResourceEnvironment_1000; |
257 | case ResourceContainerEditPart.VISUAL_ID: |
258 | return ResourceContainer_2001; |
259 | case LinkingResource2EditPart.VISUAL_ID: |
260 | return LinkingResource_2003; |
261 | case ProcessingResourceSpecificationEditPart.VISUAL_ID: |
262 | return ProcessingResourceSpecification_3001; |
263 | case CommunicationLinkResourceSpecificationEditPart.VISUAL_ID: |
264 | return CommunicationLinkResourceSpecification_3002; |
265 | case LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID: |
266 | return LinkingResourceConnectedResourceContainers_LinkingResource_4002; |
267 | } |
268 | return null; |
269 | } |
270 | |
271 | } |