package zemplen.ui;

import hibergui.Form;
import hibergui.hibernate.HibernateM2OEdit_Combo;

import org.eclipse.swt.widgets.Composite;
import org.hibernate.Criteria;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import zemplen.model.Kategoria;
import zemplen.model.Verseny;

public class KategoriaCombo extends HibernateM2OEdit_Combo<Kategoria> {
	
	private Verseny verseny;
	
    public KategoriaCombo(Form form, Composite cptParent, int style) {
		super(form, cptParent, style, "kategoria", "kategória", "elnevezes");

		btnAssoc.setText("Kategóriák");
	}
    
	public void fixVerseny(Verseny verseny) {
    	this.verseny = verseny;
    	refresh();
    }
    
	@Override
    protected Form<Kategoria> createForm(Composite cptParent, int style) {
    	KategoriaForm f = new KategoriaForm(cptParent, style);
    	f.eVerseny.set(verseny);
		f.eVerseny.fix(true);
    	return f;
    }

	@Override
	protected Criteria createCriteria() {
		return super.createCriteria().add(Restrictions.eq("verseny", verseny));
	}
	
	@Override
	public Example createExample(Kategoria sample) {
		return Example.create(sample).
		ignoreCase().
		enableLike(MatchMode.ANYWHERE);
	}
}
