package com.se.smartgwt.client.table;

import com.se.smartgwt.client.data.SampleDataSource;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;

/*******************************************************************************
* TableFilterDialog
*******************************************************************************/
public class TableFilterDialog extends Window
{

   DataSource datasource = null;
   ListGrid popUpGrid = null;

   /*******************************************************************************
   * Constructor 
   *******************************************************************************/
   public TableFilterDialog()
   {
      setAutoSize(true);
      setTitle("Test table");
      setShowMinimizeButton(false);
      setIsModal(true);
      setShowModalMask(true);
      addCloseClickHandler(new CloseClickHandler() {
         @Override
         public void onCloseClick(CloseClickEvent event)
         {
            destroy();
         }
      });
      setWidth(500);
      setHeight(150);
      centerInPage();

      buildUI();

   }

   /***************************************************************************
    * Builds the UI.
    **************************************************************************/
   private void buildUI()
   {

      DynamicForm buttonForm = new DynamicForm();
      buttonForm.setHeight100();
      buttonForm.setWidth100();
      buttonForm.setPadding(0);
      ButtonItem okbutton = new ButtonItem("Ok");

      okbutton.setAutoFit(true);

      okbutton.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event)
         {            
            destroy();
         }
      });

      buttonForm.setFields(okbutton);

      createList();

      addItem(popUpGrid);
      addItem(buttonForm);

   }

   /*******************************************************************************
   * @return
   *******************************************************************************/
   private void createList()
   {
      datasource = SampleDataSource.getInstance();

      popUpGrid = new ListGrid();
      popUpGrid.setWidth100();
      popUpGrid.setHeight(500);
      popUpGrid.setAlternateRecordStyles(true);
      popUpGrid.setAutoFetchData(true);
      popUpGrid.setShowFilterEditor(true);
      popUpGrid.setDataSource(datasource);

      popUpGrid.draw();
   }

   public void display()
   {
      show();
   }

}
