/*
* HiberGUI Form
* Generated by HiberGUI generator.
*/
package zemplen.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import static hibergui.HiberGUI.*;

import zemplen.model.Reszido;
import zemplen.ui.AllomasForm;
import zemplen.model.Verseny;
import java.util.Set;
import java.util.HashSet;
import hibergui.Form;

import hibergui.assoc.O2MEdit_Button;


import hibergui.hibernate.HibernateForm;

import hibergui.property.StringEdit;



import zemplen.model.Allomas;

public class AllomasFormGenerated extends HibernateForm<Allomas>{
	
VersenyCombo eVerseny;
StringEdit eElnevezes;
O2MEdit_Button<Reszido> eReszidok;
		GridLayout gridLayout;		
		GridData data;			
		Composite cptFields;
		
	public AllomasFormGenerated (Composite cptParent, int mode){			
			super(cptParent, mode);
			setWindowTitle("Állomás");
		}
	
	@Override
	protected Composite createFields(Composite cptParent) {
			cptFields = new Composite(cptParent, SWT.BORDER);			
        	gridLayout = new GridLayout();
        	gridLayout.numColumns = 2;
        	cptFields.setLayout(gridLayout);
        	new Label(cptFields, SWT.NONE).setText("Verseny:");
eVerseny = new VersenyCombo(this, cptFields, NOT_NULL           			);
           	data = new GridData(GridData.FILL_HORIZONTAL);
           	eVerseny.setLayoutData(data);           	
        	new Label(cptFields, SWT.NONE).setText("Elnevezés: ");
eElnevezes = new StringEdit(this, cptFields, NOT_NULL, "elnevezes" , "elnevezés"           			);
           	data = new GridData(GridData.FILL_HORIZONTAL);
           	eElnevezes.setLayoutData(data);           	
eReszidok = new O2MEdit_Button<Reszido>(this, cptFields, NOT_NULL
, "reszidok" , "Részidők"           			)           			           				           			
           						
			{
			@Override
            protected Form<Reszido> createForm(Composite cpt, int style) {
				ReszidoForm f = new ReszidoForm(cpt, style);
//				f.eVerseny.set(eVerseny.get());
				f.fixVerseny(eVerseny.get());
				f.eAllomas.set(AllomasFormGenerated.this.get());
				f.eAllomas.fix(true);
				f.refresh();
				return f;
            }
        }; 
			           			
           	data = new GridData(GridData.FILL_HORIZONTAL);
           	eReszidok.setLayoutData(data);           	
           	return cptFields;
    }
    
    /*
    *	Programmer's code here
    */    
    
		@Override
    	protected void save(Allomas allomas) {
        	super.save(allomas);
        	Verseny v = eVerseny.get();
        	Set<Allomas> allomasok = v.getAllomasok();
        	if (allomasok == null)
        		v.setAllomasok(allomasok = new HashSet<Allomas>());
        	allomasok.add(allomas);
    	}
    
    	@Override
    	protected void delete(Allomas allomas) {
    		super.delete(allomas);
        	eVerseny.get().getAllomasok().remove(allomas);
    	}
		    
	
	@Override
    protected void createColumnsForTable() {
        addColumn(SWT.LEFT, "elnevezes", "Elnevezés", 200);
    }     
}	 