Is there an example out there for using IDecorationContext
for label decorations?
有没有使用IDecorationContext进行标签装饰的例子?
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...
从它的外观来看,IDecorationContext类似乎提供了某种上下文装饰支持,但对于我的生活,我找不到任何使用此功能的示例代码...
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).
PS:我正在寻找一种将图像装饰应用于对象标签的方法,并且根据对象的显示位置,基本图标大小会有所不同(例如,表和树项中的传统“小”图标和内容标题的较大图标)。
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.
IDecorationContext似乎符合我所需要的条件,但是文档与开源库的一个小功能一样稀疏,并且没有找到示例。
Googling for the "IDecorationContext" did not reveal anything interesting either, so I turn to * crowd wisdom in hopes next guy getting the question would be able to get their answer faster ;)
谷歌搜索“IDecorationContext”也没有透露任何有趣的东西,所以我转向*众智,希望下一个得到问题的人能够更快地得到答案;)
1 个解决方案
#1
7
I did not use IDecorationContext, but you can see it used in org.eclipse.jface.viewers.LabelDecorator
.
我没有使用IDecorationContext,但你可以在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 a ILightweightLabelDecorator to add a replace overlay to the respective icons:
我目前的方法是使用ILightweightLabelDecorator扩展org.eclipse.ui.decorators,为相应的图标添加替换叠加层:
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) {
}
}
}
...
}
#1
7
I did not use IDecorationContext, but you can see it used in org.eclipse.jface.viewers.LabelDecorator
.
我没有使用IDecorationContext,但你可以在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 a ILightweightLabelDecorator to add a replace overlay to the respective icons:
我目前的方法是使用ILightweightLabelDecorator扩展org.eclipse.ui.decorators,为相应的图标添加替换叠加层:
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) {
}
}
}
...
}