package info.bukova.isspst.ui.renderers;

import org.zkoss.bind.impl.BindListitemRenderer;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;

@SuppressWarnings("serial")
public abstract class GenericListitemRenderer<T> extends BindListitemRenderer
{
	protected abstract void changeProperties(Listbox lb, Listitem li, int index, String varnm);

	protected T objectOfStates;

	public T getObjectOfStates()
	{
		return objectOfStates;
	}

	public void setObjectOfStates(T objectOfStates)
	{
		this.objectOfStates = objectOfStates;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void render(Listitem item, Object data, int index) throws Exception
	{
		this.objectOfStates = (T) data;

		super.render(item, data, index);
	}

	@Override
	protected void addItemReference(Component modelOwner, Component comp, int index, String varnm)
	{
		if (this.objectOfStates != null)
		{
			if (modelOwner != null && modelOwner instanceof Listbox)
			{
				if (comp != null && comp instanceof Listitem)
				{
					this.changeProperties((Listbox) modelOwner, (Listitem) comp, index, varnm);
				}
			}
		}

		super.addItemReference(modelOwner, comp, index, varnm);
	}
}
