
package com.rjconsultores.ventaboletos.web.utilerias;

import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.event.CheckEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Checkbox;

public class MyCheckboxSiNo extends Checkbox {

	private static final long serialVersionUID = 1L;

	public MyCheckboxSiNo() {
		initialize();
	}

	private void initialize() {
		setLabelValue(this.isChecked());
		this.addEventListener(Events.ON_CHECK, new EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				CheckEvent checkEvent = (CheckEvent) event;
				setLabelValue(checkEvent.isChecked());
			}
		});
	}

	@Override
	public void setChecked(boolean checked) {
		super.setChecked(checked);
		setLabelValue(checked);
	}

	@Override
	public void setLabel(String label) {
		super.setLabel(label);
	}

	private void setLabelValue(boolean checked) {
		if (checked) {
			setLabel(Labels.getLabel("MSG.SI"));
		} else {
			setLabel(Labels.getLabel("MSG.NO"));
		}
	}

}
