import org.eclipse.core.resources.IProject; //导入方法依赖的package包/类
protected void createNewXTextProject() {
/*
* MessageDialog.openWarning(
* PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
* "Gemoc Language Workbench UI",
* "Action not completly implemented yet");
*/
// create xtext project from existing ecore model
// wizard id =
// org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.NewXtextProjectFromEcoreWizard
// launch the appropriate wizard
IWizardDescriptor descriptor = WizardFinder
.findNewWizardDescriptor("org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.NewXtextProjectFromEcoreWizard");
// Then if we have a wizard, open it.
if (descriptor != null) {
// add a listener to capture the creation of the resulting project
NewProjectWorkspaceListener workspaceListener = new NewProjectWorkspaceListener();
ResourcesPlugin.getWorkspace().addResourceChangeListener(
workspaceListener);
try {
IWizard wizard;
wizard = descriptor.createWizard();
// this wizard need some dedicated initialization
// ((EcoreModelerWizard )wizard).init(PlatformUI.getWorkbench(),
// (IStructuredSelection)
// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection());
// ((EcoreModelWizard)wizard).init(PlatformUI.getWorkbench(),
// (IStructuredSelection) selection);
WizardDialog wd = new WizardDialog(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell(), wizard);
wd.create();
wd.setTitle(wizard.getWindowTitle());
int res = wd.open();
if (res == WizardDialog.OK) {
ResourcesPlugin.getWorkspace()
.removeResourceChangeListener(workspaceListener);
ArrayList newlyCreatedProjects = workspaceListener
.getNewlyCreatedProjects();
// find the created project with xtext files in it
FileFinderVisitor fileFinder = new FileFinderVisitor(
"xtext");
for (Iterator iterator = newlyCreatedProjects
.iterator(); iterator.hasNext();) {
IProject iProject = (IProject) iterator.next();
iProject.accept(fileFinder);
if (fileFinder.getFile() != null) {
createdProject = iProject;
break;
}
}
// update the project configuration model
if (createdProject != null) {
// maybe we should do something in the melange file ?
} else {
Activator
.error("not able to detect which project was created by wizard",
null);
}
}
} catch (CoreException e) {
Activator.error(e.getMessage(), e);
} finally {
// make sure to remove listener in all situations
ResourcesPlugin.getWorkspace().removeResourceChangeListener(
workspaceListener);
}
} else {
Activator
.error("wizard with id=org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.NewXtextProjectFromEcoreWizard not found",
null);
}
}