如何以编程方式从eclipse插件调用importwizard

时间:2018-01-18 12:32:29

标签: eclipse eclipse-rcp

我需要以编程方式从eclipse插件项目中调用eclipse importwizard。我按照这个例子,似乎不行 https://resheim.net/2010/07/invoking-eclipse-wizard.html

然后在我的代码中,它显示向导数组为空,我是否需要注册importwizard?怎么样?

var file = new FileInfo(fileName);

Console.WriteLine("Bytes before: " + file.Length);

var optimizer = new ImageOptimizer();
optimizer.Compress(file);

file.Refresh();
Console.WriteLine("Bytes after:  " + file.Length);

2 个答案:

答案 0 :(得分:1)

导入对话框不使用“主要”向导。您需要知道要使用的向导的ID,并调用向导注册表findWizard方法。

“导入项目”向导ID为org.eclipse.ui.wizards.import.ExternalProject,因此代码如下所示:

String id = "org.eclipse.ui.wizards.import.ExternalProject"
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(id);
IWizard wizard = descriptor.createWizard();
WizardDialog wd = new WizardDialog(display.getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();

答案 1 :(得分:0)

private void openProject(String projectfolder)抛出CoreException {         // TODO:检查项目是否已创建并打开,如果是,则不执行任何操作或仅刷新

    IProjectDescription description = null;
    IProject project = null;
    description = ResourcesPlugin.getWorkspace().loadProjectDescription(
            new Path(new File(projectfolder).getAbsolutePath()
                    + "/.project"));
    project = ResourcesPlugin.getWorkspace().getRoot()
            .getProject(description.getName());
    project.create(description, null);

    project.open(null);

}