package info.bukova.isspst.filters;

import info.bukova.isspst.StringUtils;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;

@SuppressWarnings("serial")
public class BooleanFilterListbox extends Listbox
{
	class TristateBooleanListItem extends TristateBoolean
	{
		public TristateBooleanListItem(String text, int value)
		{
			this.setText(text);
			this.setValue(value);
		}

		private String text;

		public String getText()
		{
			return text;
		}

		public void setText(String text)
		{
			this.text = text;
		}
	}

	public BooleanFilterListbox()
	{
		super();

		List<TristateBooleanListItem> list = new ArrayList<TristateBooleanListItem>();
		list.add(new TristateBooleanListItem(StringUtils.localize("LabelAll"), TristateBoolean.NULL));
		list.add(new TristateBooleanListItem(StringUtils.localize("LabelNo"), TristateBoolean.FALSE));
		list.add(new TristateBooleanListItem(StringUtils.localize("LabelYes"), TristateBoolean.TRUE));

		for (int i = 0; i < list.size(); i++)
		{
			TristateBooleanListItem triStateItem = (TristateBooleanListItem) list.get(i);
			this.appendItem(triStateItem.getText(), "");

			Listitem item = this.getItemAtIndex(i);
			item.setValue((TristateBoolean) triStateItem);
		}

		this.setSelectedIndex(0);
		// this.setHflex("1");
		this.setMold("select");
	}
}
