package com.rjconsultores.ventaboletos.web.utilerias;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;

import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;

public abstract class EventListenerExecutarRelatorio<T extends MyGenericForwardComposer> implements EventListener {
	
	private T controller;
	
	public EventListenerExecutarRelatorio(T controller) {
		this.controller = controller;
	}

	@Override
	public void onEvent(Event arg0) throws Exception {
		if (filtrosValidos(controller)) {
			Relatorio relatorio = configuraRelatorio(controller);
			Map<Object, Object> args = new HashMap<Object, Object>();
			args.put("relatorio", relatorio);

			(controller).openWindow("/component/reportView.zul",
					Labels.getLabel(getTituloRelatorio()), args, MyGenericForwardComposer.MODAL);
		}
	}

	protected abstract boolean filtrosValidos(T controller);
	protected abstract Relatorio configuraRelatorio(T controller) throws SQLException;
	protected abstract String getTituloRelatorio();

	public T getController() {
		return controller;
	}

}
