/*
 * Created on Aug 11, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package zemplen.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import static hibergui.HiberGUI.*;

import hibergui.Form;
import hibergui.assoc.O2MEdit_Button;
import hibergui.hibernate.HibernateForm;
import hibergui.property.DateEdit;
import hibergui.property.StringEdit;

import zemplen.model.Allomas;
import zemplen.model.Kategoria;
import zemplen.model.Nevezes;
import zemplen.model.Tav;
import zemplen.model.Verseny;

/**
 * @author espakm
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class VersenyForm extends HibernateForm<Verseny> {
    
    StringEdit eElnevezes;
    StringEdit eHelyszin;
    DateEdit eIdopont;
    O2MEdit_Button<Tav> eTavok;
    O2MEdit_Button<Allomas> eAllomasok;
    O2MEdit_Button<Kategoria> eKategoriak;
    O2MEdit_Button<Nevezes> eNevezesek;
    
    public VersenyForm(Composite cptParent, int mode) {
        super(cptParent, mode);
        
        setWindowTitle("Versenyek");
    }
    
    @Override
    protected Composite createFields(Composite cptParent) {
        final Composite cptFields = new Composite(cptParent, SWT.BORDER);
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        cptFields.setLayout(gridLayout);
        
        GridData 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);
        
        new Label(cptFields, SWT.NONE).setText("Helyszín:");
        eHelyszin = new StringEdit(this, cptFields, NOT_NULL, "helyszin", "helyszín");
        data = new GridData(GridData.FILL_HORIZONTAL);
        eHelyszin.setLayoutData(data);
        
        new Label(cptFields, SWT.NONE).setText("Időpont:");
        
        eIdopont = new DateEdit(this, cptFields, NONE, "idopont", "időpont");
        data = new GridData(GridData.FILL_HORIZONTAL);
        eIdopont.setLayoutData(data);
        
        Composite cptRelations = new Composite(cptFields, SWT.NONE);
        data = new GridData();
        data.horizontalSpan = 2;
        data.horizontalAlignment = GridData.FILL;
        cptRelations.setLayoutData(data);
        
        RowLayout rowLayout = new RowLayout();
        rowLayout.pack = false;
        rowLayout.justify = true;
        cptRelations.setLayout(rowLayout);
        
        eTavok = new O2MEdit_Button<Tav>(this, cptRelations, NONE, "tavok", "Távok") {
			@Override
			protected Form<Tav> createForm(Composite cpt, int formStyle) {
				TavForm f = new TavForm(cpt, formStyle);
				f.eVerseny.set(VersenyForm.this.get());
				f.eVerseny.fix(true);
				return f;
			}
        };
        
        eAllomasok = new O2MEdit_Button<Allomas>(this, cptRelations, NONE, "allomasok", "Állomások") {
			@Override
			protected Form<Allomas> createForm(Composite cpt, int formStyle) {
				AllomasForm f = new AllomasForm(cpt, formStyle);
				f.eVerseny.set(VersenyForm.this.get());
				f.eVerseny.fix(true);
				return f;
			}
        };
        
        eKategoriak = new O2MEdit_Button<Kategoria>(this, cptRelations, NONE, "kategoriak", "Kategóriák") {
			@Override
			protected Form<Kategoria> createForm(Composite cpt, int formStyle) {
				KategoriaForm f = new KategoriaForm(cpt, formStyle);
				f.eVerseny.set(VersenyForm.this.get());
				f.eVerseny.fix(true);
				return f;
			}
        };
        
        eNevezesek = new O2MEdit_Button<Nevezes>(this, cptRelations, NONE, "nevezesek", "Nevezések") {
			@Override
			protected Form<Nevezes> createForm(Composite cpt, int formStyle) {
				NevezesForm f = new NevezesForm(cpt, formStyle);
				f.eVerseny.set(VersenyForm.this.get());
				f.eVerseny.fix(true);
				return f;
			}
        };
        
        return cptFields;
    }

    @Override
    protected void createColumnsForTable() {
        addColumn(SWT.LEFT, "elnevezes", "Elnevezés", 200);
        addColumn(SWT.LEFT, "helyszin", "Helyszín", 120);
        addColumn(SWT.LEFT, "idopont", "Időpont", 120);
    }
}
