一个人怎么会用在Eclipse中的JFace IDecorationContext API
题
是否有一个例子在那里使用IDecorationContext
用于标签装饰品?
这是它的外观,IDecorationContext
类似乎提供了某种情境装修支持,但对我的生活,我可以使用此功能没有发现任何样本代码...
有没有人实际使用的装饰背景功能,如果是的话,它解决什么用例?
<强> PS:强>我要寻找一种方法来应用图像装饰品到对象的标签,并根据被显示的对象,其中,基座图标大小而变化(例如,在表 - 传统的“小”的图标和树项目和内容头部较大的图标)。
应用到原始图标的装饰品应该相应地选择合适的尺寸的装饰品。
IDecorationContext
似乎适合什么,我需要它支持该法案,但文档是稀疏的人们可以从一个开源库的一个小功能,期待并没有被发现的例子。
谷歌搜索的的“IDecorationContext” 的并没有透露什么有趣或者,让我转向StackOverflow的人群的智慧,希望未来的家伙得到的问题将能够得到他们的回答快;)
解决方案
我没有用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) {
}
}
}
...
}
不隶属于 StackOverflow