package com.salsaw.msalsa;

import com.salsaw.msalsa.algorithm.TerminalGAPsStrategy;
import com.salsaw.msalsa.cli.SalsaParameters;
import com.salsaw.msalsa.cli.ScoringMatrix;
import com.vaadin.data.fieldgroup.FieldGroup;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.data.fieldgroup.PropertyId;
import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.TextField;

public class SalsaParametersForm extends CustomComponent {	
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@PropertyId("GOP")
    TextField GOPField = new TextField("GOP");
    
    @PropertyId("GEP")
    TextField GEPField = new TextField("GEP");
    
    @PropertyId("gamma")
    TextField gammaField = new TextField("Gamma");
    
    @PropertyId("scoringMatrix")
    ComboBox scoringMatrixField = new ComboBox("Scoring Matrix");
    
    @PropertyId("minIterations")
    TextField minIterationsField = new TextField("Min Matrix");
    
    @PropertyId("probabilityOfSplit")
    TextField probabilityOfSplitField = new TextField("Probability Of Split");
    
    @PropertyId("terminalGAPsStrategy")
    ComboBox terminalGAPsStrategyField = new ComboBox("Terminal GAPs Strategy");  
    
	public SalsaParametersForm(SalsaParameters salsaParameters) {		
        FormLayout formLayout = new FormLayout();
        scoringMatrixField.setNullSelectionAllowed(false);
        for(ScoringMatrix scoringMatrix : ScoringMatrix.values()) {
        	scoringMatrixField.addItem(scoringMatrix);
        }
        scoringMatrixField.setImmediate(true);
        formLayout.addComponent(scoringMatrixField);
        minIterationsField.setImmediate(true);       
        formLayout.addComponent(minIterationsField);        
        formLayout.addComponent(GOPField);
        formLayout.addComponent(GEPField);
        formLayout.addComponent(probabilityOfSplitField);
        formLayout.addComponent(gammaField);
        formLayout.addComponent(terminalGAPsStrategyField);
        terminalGAPsStrategyField.setNullSelectionAllowed(false);
        for(TerminalGAPsStrategy terminalGAPsStrategy : TerminalGAPsStrategy.values()) {
        	terminalGAPsStrategyField.addItem(terminalGAPsStrategy);
        }
        
        BeanItem<SalsaParameters> item = new BeanItem<SalsaParameters> (salsaParameters);
        FieldGroup binder = new FieldGroup(item);
        binder.bindMemberFields(this);
		
        formLayout.setSizeUndefined();
        
		Button button = new Button("Commit modifications");

		button.addClickListener(new Button.ClickListener() {
		    /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void buttonClick(ClickEvent event) {
		    	try {
					binder.commit();
				} catch (CommitException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		    }
		});
				
		formLayout.addComponent(button);
        
		setCompositionRoot(formLayout);
	}

}


@@ -1448,16 +1448,25 @@
 ersForm(
+BeanItem%3C
 SalsaPar
@@ -1472,16 +1472,17 @@
 rameters
+%3E
  salsaPa
@@ -1489,16 +1489,24 @@
 rameters
+BeanItem
 ) %7B%09%09%0D%0A 
@@ -2478,89 +2478,43 @@
     
-BeanItem%3CSalsaParameters%3E item = new BeanItem%3CSalsaParameters%3E (salsaParameters);
+// Data binding based on attributes
 %0D%0A  
@@ -2554,17 +2554,36 @@
 ldGroup(
-i
+salsaParametersBeanI
 tem);%0D%0A 
@@ -2730,18 +2730,16 @@
 ons%22);%0D%0A
-%0D%0A
 %09%09button

Use bean items for create binding inside SalsaParamtersForm