// Description: The listGrid will not validate the records that added initially.
//              records added when edit listGrid cells inline are validated properly.

package com.hp.isomorphic.client.issues;

import java.util.ArrayList;
import java.util.List;

import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.widgets.form.validator.IsIntegerValidator;
import com.smartgwt.client.widgets.form.validator.LengthRangeValidator;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class EditByCellWithSort extends ListGrid {
	public EditByCellWithSort() {
		ListGridField integerField = new ListGridField("Col1", "Integer Field", 100);
		integerField.setValidators(new IsIntegerValidator());

		ListGridField stringField = new ListGridField("Col2", "String Field", 100);
		LengthRangeValidator lengthValidator = new LengthRangeValidator();
		lengthValidator.setMax(10);
		stringField.setValidators(lengthValidator);
		setFields(integerField, stringField);
		setSortField("Col1");
		
		List<ListGridRecord> recordList = new ArrayList<>();
		for (int i = 1; i < 10; ++i) {
			ListGridRecord record = new ListGridRecord();
			record.setAttribute("Col1",  i );
			record.setAttribute("Col2",  i +" test" );
			recordList.add(record);
		}

		ListGridRecord lastRecord = new ListGridRecord();
		lastRecord.setAttribute("Col1",  "String Data" );
		lastRecord.setAttribute("Col2",  "String more than 10");
		recordList.add(lastRecord);

		ListGridRecord[] records = new ListGridRecord[recordList.size()];
		recordList.toArray(records);
		setData(records);
		setCanEdit(true);
		setEditByCell(true);
		setEditEvent(ListGridEditEvent.CLICK);
	}
}
