Bug 576640 - [JFace] add a dedicated IStyledLabelProvider interface?
Summary: [JFace] add a dedicated IStyledLabelProvider interface?
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.22   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-15 02:42 EDT by Christoph Laeubrich CLA
Modified: 2021-10-15 03:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Laeubrich CLA 2021-10-15 02:42:31 EDT
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.
Comment 1 Alexander Fedorov CLA 2021-10-15 03:13:25 EDT
@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`
Comment 2 Christoph Laeubrich CLA 2021-10-15 03:37:44 EDT
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).