【问题标题】:How would one use IDecorationContext api from Eclipse JFace如何使用来自 Eclipse JFace 的 IDecorationContext api
【发布时间】:2011-01-02 21:56:58
【问题描述】:

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

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

是否有人实际使用过装饰上下文功能,如果有,它解决了哪些用例?


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

应用于原图标的装饰应相应选择合适大小的装饰。

IDecorationContext 似乎符合我的需求,但文档很稀疏,正如人们对开源库的一个次要功能所期望的那样,并且找不到示例。

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

【问题讨论】:

    标签: java eclipse api swt jface


    【解决方案1】:

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

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

    我目前的方法是使用扩展 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 个回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 2018-07-27
    • 2016-04-13
    • 2018-05-11
    • 1970-01-01
    相关资源
    最近更新 更多