如何使用 Eclipse JFace 中的 IDecorationContext api

发布于 2024-08-16 21:24:49 字数 511 浏览 3 评论 0原文

是否有使用 IDecerationContext 进行标签装饰的示例?

从表面上看, IDecationContext 类似乎提供了某种上下文装饰支持,但在我的一生中,我找不到任何使用此功能的示例代码...

有人真正使用过装饰吗上下文功能,如果有,它解决了哪些用例?


PS:我正在寻找一种将图像装饰应用于对象标签的方法,并且根据对象的显示位置,基本图标大小会有所不同(例如,表和树项目中的传统“小”图标以及内容标题的图标更大)。

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

IDecerationContext 似乎符合我的需要,但文档非常稀疏,就像人们对开源库的一个小功能所期望的那样,并且没有找到任何示例。

谷歌搜索“IDecorationContext”也没有发现任何有趣的东西,所以我转向 StackOverflow 群众智慧,希望下一个得到问题的人能够更快地得到答案;)

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 ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请你别敷衍 2024-08-23 21:24:49

我没有使用 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) {
         }
      }
   }

   ...
}

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) {
         }
      }
   }

   ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文