
package com.smartgwt.sample.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceSequenceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.CharacterCasing;
import com.smartgwt.client.util.KeyCallback;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.FilterBuilder;
import com.smartgwt.client.widgets.layout.VStack;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CustomDS implements EntryPoint
{

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad()
	{

		KeyIdentifier debugKey = new KeyIdentifier();
		debugKey.setCtrlKey( true );
		debugKey.setKeyName( "D" );

		Page.registerKey( debugKey, new KeyCallback()
		{
			public void execute(String keyName)
			{
				SC.showConsole();
			}
		} );

		// instantiate DataSource on the client only (this example explicitly bypasses
		// ISC server-side DataSource management)

		DataSource dataSource = new DataSource();
		dataSource.setDataURL( GWT.getModuleBaseURL() + "/supplyItemOperations.rpc" );
		dataSource.setID( "supplyItem" );

		DataSourceSequenceField itemID = new DataSourceSequenceField( "itemID" );
		itemID.setPrimaryKey( true );
		itemID.setHidden( true );

		DataSourceTextField itemName = new DataSourceTextField( "itemName", "Item", 128, true );
		CustomTextItem cti = new CustomTextItem();
		cti.setCharacterCasing( CharacterCasing.UPPER );
		itemName.setEditorType( cti );

		DataSourceTextField SKU = new DataSourceTextField( "SKU", "SKU", 10 );
		//SKU.setCanFilter(false);

		DataSourceTextField description = new DataSourceTextField( "description", "Description" );
		DataSourceTextField category = new DataSourceTextField( "category", "Category", 128 );
		DataSourceTextField units = new DataSourceTextField( "units", "Units", 5 );

		DataSourceFloatField unitCost = new DataSourceFloatField( "unitCost", "Unit Cost" );
		DataSourceBooleanField inStock = new DataSourceBooleanField( "inStock", "In Stock" );

		DataSourceDateField nextShipment = new DataSourceDateField( "nextShipment", "Next Shipment" );

		dataSource.setFields( itemID, itemName, SKU, description, category, units, unitCost, inStock, nextShipment );

		VStack vStack = new VStack();
		vStack.setLeft( 175 );
		vStack.setTop( 75 );
		vStack.setWidth( "70%" );
		vStack.setMembersMargin( 20 );

		FilterBuilder filterBuilder = new FilterBuilder();
		filterBuilder.setDataSource( dataSource );
		vStack.addMember( filterBuilder );
		
		DynamicForm form = new DynamicForm();
		CustomTextItem itemField = new CustomTextItem();
		itemField.setTitle( "Item" );
		form.setFields( itemField );
		vStack.addMember( form );

		vStack.draw();
	}
}
