/******************************************************************************
 * TextRenderer.java - created by aaronz@vt.edu
 * 
 * Copyright (c) 2007 Virginia Polytechnic Institute and State University
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 * 
 * Contributors:
 * Aaron Zeckoski (aaronz@vt.edu) - primary
 * 
 *****************************************************************************/

package org.sakaiproject.evaluation.tool.renderers;

import java.util.HashMap;
import java.util.Map;

import org.sakaiproject.evaluation.model.EvalTemplateItem;
import org.sakaiproject.evaluation.model.constant.EvalConstants;

import uk.org.ponder.messageutil.MessageLocator;
import uk.org.ponder.rsf.components.UIBoundBoolean;
import uk.org.ponder.rsf.components.UIBranchContainer;
import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIInput;
import uk.org.ponder.rsf.components.UIJointContainer;
import uk.org.ponder.rsf.components.UIOutput;
import uk.org.ponder.rsf.components.UIVerbatim;
import uk.org.ponder.rsf.components.decorators.DecoratorList;
import uk.org.ponder.rsf.components.decorators.UIFreeAttributeDecorator;

/**
 * This handles the rendering of text type items
 * 
 * @author Aaron Zeckoski (aaronz@vt.edu)
 */
public class TextRenderer implements ItemRenderer {

	private MessageLocator messageLocator;
	public void setMessageLocator(MessageLocator messageLocator) {
		this.messageLocator = messageLocator;
	}

	/**
	 * This identifies the template component associated with this renderer
	 */
	public static final String COMPONENT_ID = "render-text-item:";

	/* (non-Javadoc)
	 * @see org.sakaiproject.evaluation.tool.renderers.ItemRenderer#renderItem(uk.org.ponder.rsf.components.UIContainer, java.lang.String, org.sakaiproject.evaluation.model.EvalTemplateItem, int, boolean)
	 */
	public UIJointContainer renderItem(UIContainer parent, String ID, String[] bindings, EvalTemplateItem templateItem, int displayNumber, boolean disabled) {
		UIJointContainer container = new UIJointContainer(parent, ID, COMPONENT_ID);

		UIOutput.make(container, "itemNum", displayNumber>0?displayNumber+"":"0" ); //$NON-NLS-1$
		UIVerbatim.make(container, "itemText", templateItem.getItem().getItemText()); //$NON-NLS-1$
		if ( templateItem.getUsesNA().booleanValue() ) {
			UIBranchContainer NAbranch = UIBranchContainer.make(container, "showNA:"); //$NON-NLS-1$
			UIBoundBoolean.make(NAbranch, "itemNA", templateItem.getUsesNA()); //$NON-NLS-1$
			UIOutput.make(NAbranch, "na-desc", messageLocator.getMessage("viewitem.na.desc")); //$NON-NLS-1$ //$NON-NLS-2$
		}

		UIInput textarea = UIInput.make(container, "essayBox", bindings[0]); //$NON-NLS-1$ //$NON-NLS-2$

		Map attrmap = new HashMap();
		attrmap.put("rows", templateItem.getDisplayRows().toString()); //$NON-NLS-1$
		if (disabled) {
			attrmap.put("disabled", "true"); //$NON-NLS-1$ //$NON-NLS-2$		
		}
		textarea.decorators = new DecoratorList( new UIFreeAttributeDecorator(attrmap) );

		return container;
	}

	/* (non-Javadoc)
	 * @see org.sakaiproject.evaluation.tool.renderers.ItemRenderer#getRenderType()
	 */
	public String getRenderType() {
		return EvalConstants.ITEM_TYPE_TEXT;
	}

}

@@ -2840,18 +2840,16 @@
 $%0D%0A%09%09%7D%0D%0A
-%0D%0A
 %09%09UIInpu
@@ -2858,17 +2858,55 @@
 textarea
- 
+;%0D%0A%09%09if(bindings != null)%7B%0D%0A%09%09%09textarea
 = UIInpu
@@ -2952,36 +2952,117 @@
 0%5D);
- //$NON-NLS-1$ //$NON-NLS-2$
+%0D%0A%09%09%7Delse%7B%0D%0A%09%09%09textarea = UIInput.make(container, %22essayBox%22,null,templateItem.getItem().getItemText());%0D%0A%09%09%7D
 %0D%0A%0D%0A

fix null-pointer exception in TextRender.java, which let PreviewItem, RemoveQuestion fails