package com.smartgwt.sample.showcase.client.effects.animation;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.types.DragAppearance;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.*;
import com.smartgwt.client.widgets.events.*;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.CheckboxItem;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.sample.showcase.client.PanelFactory;
import com.smartgwt.sample.showcase.client.ShowcasePanel;

public class AnimationPlaypenSample extends ShowcasePanel {

    private static final String DESCRIPTION = null;
    
    CheckboxItem masterChkB;
    RadioGroupItem userReplyRGI;

    public static class Factory implements PanelFactory {
        private String id;

        public Canvas create() {
            AnimationPlaypenSample panel = new AnimationPlaypenSample();
            id = panel.getID();
            return panel;
        }

        public String getID() {
            return id;
        }

        public String getDescription() {
            return DESCRIPTION;
        }
    }

    public Canvas getViewPanel() {
        Canvas canvas = new Canvas();
        canvas.setWidth100();
        canvas.setHeight100();
        
        DynamicForm dynamicForm = new DynamicForm();
        
        masterChkB = new CheckboxItem("master", "Master ChkB");
        
        userReplyRGI = new RadioGroupItem("userReply" , "User Reply");
        userReplyRGI.setVertical(false);
        userReplyRGI.setValueMap("confirmed", "declined", "no reply");
        userReplyRGI.setDefaultValue("confirmed");
        userReplyRGI.setWrap(false);
        userReplyRGI.setWrapTitle(false);
        userReplyRGI.setDisabled(true);
        
        dynamicForm.setFields(masterChkB, userReplyRGI);
        
        masterChkB.addChangedHandler(new ChangedHandler() {
			public void onChanged(ChangedEvent event) {
				if(masterChkB.getValue() != null && masterChkB.getValueAsBoolean()) {
					userReplyRGI.setDisabled(false);
				}
				else if(masterChkB.getValue() != null && !masterChkB.getValueAsBoolean()) {
					userReplyRGI.setDisabled(true);
				}
				
			}
		});
        
        canvas.addChild(dynamicForm);
        return canvas;
    }

    public String getIntro() {
        return DESCRIPTION;
    }

}