package to.etc.domui.dom.html;

/**
 * A THEAD node.
 *
 * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
 * Created on Jun 2, 2008
 */
public class THead extends NodeContainer {
	public THead() {
		super("thead");
	}

	@Override
	public void visit(INodeVisitor v) throws Exception {
		v.visitTHead(this);
	}

	public void setHeaders(String... labels) {
		forceRebuild();
		TR row = new TR();
		add(row);
		for(String s : labels) {
			TH th = new TH();
			row.add(th);
			th.setText(s);
		}
	}

	private TR getRow() {
		for(int i = getChildCount(); --i >= 0;) {
			NodeBase b = getChild(i);
			if(b instanceof TR)
				return (TR) b;
		}
		TR tr = new TR();
		add(tr);
		return tr;
	}

	public TH addHeader(String text) {
		TR tr = getRow();
		TH th = new TH();
		tr.add(th);
		th.setText(text);
		return th;
	}
}

package to.etc.domui.dom.html;

import to.etc.webapp.nls.*;

/**
 * A THEAD node.
 *
 * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
 * Created on Jun 2, 2008
 */
public class THead extends NodeContainer {
	public THead() {
		super("thead");
	}

	@Override
	public void visit(INodeVisitor v) throws Exception {
		v.visitTHead(this);
	}

	public void setHeaders(String... labels) {
		forceRebuild();
		TR row = new TR();
		add(row);
		for(String s : labels) {
			TH th = new TH();
			row.add(th);
			th.setText(s);
		}
	}

	public void setHeaders(BundleRef b, String... keys) {
		forceRebuild();
		TR row = new TR();
		add(row);
		for(String s : keys) {
			TH th = new TH();
			row.add(th);
			th.setText(b.getString(s));
		}
	}

	private TR getRow() {
		for(int i = getChildCount(); --i >= 0;) {
			NodeBase b = getChild(i);
			if(b instanceof TR)
				return (TR) b;
		}
		TR tr = new TR();
		add(tr);
		return tr;
	}

	public TH addHeader(String text) {
		TR tr = getRow();
		TH th = new TH();
		tr.add(th);
		th.setText(text);
		return th;
	}
}

Add setHeadings using a bundle to THead