如何从Eclipse JFace中使用IDecorationContext api [英] How would one use IDecorationContext api from Eclipse JFace

查看:123
本文介绍了如何从Eclipse JFace中使用IDecorationContext api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有使用 IDecorationContext 标签装饰的例子?



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



有没有人实际使用了装饰上下文功能,如果是,那么它解决了什么用例?





$ b $ PS:我正在寻找一种将图像装饰应用于对象标签的方式,并且根据对象的显示位置,基本图标大小会有所不同(例如,表格中的传统小图标,



应用于原始图标的装饰品应相应选择适当的尺寸装饰。



IDecorationContext 似乎符合我需要的帐单,但是文档是稀疏的,可以期望从一个小的fea一个开源的图书馆,没有任何的例子可以被发现。



IDecorationContext的Googling没有显示任何有趣的东西,所以我转向StackOverflow人群的智慧,希望下一个获得问题的人能够更快地得到他们的答案;)

解决方案

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



还在此线程(即使没有答案,至少可以给你一个起点)



我目前的方法是使用
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){
}
}
}

...
}


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 a ILightweightLabelDecorator to add a replace overlay to the respective icons:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