/***
 * Excerpted from "Domain-Driven Design Using Naked Objects",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/dhnako for more book information.
***/
package com.pragprog.dhnako.carserv.wicket.ui;

import java.io.Serializable;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.FormComponent;

public class LabelAndFormComponent implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private final Label label;
	private final FormComponent formComponent;
	
	public LabelAndFormComponent(final FormComponent formComponent, final String labelStr) {
		this.label = newLabelForFormComponent(formComponent, labelStr);
		this.formComponent = formComponent;
	}

	public Label getLabel() {
		return label;
	}

	public FormComponent getFormComponent() {
		return formComponent;
	}

	private Label newLabelForFormComponent(FormComponent field, String labelStr) {
		return new Label(field.getId() + "Label", labelStr);
	}

	public void setVisible(boolean visible) {
		label.setVisible(visible);
		formComponent.setVisible(visible);
	}

	public void setEnabled(boolean enabled) {
		label.setEnabled(enabled);
		formComponent.setEnabled(enabled);
	}

}
