Rol*_*epp 7 java eclipse api swt jface
有没有IDecorationContext用于标签装饰的例子?
通过它的外观,IDecorationContext类似乎提供某种上下文装饰支持,但对于我的生活,我找不到使用此功能的任何示例代码...
有没有人实际使用装饰上下文功能,如果有,它解决了什么用例?
PS:我正在寻找一种将图像装饰应用于对象标签的方法,并且根据对象的显示位置,基本图标大小会有所不同(例如,表和树项中的传统"小"图标和内容标题的较大图标).
应用于原始图标的装饰应相应地选择合适的尺寸装饰.
IDecorationContext 似乎符合我需要它的费用,但文档很少,因为人们可以从开源库的一个小功能中看到,并且没有找到示例.
谷歌搜索"IDecorationContext"也没有透露任何有趣的东西,所以我转向StackOverflow 众智,希望下一个得到问题的人能够更快地得到答案;)
我没有使用IDecorationContext,但你可以看到它用于org.eclipse.jface.viewers.LabelDecorator.
它也在这个帖子中讨论过(即使没有答案,至少可以给你一个起点)
我目前的方法是使用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) {
}
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
513 次 |
| 最近记录: |