如何使用Eclipse JFace中的IDecorationContext api

有没有使用IDecorationContext进行标签装饰的例子?

从它的外观来看, IDecorationContext类似乎提供了某种上下文装饰支持,但对于我的生活,我找不到任何使用此function的示例代码…

有没有人实际使用装饰上下文function,如果有,它解决了什么用例?


PS:我正在寻找一种方法将图像装饰应用于对象标签,并根据对象的显示位置,基本图标大小不同(例如,表和树项中的传统“小”图标和内容标题的较大图标)。

应用于原始图标的装饰应相应地选择合适的尺寸装饰。

IDecorationContext似乎符合我所需要的条件,但是文档与开源库的一个小function一样稀疏,并且没有找到示例。

谷歌搜索“IDecorationContext”也没有透露任何有趣的东西,所以我转向StackOverflow 众智 ,希望下一个得到问题的人能够更快地得到答案;)

我没有使用IDecorationContext,但你可以在org.eclipse.jface.viewers.LabelDecorator看到它。

它也在这个post中讨论过(即使没有答案,至少可以给你一个起点)

我目前的方法是使用ILightweightLabelDecorator扩展org.eclipse.ui.decorators,为相应的图标添加替换叠加层:

 public class ProjectLabelDecorator extends LabelProvider implements ILightweightLabelDecorator { ... public void decorate(Object element, IDecoration decoration) { if (element instanceof IFolder) { IFolder folder = (IFolder) element; try { if (folder.getProject().hasNature("rttdt.nature")) { if (ProjectNature.isTestcase(folder)) { IDecorationContext context = decoration.getDecorationContext(); if (context instanceof DecorationContext) { ((DecorationContext) context).putProperty( IDecoration.ENABLE_REPLACE, Boolean.TRUE); } decoration.addOverlay(fTestcaseOverlay, IDecoration.REPLACE); } } catch (CoreException e) { } } } ... }