/*****************************************************************************
* Copyright (c) 2011 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.properties.providers;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistry;
import org.eclipse.papyrus.infra.core.editorsfactory.PageIconsRegistry;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.swt.graphics.Image;
/**
* An EMFObjectLabelProvider with support for GMF Diagram icons
*
* @author Camille Letavernier
*
*/
public class GMFLabelProvider extends EMFLabelProvider {
protected IPageIconsRegistry editorRegistry;
/**
* {@inheritDoc}
*/
@Override
public Image getImage(Object element) {
if(element instanceof Diagram) {
return getEditorRegistry().getEditorIcon(element);
}
return super.getImage(element);
}
/**
* Get the EditorRegistry used to create editor instances. This default
* implementation return the singleton eINSTANCE. This method can be
* subclassed to return another registry.
*
* @return the singleton eINSTANCE of editor registry
*/
protected IPageIconsRegistry getEditorRegistry() {
if(editorRegistry == null) {
editorRegistry = createEditorRegistry();
}
return editorRegistry;
}
/**
* Return the EditorRegistry for nested editor descriptors. Subclass should
* implements this method in order to return the registry associated to the
* extension point namespace.
*
* @return the EditorRegistry for nested editor descriptors
*/
protected IPageIconsRegistry createEditorRegistry() {
try {
return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class);
} catch (ServiceException e) {
// Not found, return an empty one which return null for each
// request.
return new PageIconsRegistry();
}
}
}