package com.smartgwt.sample.showcase.client.forms.controls;

import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.LinkItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.sample.showcase.client.PanelFactory;
import com.smartgwt.sample.showcase.client.ShowcasePanel;

public class FormVariousControlsSample extends ShowcasePanel {
    private static final String DESCRIPTION = "Demonstration of several form controls.";

    public static class Factory implements PanelFactory {
        private String id;

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

        public String getID() {
            return id;
        }

        public String getDescription() {
            return DESCRIPTION;
        }
    }

    public Canvas getViewPanel() {
        HLayout mainLayout = new HLayout();
        mainLayout.setHeight(20);
        
        HLayout layout1 = new HLayout(0);
        Label label1 = new Label("LinkItem using 'disabled' property");
        label1.setHeight(20);
        label1.setWidth(250);
        layout1.addChild(label1);

        final Canvas fooCanvas1 = new Canvas();
        fooCanvas1.setBackgroundColor("#00FF00");
        fooCanvas1.setWidth(250);
        layout1.addMember(fooCanvas1);
        
        final DynamicForm form1 = new DynamicForm();
        
        LinkItem linkItem1 = new LinkItem("link");
        linkItem1.setTitle("LinkItem");
        linkItem1.setLinkTitle("Click Me");
        linkItem1.setDisabled(true);
        linkItem1.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                SC.say("Hello World");
            }
        });
        
        form1.setBackgroundColor("#FF0000");
        form1.setFields(linkItem1);
        layout1.addMember(form1);
        
        /********************************************************************/
        
        HLayout layout2 = new HLayout(0);
        Label label2 = new Label("LinkItem not using 'disabled' property");
        label2.setHeight(20);
        label2.setWidth(250);
        layout2.addChild(label2);

        final Canvas fooCanvas2 = new Canvas();
        fooCanvas2.setBackgroundColor("#00FF00");
        fooCanvas2.setWidth(250);
        layout2.addMember(fooCanvas2);
        
        final DynamicForm form2 = new DynamicForm();
        
        LinkItem linkItem2 = new LinkItem("link");
        linkItem2.setTitle("LinkItem");
        linkItem2.setLinkTitle("Click Me");
        linkItem2.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                SC.say("Hello World");
            }
        });
        
        form2.setBackgroundColor("#FF0000");
        form2.setFields(linkItem2);
        layout2.addMember(form2);

        
        mainLayout.addMembers(layout1, layout2);
        return mainLayout;
    }

    public String getIntro() {
        return DESCRIPTION;
    }

}