代码之家  ›  专栏  ›  技术社区  ›  Roland Tepp

如何使用EclipseJFace中的IDecorationContext API

  •  7
  • Roland Tepp  · 技术社区  · 16 年前

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

    从表面上看, IDecorationContext 类似乎提供了某种上下文装饰支持,但在我的生活中,我找不到任何使用此功能的示例代码…

    是否有人实际使用了装饰上下文特性,如果是,它解决了什么用例?


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

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

    IDecorationContext 似乎符合我所需要的,但是文档是如此的稀疏,正如人们从一个开放源代码库的一个次要特性所期望的那样,并且没有找到任何例子。

    谷歌搜索 “IDecorationContext” 也没有透露任何有趣的信息,所以我求助于StackOverflow的“群体智慧”,希望下一个得到问题的人能够更快地得到答案;)

    1 回复  |  直到 16 年前
        1
  •  7
  •   VonC    16 年前

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

    它也在中讨论 this thread (即使没有答案,那至少能给你一个起点)

    我目前的方法是使用 ilightweightlabelcorator将替换覆盖添加到相应的 图标:

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