import com.allen_sauer.gwt.log.client.Log;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.layout.VLayout;

public class MultipleItemTest {

	public void go() {
		
		Log.debug("Multi item test");
		
		final DynamicForm form = new DynamicForm();
		
		FormItem valueInputItem = new TextItem();
		valueInputItem.setWidth(100); // Necessary or valueInputItem.getWidth() crashes?
		
		Log.debug("TextItem width: " + valueInputItem.getWidth());
		
		final MultipleItem<String> multipleItem =
			new MultipleItem<String>("testItem", "Test Item", valueInputItem);
		
		multipleItem.setRequired(true);
		
		multipleItem.addChangedHandler(new ChangedHandler() {
			@Override
			public void onChanged(ChangedEvent event) {
				Log.debug("Multiple item changed. Current values: " + multipleItem.getValueAsList());
			}
		});
		
		form.setItems(multipleItem);
		
		IButton button = new IButton("Validate", new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				boolean valid = form.validate();
				Log.debug("Multiple item current values: " + multipleItem.getValueAsList());
				Log.debug("Form is valid? " + valid);
			}
		});
		
		VLayout layout = new VLayout();
		layout.addMember(form);
		layout.addMember(button);
		
		layout.draw();
	}

}
