package com.google.gwt.sample.contacts.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
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.CloseClickHandler;
import com.smartgwt.client.widgets.tab.events.TabCloseClickEvent;

public class TestEntryPoint implements EntryPoint {

	public void onModuleLoad() {
		VLayout container = new VLayout();

		final TabSet tabSet = new TabSet();
		tabSet.setHeight(300);
		tabSet.setWidth(300);
		
		Tab tab = new Tab();
		tab.setCanClose(true);
		tab.setTitle("Tab 0");
		tab.setAttribute("myProperty", "my value");
		Canvas tabPanel = new Canvas();
		tabPanel.addChild(new Label("My Tab 0"));
		tab.setPane(tabPanel);
		tabSet.addTab(tab);

		Button changeAttributeValueButton = new Button("Change value");
		changeAttributeValueButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				tabSet.getTab(0).setAttribute("myProperty" , "my NEW value");
				SC.say("myProperty was changed successfully!");
			}
		});
		
		Button getAttributeValueButton = new Button("Get value");
		getAttributeValueButton .addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				SC.say("myProperty: " + tabSet.getTab(0).getAttribute("myProperty") );
			}
		});		
		
		container.addMember(tabSet);
		container.addMember(changeAttributeValueButton);
		container.addMember(getAttributeValueButton);
	
		tabSet.addCloseClickHandler(new CloseClickHandler() {
			@Override
			public void onCloseClick(TabCloseClickEvent event) {
				// always show the old value
				SC.say("TabCloseClick: " + event.getTab().getAttribute("myProperty"));
				
				// wrong value too...
				//int index = tabSet.getTabNumber( event.getTab().getID() );
				//SC.say("myProperty: " + tabSet.getTab(index).getAttribute("myProperty") );
			}
		});
		
		container.draw();
	}

}
