/**
 *  Copyright (c) 2015-2016 Angelo ZERR.
 *  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:
 *  Springrbua - initial implementation
 *
 */
package ts.eclipse.ide.angular2.internal.cli.wizards;

import org.eclipse.core.resources.IContainer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

import ts.eclipse.ide.angular2.cli.NgBlueprint;
import ts.eclipse.ide.angular2.internal.cli.AngularCLIMessages;
import ts.eclipse.ide.angular2.internal.cli.json.AngularCLIJson;

/**
 * Wizard page for Angular2 Module.
 *
 */
public class NewNgModuleWizardPage extends NgGenerateBlueprintWizardPage {

	private static final String PAGE_NAME = "ngModule";

	private Button chkRouting;
	private Button chkSpec;

	protected NewNgModuleWizardPage(IContainer folder) {
		super(PAGE_NAME, AngularCLIMessages.NewNgModuleWizardPage_title, null, NgBlueprint.MODULE, folder);
		super.setDescription(AngularCLIMessages.NewNgModuleWizardPage_description);
	}

	@Override
	public void createParamsControl(Composite parent) {
		super.createParamsControl(parent);
		Font font = parent.getFont();

		// params group
		Composite paramsGroup = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.marginWidth = 0;
		paramsGroup.setLayout(layout);
		paramsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
		paramsGroup.setFont(font);

		// Checkbox for routing
		chkRouting = new Button(paramsGroup, SWT.CHECK);
		chkRouting.addListener(SWT.Selection, this);
		chkRouting.setText(AngularCLIMessages.NewNgModuleWizardPage_routing);
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
		chkRouting.setLayoutData(data);

		// Checkbox for spec
		chkSpec = new Button(paramsGroup, SWT.CHECK);
		chkSpec.addListener(SWT.Selection, this);
		chkSpec.setText(AngularCLIMessages.NgGenerateBlueprintWizardPage_generate_spec);
		data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
		chkSpec.setLayoutData(data);
	}

	@Override
	protected void initializePage() {
		super.initializePage();
		chkSpec.setSelection(getAngularCLIJson().isSpec(NgBlueprint.MODULE));
	}

	@Override
	protected String[] getGeneratedFilesImpl() {
		AngularCLIJson cliJson = getAngularCLIJson();
		String name = getBlueprintName();
		int cnt = isSpec() ? 2 : 1;
		if (isRouting())
			cnt += 5;
		String[] files = new String[cnt];
		String folderName = cliJson.getFolderName(name);
		int i = 0;
		files[i++] = folderName.concat(cliJson.getModuleFileName(name));
		if (isSpec())
			files[i++] = folderName.concat(cliJson.getModuleSpecFileName(name));
		if (isRouting()) {
			files[i++] = folderName.concat(cliJson.getRoutingModuleFileName(name));
			files[i++] = folderName.concat(cliJson.getComponentTsFileName(name));
			files[i++] = folderName.concat(cliJson.getComponentSpecFileName(name));			// default spec setting seems to be ignored
			files[i++] = folderName.concat(cliJson.getComponentTemplateFileName(name));		// default "inline-template" seems to be ignored
			files[i++] = folderName.concat(cliJson.getComponentStyleFileName(name));		// default "inline-style" seems to be ignored
		}
		return files;
	}

	public boolean isRouting() {
		return chkRouting.getSelection();
	}

	public boolean isSpec() {
		return chkSpec.getSelection();
	}
}

@@ -2788,11 +2788,9 @@
 nt +
-= 5
++
 ;%0A%09%09
@@ -3060,18 +3060,16 @@
 uting())
- %7B
 %0A%09%09%09file
@@ -3140,458 +3140,8 @@
 ));%0A
-%09%09%09files%5Bi++%5D = folderName.concat(cliJson.getComponentTsFileName(name));%0A%09%09%09files%5Bi++%5D = folderName.concat(cliJson.getComponentSpecFileName(name));%09%09%09// default spec setting seems to be ignored%0A%09%09%09files%5Bi++%5D = folderName.concat(cliJson.getComponentTemplateFileName(name));%09%09// default %22inline-template%22 seems to be ignored%0A%09%09%09files%5Bi++%5D = folderName.concat(cliJson.getComponentStyleFileName(name));%09%09// default %22inline-style%22 seems to be ignored%0A%09%09%7D%0A
 %09%09re

Fix preview of generated files for module. See angelozerr/angular2-eclipse#49