我开发了自己的 eclipse 插件,可以创建一个新的自定义向导。 在向导结束时,完成所有任务后,我想启动"导入 Maven 项目"向导。
例如,对于一个普通的项目,我可以做这样的事情
IWizard wizard = new ExternalProjectImportWizard(page1.getTxtPathLocation().getText());
WizardDialog dialog = new WizardDialog(getShell(), wizard);
dialog.open();
Maven 等效导入向导的类名是什么?
非常感谢。
类MavenImportWizard
:
org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizard
并且是 M2E 插件的一部分。
如何通过Google/grepcode找到它
谷歌
grepcode import existing maven project
将您引导至 plugin.properties,其中您会看到以下行:m2.wizard.import.description = Import Existing Maven Projects
在 grepcode 的同一项目中,您会看到插件.xml其中包含类名的代码片段:
<wizard id="org.eclipse.m2e.core.wizards.Maven2ImportWizard" class="org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizard" icon="icons/import_m2_project.gif" category="org.eclipse.m2e" name="%m2.wizard.import.name"> <description>%m2.wizard.import.description</description> </wizard>
如何以通用方式实例化导入向导
正如 Greg 指出的那样,该类internal
包中,不应直接使用。相反,您应该使用 Eclipse API 按向导描述符的 id 获取向导描述符,然后使用该描述符实例化向导。您将在插件中找到向导描述符 id.xml(见上文)。在你的情况下org.eclipse.m2e.core.wizards.Maven2ImportWizard
。
以下是完成任务的代码片段:
final String MAVEN_IMPORT_WIZARD_ID =
"org.eclipse.m2e.core.wizards.Maven2ImportWizard";
final IWizardDescriptor mavenImportWizardDescriptor =
PlatformUI
.getWorkbench()
.getImportWizardRegistry()
.findWizard(MAVEN_IMPORT_WIZARD_ID);
if (mavenImportWizardDescriptor != null) {
final IWizard mavenImportWizard = mavenImportWizardDescriptor.createWizard();
final WizardDialog mavenImportWizardDialog = new WizardDialog(getShell(), mavenImportWizard);
mavenImportWizardDialog.open();
}
else {
// Wizard not found - e.g. if m2e is not installed.
// Notify user.
}
另请参阅:
http://www.programcreek.com/java-api-examples/index.php?api=org.eclipse.jface.wizard.IWizard
http://blog.resheim.net/2010/07/invoking-eclipse-wizard.html