/** | |
* <copyright> | |
* | |
* Copyright (c) 2013 itemis and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html | |
* | |
* Contributors: | |
* itemis - Initial API and implementation | |
* | |
* </copyright> | |
*/ | |
package org.eclipse.sphinx.examples.hummingbird20.diagram.gmf.providers; | |
import java.util.HashSet; | |
import java.util.IdentityHashMap; | |
import java.util.Map; | |
import java.util.Set; | |
import org.eclipse.core.runtime.IAdaptable; | |
import org.eclipse.emf.ecore.EClass; | |
import org.eclipse.emf.ecore.EClassifier; | |
import org.eclipse.emf.ecore.ENamedElement; | |
import org.eclipse.emf.ecore.EStructuralFeature; | |
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; | |
import org.eclipse.gmf.runtime.emf.type.core.IElementType; | |
import org.eclipse.jface.resource.ImageDescriptor; | |
import org.eclipse.jface.resource.ImageRegistry; | |
import org.eclipse.sphinx.examples.hummingbird20.diagram.gmf.edit.parts.ApplicationEditPart; | |
import org.eclipse.sphinx.examples.hummingbird20.diagram.gmf.edit.parts.ComponentEditPart; | |
import org.eclipse.sphinx.examples.hummingbird20.diagram.gmf.edit.parts.ConnectionEditPart; | |
import org.eclipse.sphinx.examples.hummingbird20.diagram.gmf.part.Hummingbird20DiagramEditorPlugin; | |
import org.eclipse.sphinx.examples.hummingbird20.instancemodel.InstanceModel20Package; | |
import org.eclipse.swt.graphics.Image; | |
/** | |
* @generated | |
*/ | |
public class Hummingbird20ElementTypes { | |
/** | |
* @generated | |
*/ | |
private Hummingbird20ElementTypes() { | |
} | |
/** | |
* @generated | |
*/ | |
private static Map<IElementType, ENamedElement> elements; | |
/** | |
* @generated | |
*/ | |
private static ImageRegistry imageRegistry; | |
/** | |
* @generated | |
*/ | |
private static Set<IElementType> KNOWN_ELEMENT_TYPES; | |
/** | |
* @generated | |
*/ | |
public static final IElementType Application_1000 = getElementType("org.eclipse.sphinx.examples.hummingbird20.diagram.Application_1000"); //$NON-NLS-1$ | |
/** | |
* @generated | |
*/ | |
public static final IElementType Component_2001 = getElementType("org.eclipse.sphinx.examples.hummingbird20.diagram.Component_2001"); //$NON-NLS-1$ | |
/** | |
* @generated | |
*/ | |
public static final IElementType Connection_4001 = getElementType("org.eclipse.sphinx.examples.hummingbird20.diagram.Connection_4001"); //$NON-NLS-1$ | |
/** | |
* @generated | |
*/ | |
private static ImageRegistry getImageRegistry() { | |
if (imageRegistry == null) { | |
imageRegistry = new ImageRegistry(); | |
} | |
return imageRegistry; | |
} | |
/** | |
* @generated | |
*/ | |
private static String getImageRegistryKey(ENamedElement element) { | |
return element.getName(); | |
} | |
/** | |
* @generated | |
*/ | |
private static ImageDescriptor getProvidedImageDescriptor(ENamedElement element) { | |
if (element instanceof EStructuralFeature) { | |
EStructuralFeature feature = (EStructuralFeature) element; | |
EClass eContainingClass = feature.getEContainingClass(); | |
EClassifier eType = feature.getEType(); | |
if (eContainingClass != null && !eContainingClass.isAbstract()) { | |
element = eContainingClass; | |
} else if (eType instanceof EClass && !((EClass) eType).isAbstract()) { | |
element = eType; | |
} | |
} | |
if (element instanceof EClass) { | |
EClass eClass = (EClass) element; | |
if (!eClass.isAbstract()) { | |
return Hummingbird20DiagramEditorPlugin.getInstance().getItemImageDescriptor( | |
eClass.getEPackage().getEFactoryInstance().create(eClass)); | |
} | |
} | |
// TODO : support structural features | |
return null; | |
} | |
/** | |
* @generated | |
*/ | |
public static ImageDescriptor getImageDescriptor(ENamedElement element) { | |
String key = getImageRegistryKey(element); | |
ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key); | |
if (imageDescriptor == null) { | |
imageDescriptor = getProvidedImageDescriptor(element); | |
if (imageDescriptor == null) { | |
imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); | |
} | |
getImageRegistry().put(key, imageDescriptor); | |
} | |
return imageDescriptor; | |
} | |
/** | |
* @generated | |
*/ | |
public static Image getImage(ENamedElement element) { | |
String key = getImageRegistryKey(element); | |
Image image = getImageRegistry().get(key); | |
if (image == null) { | |
ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element); | |
if (imageDescriptor == null) { | |
imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); | |
} | |
getImageRegistry().put(key, imageDescriptor); | |
image = getImageRegistry().get(key); | |
} | |
return image; | |
} | |
/** | |
* @generated | |
*/ | |
public static ImageDescriptor getImageDescriptor(IAdaptable hint) { | |
ENamedElement element = getElement(hint); | |
if (element == null) { | |
return null; | |
} | |
return getImageDescriptor(element); | |
} | |
/** | |
* @generated | |
*/ | |
public static Image getImage(IAdaptable hint) { | |
ENamedElement element = getElement(hint); | |
if (element == null) { | |
return null; | |
} | |
return getImage(element); | |
} | |
/** | |
* Returns 'type' of the ecore object associated with the hint. | |
* | |
* @generated | |
*/ | |
public static ENamedElement getElement(IAdaptable hint) { | |
Object type = hint.getAdapter(IElementType.class); | |
if (elements == null) { | |
elements = new IdentityHashMap<IElementType, ENamedElement>(); | |
elements.put(Application_1000, InstanceModel20Package.eINSTANCE.getApplication()); | |
elements.put(Component_2001, InstanceModel20Package.eINSTANCE.getComponent()); | |
elements.put(Connection_4001, InstanceModel20Package.eINSTANCE.getConnection()); | |
} | |
return elements.get(type); | |
} | |
/** | |
* @generated | |
*/ | |
private static IElementType getElementType(String id) { | |
return ElementTypeRegistry.getInstance().getType(id); | |
} | |
/** | |
* @generated | |
*/ | |
public static boolean isKnownElementType(IElementType elementType) { | |
if (KNOWN_ELEMENT_TYPES == null) { | |
KNOWN_ELEMENT_TYPES = new HashSet<IElementType>(); | |
KNOWN_ELEMENT_TYPES.add(Application_1000); | |
KNOWN_ELEMENT_TYPES.add(Component_2001); | |
KNOWN_ELEMENT_TYPES.add(Connection_4001); | |
} | |
return KNOWN_ELEMENT_TYPES.contains(elementType); | |
} | |
/** | |
* @generated | |
*/ | |
public static IElementType getElementType(int visualID) { | |
switch (visualID) { | |
case ApplicationEditPart.VISUAL_ID: | |
return Application_1000; | |
case ComponentEditPart.VISUAL_ID: | |
return Component_2001; | |
case ConnectionEditPart.VISUAL_ID: | |
return Connection_4001; | |
} | |
return null; | |
} | |
} |