Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. 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 /
 
 package org.eclipse.xtext.ui.label;
 
import  org.eclipse.emf.edit.provider.IItemLabelProvider;
import  org.eclipse.jface.viewers.BaseLabelProvider;
import  org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import  org.eclipse.jface.viewers.ILabelProvider;
import  org.eclipse.jface.viewers.StyledString;
import  org.eclipse.swt.graphics.Image;
Delegates to the DefaultDescriptionLabelProvider looked up in the org.eclipse.xtext.resource.IResourceServiceProvider.Registry

Author(s):
Jan Koehnlein - Initial contribution and API
public class GlobalDescriptionLabelProvider extends BaseLabelProvider implements ILabelProvider, IItemLabelProvider, IStyledLabelProvider {
	public Image getImage(Object element) {
		ILabelProvider descriptionLabelProvider = lookupDescriptionLabelProvider(element);
		if (descriptionLabelProvider != null) {
			return descriptionLabelProvider.getImage(element);
else {
			return null;
		}
	}
	public String getText(Object element) {
		if (element == null) {
else {
			ILabelProvider descriptionLabelProvider = lookupDescriptionLabelProvider(element);
			if (descriptionLabelProvider != null) {
				return descriptionLabelProvider.getText(element);
else {
				return element.toString();
			}
		}
	}
	public StyledString getStyledText(Object element) {
		if (element == null) {
			return new StyledString(.);
else {
			ILabelProvider descriptionLabelProvider = lookupDescriptionLabelProvider(element);
			if (descriptionLabelProvider instanceof IStyledLabelProvider)
				return ((IStyledLabelProvider) descriptionLabelProvider).getStyledText(element);
			else if(descriptionLabelProvider != null) {
				return new StyledString(descriptionLabelProvider.getText(element));
else {
				return new StyledString(element.toString());
			}
		}
	}

Since:
2.1 protected
	protected ILabelProvider lookupDescriptionLabelProvider(Object description) {
		URI uri = uri(description);
		if (uri != null) {
			if (resourceServiceProvider instanceof IResourceUIServiceProvider)
				return ((IResourceUIServiceProviderresourceServiceProvider).getLabelProvider();
		}
		return null;
	}

Since:
2.1 protected
	protected URI uri(Object description) {
		if (description instanceof IEObjectDescription) {
			return ((IEObjectDescriptiondescription).getEObjectURI();
else if (description instanceof IResourceDescription) {
			return ((IResourceDescriptiondescription).getURI();
else if(description instanceof IReferenceDescription) {
			URI containerEObjectURI = ((IReferenceDescriptiondescription).getContainerEObjectURI();
			return containerEObjectURI == null ? ((IReferenceDescriptiondescription).getSourceEObjectUri() : null;
		}
		return null;
	}
New to GrepCode? Check out our FAQ X