Skip to content

Instantly share code, notes, and snippets.

@lschuetze
Created July 30, 2015 11:55
Show Gist options
  • Save lschuetze/0ce263faf165756b34cf to your computer and use it in GitHub Desktop.
Save lschuetze/0ce263faf165756b34cf to your computer and use it in GitHub Desktop.
Add Xtext nature to Eclipse Project
public static void addNature(IProject project) throws CoreException {
if (!project.hasNature("org.eclipse.xtext.ui.shared.xtextNature")) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = "org.eclipse.xtext.ui.shared.xtextNature";
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
public IProject getProjectHandle() {
return ResourcesPlugin.getWorkspace().getRoot().getProject(
getProjectName());
}
/*
....
*/
IProject project = firstPage.getProjectHandle();
try {
project.create(null);
project.open(null);
SlrProjectSupport.addNature(project);
} catch (CoreException e) {
e.printStackTrace();
}
@szarnekow
Copy link

Another option is to @Inject ToggleXtextNatureAction helper with helper.toggleNature(project)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment