package org.openoffice.odf.doc.element.table;

import java.util.List;
import org.openoffice.odf.doc.OdfFileDom;
import org.openoffice.odf.doc.element.text.OdfParagraph;
import org.openoffice.odf.doc.element.text.OdfParagraphExtra;
import org.openoffice.odf.dom.type.office.OdfValueType;

public class OdfTableRowExtra extends OdfTableRow
{
	OdfFileDom owner;
	/**
	 * Construct an OdfTableExtra from owner document.
	 * @param _aOwnerDoc the owner document DOM
	 */
	public OdfTableRowExtra( OdfFileDom _aOwnerDoc)
	{
		super(_aOwnerDoc);
		owner = _aOwnerDoc;
	}
	
	/**
	 * Populate a row with strings.
	 * If the <code>cellStyleList</code> or
	 * <code>paraStyleList</code> is shorter than the <code>stringList</code>,
	 * the values will be recycled. Thus, if you want all the cells to have
	 * the same cell style, just put one item in <code>cellStyleList</code>.
	 * @param valueList a <code>List&lt;String&gt;</code> containing
	 * cell values.
	 * @param cellStyleList a <code>List&lt;String&gt;</code> containing
	 * cell style names.
	 * @param paraStyleList a <code>List&lt;String&gt;</code> containing
	 * paragraph style names.
	 */
	public void populateStrings(List<String> valueList,
		List<String> cellStyleList,	List<String> paraStyleList)
	{
		int cellIndex = 0;
		int paraIndex = 0;
		OdfTableCell cell;
		OdfParagraph para;

		for (String value : valueList)
		{
			cell = new OdfTableCell(owner);
			cell.setStyleName(cellStyleList.get(cellIndex));
			cell.setStringValue(value);
			cell.setValueType(OdfValueType.STRING);
			para = new OdfParagraphExtra(owner, value,
				paraStyleList.get(paraIndex));
			cell.appendChild(para);
			this.appendCell(cell);
			
			/* advance style indices, wrapping around if necessary */
			cellIndex = (cellIndex + 1) % cellStyleList.size();
			paraIndex = (paraIndex + 1) % paraStyleList.size();
		}
	}
			
}
