package com.gwt.client;

import java.util.logging.Logger;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;

/**
 * The client view of the demo.
 * 
 */
public class AcmeDemo implements EntryPoint {

  private static final Logger log = Logger.getLogger(AcmeDemo.class.getName());

  private VLayout mainLayout = new VLayout();
  TabSet tabSet = new TabSet();

  public void onModuleLoad() {
    tabSet.setDestroyPanes(true);
    tabSet.setWidth100();
    tabSet.setHeight100();

    tabSet.setShowCustomScrollbars(false);
    tabSet.setPaneContainerOverflow(Overflow.VISIBLE);
    tabSet.setOverflow(Overflow.VISIBLE);

    tabSet.addTab(getSmallerListingWidget());
    tabSet.addTab(getBiggerListingWidget());

    mainLayout.setWidth100();
    mainLayout.setHeight100();

    mainLayout.addMember(tabSet);
    mainLayout.draw();
  }

  private Tab getSmallerListingWidget() {

    Tab tab = new Tab("Smaller Listing - 10 Records");
    tab.setID("SmallerListingWidget");
    tab.setPane(new SmallerListingWidget());

    tab.addTabSelectedHandler(new TabSelectedHandler() {
      @Override
      public void onTabSelected(TabSelectedEvent event) {
        Tab bigTab = tabSet.getTab("BiggerListingWidget");
        if (bigTab != null) {
          bigTab.getPane().clear();
        }
      }
    });

    return tab;
  }

  private Tab getBiggerListingWidget() {
    Tab tab = new Tab("Bigger Listing - 100 Records");
    tab.setID("BiggerListingWidget");
    tab.setPane(new BiggerListingWidget());

    tab.addTabSelectedHandler(new TabSelectedHandler() {
      @Override
      public void onTabSelected(TabSelectedEvent event) {
        Tab smallTab = tabSet.getTab("SmallerListingWidget");
        if (smallTab != null) {
          smallTab.getPane().clear();
        }
      }
    });
    return tab;
  }
}
