bug 401928: add a way to choose the grammar in new project wizard.
diff --git a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/LuaProjectCreator.java b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/LuaProjectCreator.java
index 4d8fca1..4490cff 100644
--- a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/LuaProjectCreator.java
+++ b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/LuaProjectCreator.java
@@ -23,10 +23,12 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.dltk.core.DLTKCore;
 import org.eclipse.dltk.core.IBuildpathEntry;
 import org.eclipse.dltk.ui.wizards.ILocationGroup;
@@ -34,10 +36,13 @@
 import org.eclipse.dltk.ui.wizards.ProjectCreator;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.ldt.core.LuaConstants;
+import org.eclipse.ldt.core.internal.LuaLanguageToolkit;
+import org.eclipse.ldt.core.internal.PreferenceInitializer;
 import org.eclipse.ldt.core.internal.buildpath.LuaExecutionEnvironment;
 import org.eclipse.ldt.core.internal.buildpath.LuaExecutionEnvironmentBuildpathUtil;
 import org.eclipse.ldt.ui.internal.Activator;
 import org.eclipse.ldt.ui.wizards.pages.LuaProjectSettingsPage;
+import org.osgi.service.prefs.BackingStoreException;
 
 public class LuaProjectCreator extends ProjectCreator {
 
@@ -58,6 +63,10 @@
 		ProjectCreateStep createSourceFolderStep = createSourceFolderStep();
 		if (createSourceFolderStep != null)
 			addStep(IProjectCreateStep.KIND_FINISH, 0, createSourceFolderStep, (IWizardPage) locationGroup);
+
+		ProjectCreateStep setGrammarStep = createGrammaStep();
+		if (setGrammarStep != null)
+			addStep(IProjectCreateStep.KIND_FINISH, 0, setGrammarStep, (IWizardPage) locationGroup);
 	}
 
 	/**
@@ -123,6 +132,23 @@
 		return entries.toArray(new IBuildpathEntry[entries.size()]);
 	}
 
+	private class SetGrammarStep extends ProjectCreateStep {
+
+		@Override
+		public void execute(IProject project, IProgressMonitor monitor) throws CoreException, InterruptedException {
+			String grammar = luaProjectSettingPage.getGrammar();
+			try {
+				IEclipsePreferences node = new ProjectScope(project).getNode(LuaLanguageToolkit.getDefault().getPreferenceQualifier());
+				node.put(PreferenceInitializer.GRAMMAR_DEFAULT_ID, grammar);
+				node.flush();
+			} catch (BackingStoreException e) {
+				Activator.logError(MessageFormat.format("Unable store grammar version {0} for project {1}", grammar, project.getName()), e); //$NON-NLS-1$
+			}
+			monitor.done();
+		}
+
+	}
+
 	/**
 	 * Creates a default file named LuaWizardContants.DEFAULT_MAIN_FILE in default source folder.
 	 */
@@ -200,4 +226,8 @@
 	protected ProjectCreateStep createSourceFolderStep() {
 		return new CreateDefaultSourceFolderProjectCreateStep();
 	}
+
+	protected ProjectCreateStep createGrammaStep() {
+		return new SetGrammarStep();
+	}
 }
