通过IPluginContentWizard接口创建插件项目时,将eclipse插件设置为singleton

问题描述 投票:0回答:2

我正在开发一个实现org.eclipse.pde.ui.IPluginContentWizard接口的向导。因此,它作为插件项目模板添加到插件项目向导的末尾。所有文件都可以正常创建,但项目中有一个错误。插件未声明为扩展扩展点时必须使用的单例。

我如何在向导中执行此操作?我认为它需要在performFinish(IProject项目,IPluginModelBase模型,IProgressMonitor监视器)中完成,但项目和模型都没有给我这样做的可能性。

编辑:对于未来的读者:我的错误是,我没有通过API添加扩展,而是通过“手动”生成plugin.xml。这导致后台没有机制来完成他们的工作,因此没有设置singleton指令。

eclipse plugins wizard eclipse-pde
2个回答
0
投票

这种方式太长了,让我们使用更多的PDE API:

首先,定义模板部分

import org.eclipse.pde.ui.templates.OptionTemplateSection;

public class YourTemplateSection extends OptionTemplateSection {

    //implement abstract methods according your needs

    @Override
    protected void updateModel(IProgressMonitor monitor) throws CoreException {
        IPluginBase plugin = model.getPluginBase();

        //do what is needed

        plugin.add(extension);//here the "singleton" directive will be set

    }
}

然后使用带向导的部分

import org.eclipse.pde.ui.templates.ITemplateSection;
import org.eclipse.pde.ui.templates.NewPluginTemplateWizard;

public class YourContentWizard extends NewPluginTemplateWizard {

    @Override
    public ITemplateSection[] createTemplateSections() {
        return new ITemplateSection[] { new YourTemplateSection() };
    }

}

0
投票

如果一个人犯了同样的菜鸟错误,那么我,我想发布我的解决方案后我重新访问该项目后出现:

不要手动创建plugin.xml,使用插件模型的PDE API添加扩展。

org.eclipse.pde.ui.IPluginContentWizard实现的performFinish(...)方法中这样做:

try {
    IPluginExtension extension = model.getExtensions().getModel().getFactory().createExtension();
    extension.setPoint("org.eclipse.elk.core.layoutProviders");
    IPluginElement provider = model.getPluginFactory().createElement(extension);
    provider.setName("provider");
    provider.setAttribute("class", id + "." + algorithmName + "MetadataProvider");
            extension.add(provider);
    model.getExtensions().add(extension);
} catch (CoreException e) {
    e.printStackTrace();
}
© www.soinside.com 2019 - 2024. All rights reserved.