org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider Java Examples

The following examples show how to use org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Subclasses should rather override {@link #doGetText}.
 */
@Override
public StyledString getStyledText(Object element) {
	StyledString styledText = convertToStyledString(doGetText(element));
	if (styledText != null) {
		return styledText;
	} else if (delegate != null) {
		if (delegate instanceof IStyledLabelProvider) {
			styledText = ((IStyledLabelProvider) delegate).getStyledText(element);
			if (styledText != null) {
				return styledText;
			}
		} else {
			styledText = convertToStyledString(delegate.getText(element));
			if (styledText != null) {
				return styledText;
			}
		}
	}
	return getDefaultStyledText();
}
 
Example #2
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
public void update(ViewerCell cell) {
	Object element = cell.getElement();

	if (!(element instanceof ItemsListSeparator)
			&& provider instanceof IStyledLabelProvider) {
		IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) provider;
		StyledString styledString = getStyledText(element,
				styledLabelProvider);

		cell.setText(styledString.getString());
		cell.setStyleRanges(styledString.getStyleRanges());
		cell.setImage(styledLabelProvider.getImage(element));
	} else {
		cell.setText(getText(element));
		cell.setImage(getImage(element));
	}
	cell.setFont(getFont(element));
	cell.setForeground(getForeground(element));
	cell.setBackground(getBackground(element));

	super.update(cell);
}
 
Example #3
Source File: GlobalDescriptionLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public StyledString getStyledText(Object element) {
	if (element == null) {
		return new StyledString(Messages.GlobalDescriptionLabelProvider_0);
	} 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());
		}
	}
}
 
Example #4
Source File: DefaultOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Default for textDispatcher
 */
protected Object _text(Object modelElement) {
	if (labelProvider instanceof IStyledLabelProvider)
		return ((IStyledLabelProvider) labelProvider).getStyledText(modelElement);
	else
		return labelProvider.getText(modelElement);
}
 
Example #5
Source File: AbstractOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default for textDispatcher with two arguments.
 *
 * @param modelElement
 *          the {@link EObject} model element
 * @return the label text
 */
// CHECKSTYLE:CHECK-OFF Name (dispatcher enforces names starting with underscore)
protected Object _text(final Object modelElement) {
  // CHECKSTYLE:CHECK-ON
  if (getLabelProvider() instanceof IStyledLabelProvider) {
    return ((IStyledLabelProvider) getLabelProvider()).getStyledText(modelElement);
  } else {
    return getLabelProvider().getText(modelElement);
  }
}
 
Example #6
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Creates a new instance of the class.
 *
 * @param provider
 *            the label provider for all items, not <code>null</code>
 * @param selectionDecorator
 *            the decorator for selected items, can be <code>null</code>
 */
public ItemsListLabelProvider(ILabelProvider provider,
		ILabelDecorator selectionDecorator) {
	Assert.isNotNull(provider);
	this.provider = provider;
	this.selectionDecorator = selectionDecorator;

	setOwnerDrawEnabled(showColoredLabels() && provider instanceof IStyledLabelProvider);

	provider.addListener(this);

	if (selectionDecorator != null) {
		selectionDecorator.addListener(this);
	}
}
 
Example #7
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Sets new label provider.
 *
 * @param newProvider
 *            new label provider for items in the list, not
 *            <code>null</code>
 */
public void setProvider(ILabelProvider newProvider) {
	Assert.isNotNull(newProvider);
	provider.removeListener(this);
	provider.dispose();

	provider = newProvider;

	if (provider != null) {
		provider.addListener(this);
	}

	setOwnerDrawEnabled(showColoredLabels() && provider instanceof IStyledLabelProvider);
}
 
Example #8
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 5 votes vote down vote up
private StyledString getStyledText(Object element,
		IStyledLabelProvider provider) {
	StyledString string = provider.getStyledText(element);

	if (selectionDecorator != null && isSelected(element)) {
		String decorated = selectionDecorator.decorateText(string
				.getString(), element);
		return StyledCellLabelProvider.styleDecoratedString(decorated, null, string);
		// no need to add colors when element is selected
	}
	return string;
}
 
Example #9
Source File: SearchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected StyledString getStyledParticipantText(Object element) {
	ILabelProvider labelProvider= getLabelProvider(element);
	if (labelProvider instanceof IStyledLabelProvider)
		return ((IStyledLabelProvider) labelProvider).getStyledText(element);
	if (labelProvider != null)
		return new StyledString(labelProvider.getText(element));
	return new StyledString();
}
 
Example #10
Source File: SARLOutlineTreeProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Compute the text for the given JVM constructor, which is usually a inherited constructor.
 *
 * @param modelElement the model
 * @return the text.
 */
protected CharSequence _text(JvmConstructor modelElement) {
	if (this.labelProvider instanceof IStyledLabelProvider) {
		final StyledString str = ((IStyledLabelProvider) this.labelProvider).getStyledText(modelElement);
		str.setStyle(0, str.length(), ColoringLabelProvider.INHERITED_STYLER);
		return str;
	}
	return this.labelProvider.getText(modelElement);
}
 
Example #11
Source File: BackgroundOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Object getText(Object modelElement) {
	if (getLabelProvider() instanceof IStyledLabelProvider)
		return ((IStyledLabelProvider) getLabelProvider()).getStyledText(modelElement);
	else
		return getLabelProvider().getText(modelElement);
}