【问题标题】:How to create custom image decorator in java file using eclipse plugin如何使用eclipse插件在java文件中创建自定义图像装饰器
【发布时间】:2014-10-15 18:23:42
【问题描述】:

我想在我的 Eclipse 插件中使用一些装饰器。我创建了一个插件,在其中为自己的 .test 文件创建了自己的编辑器。如果用户编辑 .test 文件并保存它。该文件必须显示一些装饰,不仅是 .test 文件,而且项目也必须显示装饰器。我被这个问题困住了,我找不到任何好的教程来创建装饰器。

我看过一些像https://www.eclipse.org/articles/Article-Decorators/decorators.html 这样的网站,但我无法理解确切的意思。

请有人告诉我如何为我的 Eclipse 插件创建自定义装饰器。

【问题讨论】:

    标签: eclipse eclipse-rcp eclipse-plugin eclipse-pde


    【解决方案1】:

    ILightweightLabelDecorator 是最常见的装饰器类型

    在你的 plugin.xml 中声明,如下所示:

    <extension point="org.eclipse.ui.decorators"> 
        <decorator
            id="my.decorator.id" 
            class="my.decorator.Decorator" 
            label="My Decorator" 
            state="true" 
            lightweight="true" 
            adaptable="true"> 
            <enablement>
                <objectClass name="org.eclipse.core.resources.IResource"/> 
            </enablement>
        </decorator>
    </extension>
    

    您必须调整启用以适合您的需求。

    你的装饰器类应该是这样的:

    public class Decorator extends BaseLabelDecorator implements ILightweightLabelDecorator
    {
      @Override
      public void decorate(final Object element, final IDecoration decoration)
      {
        // TODO call decoration methods to add overlay images or prefix / suffix text
      }
    }
    

    【讨论】:

    • 但是,如何检查文件是否为 .test 文件,然后应用装饰器?在哪里进行这项检查?
    • @VarunRaval 您查看传递给decorate 方法的element 对象。如果您需要更多详细信息,请提出新问题。
    • 元素对象仅代表文件还是其他?以及如何获取该文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    相关资源
    最近更新 更多