package com.smartgwt.sample.client;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.CharacterCasing;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.types.OperatorId;
import com.smartgwt.client.widgets.form.fields.TextItem;


public class MyDataSource extends DataSource
{

	public MyDataSource(String id)
	{
		setID( id );


		DataSourceField field;

		TextItem upperTextItem = new TextItem();
		
//if the line below is commented out the 'toUpperCase is not a function' bug goes away.
		upperTextItem.setCharacterCasing( CharacterCasing.UPPER );
		
		upperTextItem.setBrowserSpellCheck( false );


		field = new DataSourceTextField( "field1", "Field1", 80 );
		setStringConditions( field );
		field.setEditorType( upperTextItem );
		addField( field );

		setClientOnly( true );

		setTypeOperators(FieldType.ANY, new OperatorId[ ]
		{
			OperatorId.AND, OperatorId.OR
		} );

	}

	public MyDataSource()
	{
		this( "myDataSource" );
	}


	public void setStringConditions(DataSourceField field)
	{
		field.setValidOperators( OperatorId.EQUALS, OperatorId.NOT_EQUAL, OperatorId.ICONTAINS, OperatorId.IN_SET, OperatorId.NOT_IN_SET, OperatorId.ISTARTS_WITH, OperatorId.IENDS_WITH,
				OperatorId.INOT_CONTAINS, OperatorId.INOT_STARTS_WITH, OperatorId.INOT_ENDS_WITH, OperatorId.IS_NULL,
				OperatorId.NOT_NULL );
	}

}
