/*
 * Genres.java, 10 sept. 2005
 * 
 * This file is part of FilmZ.
 *
 * Copyright © 2005 Johan Cwiklinski
 *
 * File :               Genres.java
 * Author's email :     johan@x-tnd.be
 * Author's Website :   http://www.x-tnd.be/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 */

package be.xtnd.films.gui;

import be.xtnd.films.Genre;
import be.xtnd.gui.FilmzMain;
import be.xtnd.gui.Menus;


/** 
 * @author Johan Cwiklinski
 * @version 1.0
 */
public class Genres extends SimpleObjectWindow{
	/** Nom de la fenêtre de la liste des genres */
	public static final String LIST_NAME = "liste_genres";
	/** Nom de la fenêtre d'ajout de genre */ 
	public static final String NEW_NAME = "nouveau_genre";
	/** Nom de la fenêtre de modification de genre */ 
	public static final String MODIF_NAME = "modifie_genre_";

	/** Constructeur par défaut */
	public Genres(){
		super("types", Menus.TYPES_IMAGE, LIST_NAME, MODIF_NAME, NEW_NAME, FilmzMain.collection.isPrive()?Genre.RLIST_QUERY:Genre.LIST_QUERY);
	}
	
	protected void initObject(Integer id){
		if(id==null){
			object = new Genre();
		}else{
			object = new Genre(id);
		}
	}
	
	protected void ajout(Integer id){
		af.film.ajouteGenre(new Genre(id));
	}
	
	/**
	 * Construit la requête de recherche 
	 * @return requête
	 */
	public String constructQuery(){
		String table = FilmzMain.collection.isPrive()?Genre.RTABLE:Genre.TABLE;
		StringBuffer sb = new StringBuffer("SELECT "+Genre.PK+", "+Genre.VALUE+" FROM "+table);
		if(!textfield.getText().trim().equals("")){
			sb.append(" WHERE "+Genre.VALUE+" LIKE '%"+textfield.getText()+"%'");
		}
		String qry = new String();
		qry = sb.toString();
		return qry;
	}
}
