/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.utilerias.render;

import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Button;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

import com.rjconsultores.ventaboletos.entidad.PerfilFuncion;

/**
 * 
 * @author Bruno Neves
 */
public class RenderPermisoSelecionados implements ListitemRenderer {

	private EventListener listenerGenerico;

	public RenderPermisoSelecionados(EventListener listenerGenerico) {
		super();
		this.listenerGenerico = listenerGenerico;
	}

	public void render(Listitem lstm, Object o) throws Exception {
		PerfilFuncion permiso = (PerfilFuncion) o;

		Checkbox chkRead = new Checkbox();
		chkRead.setDisabled(Boolean.TRUE);
		Checkbox chkWrite = new Checkbox();
		chkWrite.setDisabled(Boolean.TRUE);
		

		Listcell lc = new Listcell(permiso.getFuncionSistema().toString());
		lc.setParent(lstm);

		lc = new Listcell();

		boolean indLectura = permiso.getIndLectura() == null ? true : permiso.getIndLectura();
		if (indLectura) {
			chkRead.setChecked(Boolean.TRUE);
		}
		lc.appendChild(chkRead);
		lc.setParent(lstm);

		lc = new Listcell();

		if (!indLectura) {
			chkWrite.setChecked(Boolean.TRUE);
		}
		lc.appendChild(chkWrite);
		lc.setParent(lstm);

		lc = new Listcell();
		
		Button btnRemoverPermissao = new Button();
		btnRemoverPermissao.setAttribute("data", o);
		btnRemoverPermissao.addEventListener("onClick",listenerGenerico);
		btnRemoverPermissao.setImage("/gui/img/remove.png");
		lc.appendChild(btnRemoverPermissao);
		
		lc.setParent(lstm);
		

		lstm.setAttribute("data", permiso);
	}
}
