Community
Participate
Working Groups
While refactoring the (pde) StyledBundleLabelProvider I really wondered why there is no interface for such kind of usage as it seems quite useful for making (generic) formated labels. I then noticed that JFace already offers something similar with DelegatingStyledCellLabelProvider.IStyledLabelProvider but it is embedded in the DelegatingStyledCellLabelProvider and is missing a getText(Object) that seems to be required in some places e.g. for automatic ordering and redifines a getImage method. So I wonder if it would be an option to have a dedicated interface that extends ILabelProvider in the following way: public interface IStyledLabelProvider extends ILabelProvider { /** * Returns the styled text label for the given element * * @param element the element to evaluate the styled string for * * @return the styled string. */ StyledString getStyledString(Object element); @Override default String getText(Object element) { StyledString styledString = getStyledString(element); if (styledString == null) { return null; } return styledString.getString(); } } once the interface is added the DelegatingStyledCellLabelProvider.IStyledLabelProvider could simply extend the new IStyledLabelProvider for backward compatibility.
@Christoph your suggestion looks good if we abstract from the surrounding code. I'm not sure why it was decided long ago to declare "DelegatingStyledCellLabelProvider.IStyledLabelProvider extends IBaseLabelProvider" and, moreover, to declare every particular I*LabelProvider to extend this IBaseLabelProvider - but this is something to consider before introducing "IStyledLabelProvider extends ILabelProvider" I would also have a look on related classes from EMF UI to understand the potential direct or "ideological" impact: `org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider.StyledLabelProvider` `org.eclipse.emf.common.ui.viewer.IStyledLabelDecorator`
We could also add the new interface and just deprecate the embedded one with a hint that there might be an alternative for code using newer API? I just don't mind much about making the code "cleaner" but for new APIs it just sounds strange to adapt to a DelegatingStyledCellLabelProvider.IStyledLabelProvider (even though it is already used in such a way on some places).