package org.gemoc.execution.sequential.javaxdsml.ide.ui.templates;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.xtext.util.Strings;

import fr.inria.diverse.commons.eclipse.pde.wizards.pages.pde.ui.BaseProjectWizardFields;
import fr.inria.diverse.commons.eclipse.pde.wizards.pages.pde.ui.templates.ITemplateSection;
import fr.inria.diverse.melange.ui.templates.melange.SimpleMTNewWizard;

public class SequentialNewWizard extends SimpleMTNewWizard{

	@Override
	public void init(BaseProjectWizardFields data) {
		super.init(data);
		setWindowTitle("Simple sequential GEMOC project");
	}
	
	@Override
	public ITemplateSection[] createTemplateSections() {
		return new ITemplateSection[] {new SequentialTemplate()};
	}
	
	@Override
	public IWizardPage getNextPage(IWizardPage page) {
		
		try {
			String project = getData().projectName;
			String SUFFIX = ".xdsml";
			if(project.endsWith(SUFFIX)){
				
				int startSuffix = project.length() - SUFFIX.length();
				int startName = project.lastIndexOf(".", startSuffix-1) + 1;
				
				String packageName = project.substring(0, startName - 1).toLowerCase();
				String languageName = project.substring(startName, startSuffix);
				languageName = Strings.toFirstUpper(languageName);

				ITemplateSection[] selections = getTemplateSections();
				SequentialTemplate selection = (SequentialTemplate) selections[0];
				selection.updateOptions(packageName, languageName);
			}
		} catch (Exception e) {}
	
		return super.getNextPage(page);
	}
}

@@ -65,53 +65,8 @@
 s;%0A%0A
-import org.eclipse.jface.wizard.IWizardPage;%0A
 impo
@@ -556,206 +556,8 @@
 %22);%0A
-%09%7D%0A%09%0A%09@Override%0A%09public ITemplateSection%5B%5D createTemplateSections() %7B%0A%09%09return new ITemplateSection%5B%5D %7Bnew SequentialTemplate()%7D;%0A%09%7D%0A%09%0A%09@Override%0A%09public IWizardPage getNextPage(IWizardPage page) %7B%0A
 %09%09%0A%09
@@ -1225,41 +1225,135 @@
 %7B%7D%0A%09
+%7D
 %0A%09
-%09return super.getNextPage(page)
+%0A%09@Override%0A%09public ITemplateSection%5B%5D createTemplateSections() %7B%0A%09%09return new ITemplateSection%5B%5D %7Bnew SequentialTemplate()%7D
 ;%0A%09%7D

Fix New project wizard: set default values at the init