| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, U KA |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.allocation.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.allocation.AllocationPackage; |
| 23 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelAllocationDiagramEditorPlugin; |
| 24 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage; |
| 25 | |
| 26 | /** |
| 27 | * @generated |
| 28 | */ |
| 29 | public class PalladioComponentModelElementTypes extends ElementInitializers { |
| 30 | |
| 31 | /** |
| 32 | * @generated |
| 33 | */ |
| 34 | private PalladioComponentModelElementTypes() { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @generated |
| 39 | */ |
| 40 | private static Map elements; |
| 41 | |
| 42 | /** |
| 43 | * @generated |
| 44 | */ |
| 45 | private static ImageRegistry imageRegistry; |
| 46 | |
| 47 | /** |
| 48 | * @generated |
| 49 | */ |
| 50 | private static Set KNOWN_ELEMENT_TYPES; |
| 51 | |
| 52 | /** |
| 53 | * @generated |
| 54 | */ |
| 55 | public static final IElementType Allocation_1000 = getElementType("de.uka.ipd.sdq.pcm.gmf.allocation.Allocation_1000"); //$NON-NLS-1$ |
| 56 | /** |
| 57 | * @generated |
| 58 | */ |
| 59 | public static final IElementType ResourceContainer_2002 = getElementType("de.uka.ipd.sdq.pcm.gmf.allocation.ResourceContainer_2002"); //$NON-NLS-1$ |
| 60 | /** |
| 61 | * @generated |
| 62 | */ |
| 63 | public static final IElementType AllocationContext_3001 = getElementType("de.uka.ipd.sdq.pcm.gmf.allocation.AllocationContext_3001"); //$NON-NLS-1$ |
| 64 | |
| 65 | /** |
| 66 | * @generated |
| 67 | */ |
| 68 | private static ImageRegistry getImageRegistry() { |
| 69 | if (imageRegistry == null) { |
| 70 | imageRegistry = new ImageRegistry(); |
| 71 | } |
| 72 | return imageRegistry; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @generated |
| 77 | */ |
| 78 | private static String getImageRegistryKey(ENamedElement element) { |
| 79 | return element.getName(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @generated |
| 84 | */ |
| 85 | private static ImageDescriptor getProvidedImageDescriptor( |
| 86 | ENamedElement element) { |
| 87 | if (element instanceof EStructuralFeature) { |
| 88 | EStructuralFeature feature = ((EStructuralFeature) element); |
| 89 | EClass eContainingClass = feature.getEContainingClass(); |
| 90 | EClassifier eType = feature.getEType(); |
| 91 | if (eContainingClass != null && !eContainingClass.isAbstract()) { |
| 92 | element = eContainingClass; |
| 93 | } else if (eType instanceof EClass |
| 94 | && !((EClass) eType).isAbstract()) { |
| 95 | element = eType; |
| 96 | } |
| 97 | } |
| 98 | if (element instanceof EClass) { |
| 99 | EClass eClass = (EClass) element; |
| 100 | if (!eClass.isAbstract()) { |
| 101 | return PalladioComponentModelAllocationDiagramEditorPlugin |
| 102 | .getInstance().getItemImageDescriptor( |
| 103 | eClass.getEPackage().getEFactoryInstance() |
| 104 | .create(eClass)); |
| 105 | } |
| 106 | } |
| 107 | // TODO : support structural features |
| 108 | return null; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @generated |
| 113 | */ |
| 114 | public static ImageDescriptor getImageDescriptor(ENamedElement element) { |
| 115 | String key = getImageRegistryKey(element); |
| 116 | ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key); |
| 117 | if (imageDescriptor == null) { |
| 118 | imageDescriptor = getProvidedImageDescriptor(element); |
| 119 | if (imageDescriptor == null) { |
| 120 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
| 121 | } |
| 122 | getImageRegistry().put(key, imageDescriptor); |
| 123 | } |
| 124 | return imageDescriptor; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @generated |
| 129 | */ |
| 130 | public static Image getImage(ENamedElement element) { |
| 131 | String key = getImageRegistryKey(element); |
| 132 | Image image = getImageRegistry().get(key); |
| 133 | if (image == null) { |
| 134 | ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element); |
| 135 | if (imageDescriptor == null) { |
| 136 | imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
| 137 | } |
| 138 | getImageRegistry().put(key, imageDescriptor); |
| 139 | image = getImageRegistry().get(key); |
| 140 | } |
| 141 | return image; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @generated |
| 146 | */ |
| 147 | public static ImageDescriptor getImageDescriptor(IAdaptable hint) { |
| 148 | ENamedElement element = getElement(hint); |
| 149 | if (element == null) { |
| 150 | return null; |
| 151 | } |
| 152 | return getImageDescriptor(element); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @generated |
| 157 | */ |
| 158 | public static Image getImage(IAdaptable hint) { |
| 159 | ENamedElement element = getElement(hint); |
| 160 | if (element == null) { |
| 161 | return null; |
| 162 | } |
| 163 | return getImage(element); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns 'type' of the ecore object associated with the hint. |
| 168 | * |
| 169 | * @generated |
| 170 | */ |
| 171 | public static ENamedElement getElement(IAdaptable hint) { |
| 172 | Object type = hint.getAdapter(IElementType.class); |
| 173 | if (elements == null) { |
| 174 | elements = new IdentityHashMap(); |
| 175 | |
| 176 | elements.put(Allocation_1000, AllocationPackage.eINSTANCE |
| 177 | .getAllocation()); |
| 178 | |
| 179 | elements |
| 180 | .put(ResourceContainer_2002, |
| 181 | ResourceenvironmentPackage.eINSTANCE |
| 182 | .getResourceContainer()); |
| 183 | |
| 184 | elements.put(AllocationContext_3001, AllocationPackage.eINSTANCE |
| 185 | .getAllocationContext()); |
| 186 | } |
| 187 | return (ENamedElement) elements.get(type); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @generated |
| 192 | */ |
| 193 | private static IElementType getElementType(String id) { |
| 194 | return ElementTypeRegistry.getInstance().getType(id); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @generated |
| 199 | */ |
| 200 | public static boolean isKnownElementType(IElementType elementType) { |
| 201 | if (KNOWN_ELEMENT_TYPES == null) { |
| 202 | KNOWN_ELEMENT_TYPES = new HashSet(); |
| 203 | KNOWN_ELEMENT_TYPES.add(Allocation_1000); |
| 204 | KNOWN_ELEMENT_TYPES.add(ResourceContainer_2002); |
| 205 | KNOWN_ELEMENT_TYPES.add(AllocationContext_3001); |
| 206 | } |
| 207 | return KNOWN_ELEMENT_TYPES.contains(elementType); |
| 208 | } |
| 209 | |
| 210 | } |