/**
 * 
 */
package uk.ac.ucl.excites.sapelli.collector.ui.fields;

import uk.ac.ucl.excites.sapelli.collector.control.Controller;
import uk.ac.ucl.excites.sapelli.collector.model.CollectorRecord;
import uk.ac.ucl.excites.sapelli.collector.model.Field.Optionalness;
import uk.ac.ucl.excites.sapelli.collector.model.fields.MultiListField;
import uk.ac.ucl.excites.sapelli.collector.model.fields.MultiListField.MultiListItem;
import uk.ac.ucl.excites.sapelli.collector.ui.CollectorUI;
import uk.ac.ucl.excites.sapelli.collector.ui.NonSelfLeavingFieldUI;

/**
 * @author mstevens
 *
 */
public abstract class MultiListUI<V> extends NonSelfLeavingFieldUI<MultiListField, V>
{

	static protected final String PLEASE_SELECT = " Please select "; //TODO multilang
	static protected final String UNDO_SELECTION = " No selection "; //TODO multilang
	
	public MultiListUI(MultiListField listField, Controller controller, CollectorUI<V> collectorUI)
	{
		super(listField, controller, collectorUI);
	}

	/* (non-Javadoc)
	 * @see uk.ac.ucl.excites.sapelli.collector.ui.NonSelfLeavingFieldUI#storeValue(uk.ac.ucl.excites.sapelli.collector.model.CollectorRecord)
	 */
	@Override
	protected void storeValue(CollectorRecord record)
	{
		MultiListItem chosen = getChosenItem();
		if(!field.isNoColumn() && chosen != null)
			field.getColumn().storeValue(record, field.getValueForItem(chosen));
	}

	/* (non-Javadoc)
	 * @see uk.ac.ucl.excites.sapelli.collector.ui.FieldUI#isValid(uk.ac.ucl.excites.sapelli.collector.model.CollectorRecord)
	 */
	@Override
	public boolean isValid(CollectorRecord record)
	{
		MultiListItem chosen = getChosenItem();
		boolean valid = chosen == null ? (field.getOptional() == Optionalness.ALWAYS) : chosen.isLeaf();
		return valid;
	}
	
	protected abstract MultiListItem getChosenItem();

}

@@ -1316,26 +1316,8 @@
 mn()
- && chosen != null
 )%0D%0A%09
@@ -1354,16 +1354,33 @@
 (record,
+ chosen != null ?
  field.g
@@ -1401,16 +1401,23 @@
 (chosen)
+ : null
 );%0D%0A%09%7D%0D%0A
@@ -1681,23 +1681,14 @@
 %0D%0A%09%09
-boolean valid =
+return
  cho
@@ -1770,25 +1770,8 @@
 );%0D%0A
-%09%09return valid;%0D%0A
 %09%7D%0D%0A

Fix in MultiListUI#storeValue()