如何使用Eclipse JFace中的IDecorationContext API?

7
有没有使用IDecorationContext为标签装饰提供示例的?看起来,IDecorationContext类似乎提供了某种上下文装饰支持,但是我找不到任何使用此功能的示例代码...是否有人实际使用过装饰上下文功能,如果有,它解决了哪些用例?
PS:我正在寻找一种方法将图像装饰应用于对象标签,并根据对象显示的位置变化基本图标大小(例如,传统的“小”图标在表格和树项目中,较大的图标用于内容标题)。
应用于原始图标的装饰应选择相应大小的装饰。 IDecorationContext似乎适合我所需要的,但是文档像预期的那样稀少,因为这是开源库的一个小特性,也没有找到任何示例。
对于“IDecorationContext”的谷歌搜索也没有发现任何有趣的东西,因此我求助于StackOverflow社区智慧,希望下一个得到答案的人能更快地得到答案 ;)
1个回答

7

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

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

我的当前方法是通过扩展org.eclipse.ui.decorators并使用ILightweightLabelDecorator来向相应的图标添加替换覆盖:

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) {
         }
      }
   }

   ...
}

备忘录:这似乎是我在SO上的第2000个答案。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接