diff --git a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/GrammarGroup.java b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/GrammarGroup.java
new file mode 100644
index 0000000..5c6f99f
--- /dev/null
+++ b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/GrammarGroup.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Sierra Wireless and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Sierra Wireless - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ldt.ui.wizards.pages;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ldt.core.internal.LuaLanguageToolkit;
+import org.eclipse.ldt.core.internal.PreferenceInitializer;
+import org.eclipse.ldt.core.internal.grammar.LuaGrammarManager;
+import org.eclipse.ldt.ui.internal.grammar.GrammarContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+
+public class GrammarGroup {
+
+	private ComboViewer availableGrammarComboViewer;
+	private ISelection selection;
+
+	public GrammarGroup(final Composite parent) {
+		// Create group
+		final Group group = new Group(parent, SWT.NONE);
+		group.setText(Messages.GrammarGroup_group_name);
+		GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).applyTo(group);
+		GridLayoutFactory.swtDefaults().numColumns(1).applyTo(group);
+
+		// Grammar combo viewer
+		availableGrammarComboViewer = new ComboViewer(group, SWT.READ_ONLY | SWT.BORDER);
+		availableGrammarComboViewer.setContentProvider(new GrammarContentProvider());
+		GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(true, false).applyTo(availableGrammarComboViewer.getControl());
+
+		initializeGroup();
+	}
+
+	public String getSelectedGrammar() {
+		Display.getDefault().syncExec(new Runnable() {
+			public void run() {
+				if (availableGrammarComboViewer != null) {
+					selection = availableGrammarComboViewer.getSelection();
+				} else {
+					selection = null;
+				}
+			}
+		});
+
+		if (selection instanceof IStructuredSelection) {
+			Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+			if (firstElement instanceof String)
+				return (String) firstElement;
+		}
+
+		return null;
+	}
+
+	private void initializeGroup() {
+		if (availableGrammarComboViewer == null || availableGrammarComboViewer.getControl().isDisposed())
+			return;
+
+		// Refresh list
+		List<String> availableGrammars = LuaGrammarManager.getAvailableGrammars();
+		availableGrammarComboViewer.setInput(availableGrammars);
+
+		// Set default interpreter
+		String defaultGrammar = InstanceScope.INSTANCE.getNode(LuaLanguageToolkit.getDefault().getPreferenceQualifier()).get(
+				PreferenceInitializer.GRAMMAR_DEFAULT_ID, null);
+		availableGrammarComboViewer.setSelection(new StructuredSelection(defaultGrammar));
+	}
+}
diff --git a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/LuaProjectSettingsPage.java b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/LuaProjectSettingsPage.java
index 093655a..d27e9e3 100644
--- a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/LuaProjectSettingsPage.java
+++ b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/LuaProjectSettingsPage.java
@@ -27,6 +27,7 @@
 public class LuaProjectSettingsPage extends ProjectWizardFirstPage implements Observer {
 
 	private LuaExecutionEnvironmentGroup luaExecutionEnvironmentGroup;
+	private GrammarGroup grammarGroup;
 
 	public LuaProjectSettingsPage() {
 		setTitle(Messages.LuaProjecSettingsPageLabel);
@@ -55,11 +56,15 @@
 
 	protected void createCustomGroups(final Composite composite) {
 		luaExecutionEnvironmentGroup = createExecutionEnvironmentGroup(composite);
+		grammarGroup = createGrammarGroup(composite);
+	}
+
+	protected GrammarGroup createGrammarGroup(Composite composite) {
+		return new GrammarGroup(composite);
 	}
 
 	protected LuaExecutionEnvironmentGroup createExecutionEnvironmentGroup(final Composite composite) {
-		final LuaExecutionEnvironmentGroup eeGroup = new LuaExecutionEnvironmentGroup(composite);
-		return eeGroup;
+		return new LuaExecutionEnvironmentGroup(composite);
 	}
 
 	/**
@@ -79,6 +84,12 @@
 		return null;
 	}
 
+	public String getGrammar() {
+		if (grammarGroup != null)
+			return grammarGroup.getSelectedGrammar();
+		return null;
+	}
+
 	/**
 	 * 
 	 * @deprecated Use hasToCreateTemplate() instead.
diff --git a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/Messages.java b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/Messages.java
index bcdb882..dd87c6e 100644
--- a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/Messages.java
+++ b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/Messages.java
@@ -23,6 +23,8 @@
 	/** @since 1.2 */
 	public static String DocLuaFilePage_title;
 
+	public static String GrammarGroup_group_name;
+
 	/** @since 1.1 */
 	public static String LuaExecutionEnvironmentGroupTemplateLabel;
 
diff --git a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/messages.properties b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/messages.properties
index f36059b..00a8337 100644
--- a/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/messages.properties
+++ b/plugins/org.eclipse.ldt.ui/src/org/eclipse/ldt/ui/wizards/pages/messages.properties
@@ -10,6 +10,7 @@
 ###############################################################################
 DocLuaFilePage_description=Create a DocLua file. A DocLua file is a file describing an API to\nenable tooling, and will not be taken in account at runtime.
 DocLuaFilePage_title=DocLua File
+GrammarGroup_group_name=Target Grammar
 LuaExecutionEnvironmentGroupMainLabel=Create default template project ready to run.
 LuaExecutionEnvironmentGroupTemplateLabel=Create default template project ready to run.
 LuaExecutionEnvironmentGroupManageExecutionEnvironment=Configure Execution Environments...