是否有人实际使用过装饰上下文功能,如果使用过,它解决了哪些用例?PS:我正在寻找一种将图像装饰应用于对象标签的方法,并且根据对象的显示位置,基本图标大小会有所不同(例如,表格中的传统小"图标和树项目和内容标题的更大图标).应用于原始图标的装饰应相应地选择合适大小的装饰.IDecorationContext 似乎符合我的需要,但文档非常稀疏,正如人们对开源库的一个次要功能所期望的那样,并且没有找到任何示例.谷歌搜索 "IDecorationContext" 也没有发现任何有趣的东西,所以我求助于 StackOverflow 群体智慧,希望下一个得到问题的人能够更快地得到他们的答案;) 解决方案 我没有使用 IDecorationContext,但是你可以看到它在 org.eclipse.jface.viewers.LabelDecorator.这个主题 (就算没有答案,那至少也能给你一个起点)我目前的方法是使用一个扩展 org.eclipse.ui.decoratorsILightweightLabelDecorator 将替换覆盖添加到相应的图标:公共类 ProjectLabelDecorator 扩展了 LabelProvider实现 ILightweightLabelDecorator {...公共无效装饰(对象元素,IDecoration 装饰){如果(元素实例 IFolder){IFolder 文件夹 = (IFolder) 元素;尝试 {if (folder.getProject().hasNature("rttdt.nature")) {如果(ProjectNature.isTestcase(文件夹)){IDecorationContext 上下文 =装饰.getDecorationContext();如果(装饰上下文的上下文实例){((DecorationContext) 上下文).putProperty(IDecoration.ENABLE_REPLACE, Boolean.TRUE);}装饰.addOverlay(fTestcaseOverlay,IDecoration.REPLACE);}} catch (CoreException e) {}}}...}Is there an example out there for using IDecorationContext for label decorations?By the looks of it, IDecorationContext class seems to provide some sort of contextual decoration support, but for the life of me, I can not find any sample code using this feature...Has anybody actually used decoration context feature and if so, what use cases did it solve?PS: I am looking for a way to apply image decorations to object labels and depending on where the object is displayed, the base icon size varies (e.g. traditional "small" icons in table- and tree items and larger icons for content headers).The decorations applied to the original icons should choose appropriate size decorations accordingly.IDecorationContext seems to fit the bill for what I need it for, but the documentation is as sparse as one can expect from a minor feature of an open source library and there are no examples to be found.Googling for the "IDecorationContext" did not reveal anything interesting either, so I turn to StackOverflow crowd wisdom in hopes next guy getting the question would be able to get their answer faster ;) 解决方案 I did not use IDecorationContext, but you can see it used in org.eclipse.jface.viewers.LabelDecorator.It is also discussed in this thread (even if there are no answer, that can at least give you a starting point)My current approach is to extend org.eclipse.ui.decorators using aILightweightLabelDecorator to add a replace overlay to the respectiveicons: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) { } } } ...} 这篇关于如何使用来自 Eclipse JFace 的 IDecorationContext api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-12 22:51