Created
July 30, 2015 11:55
-
-
Save lschuetze/0ce263faf165756b34cf to your computer and use it in GitHub Desktop.
Add Xtext nature to Eclipse Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another option is to
@Inject ToggleXtextNatureAction helper
withhelper.toggleNature(project)