/*
 * Perfclispe
 * 
 * 
 * Copyright (c) 2013 Jakub Knetl
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.perfclipse.ui.wizards;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.perfclipse.reflect.PerfCakeComponents;
import org.slf4j.LoggerFactory;

public class GeneratorPage extends PerfCakePage {
	
	final static org.slf4j.Logger log = LoggerFactory.getLogger(GeneratorPage.class);
	
	private Composite container;
	private Label generatorLabel;
	private Combo generatorCombo;
	
	public GeneratorPage(){
		this("Scenario genarator and sender");
	}
	
	public GeneratorPage(String pageName) {
		super(pageName);
		setTitle("Generator and sender");
		setDescription("Fill in neccessary information on this page");
	}

	@Override
	public void createControl(Composite parent) {
		//TODO : gridData constructor with FILL_HORIZONTAL is deprecated
		container = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.horizontalSpacing = 10;
		layout.verticalSpacing = 10;
		container.setLayout(layout);
		
		PerfCakeComponents components = getPerfCakeComponents();

		generatorLabel = new Label(container, SWT.NONE);
		generatorLabel.setText("Choose generator");
		generatorCombo = new Combo(container, SWT.NONE);
		if (components != null && components.getGenerators() != null){
			for (Class<?> clazz : components.getGenerators()){
				generatorCombo.add(clazz.getSimpleName());
			}
		}
		generatorCombo.addSelectionListener(new SelectionAdapter() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				updateControls();
			}
		});
		
		GridData gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
		generatorCombo.setLayoutData(gridData);
		
		setControl(container);
		setPageComplete(false);
	}
	
	@Override
	protected void updateControls() {
		if (generatorCombo.getText() == null || "".equals(generatorCombo.getText())){
			setDescription("Select generator type!");
			setPageComplete(false);
		}else{
			setDescription("Complete!");
			setPageComplete(true);
		}
	}

	public String getGeneratorName(){
		return generatorCombo.getText();
	}
}

@@ -973,16 +973,56 @@
 .Label;%0A
+import org.eclipse.swt.widgets.Spinner;%0A
 import o
@@ -1063,16 +1063,16 @@
 onents;%0A
-
 import o
@@ -1263,16 +1263,17 @@
 tainer;%0A
+%0A
 %09private
@@ -1325,16 +1325,130 @@
 orCombo;
+%0A%0A%09private Spinner threadsSpinner;%0A%09private Label threadsLabel;%0A%0A%09private Label runLabel;%0A%09private Combo runCombo;
 %0A%09%0A%09publ
@@ -1590,35 +1590,24 @@
 e(%22Generator
- and sender
 %22);%0A%09%09setDes
@@ -2557,28 +2557,37 @@
 %09%0A%09%09
-GridData grid
+generatorCombo.setLayout
 Data
- = 
+(
 new 
@@ -2646,49 +2646,450 @@
 lse)
+)
 ;%0A%09%09
-generatorCombo.setLayoutData(gridData
+%0A%09%09threadsLabel = new Label(container, SWT.NONE);%0A%09%09threadsLabel.setText(%22Number of threads: %22);%0A%0A%09%09threadsSpinner = new Spinner(container, SWT.NONE);%0A%09%09//TODO: set size of spinner%0A%09%09%0A%09%09runLabel = new Label(container, SWT.NONE);%0A%09%09runLabel.setText(%22Run type: %22);%0A%09%09%0A%09%09runCombo = new Combo(container, SWT.NONE);%0A%0A%09%09//TODO: read possible values from perfcake%0A%09%09runCombo.add(%22iteration%22);%0A%09%09runCombo.add(%22time%22);%0A%09%09runCombo.add(%22percentage%22
 );%0A%09

Add controls to Generator page