package org.mytest.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.tab.TabSet;

public class Test implements EntryPoint {
	
	TabSet mainTabSet;

	@Override
	public void onModuleLoad() {
		
		HLayout mainLayout = new HLayout();
		mainLayout.setHeight100();
		mainLayout.setWidth100();
		
		mainTabSet = new TabSet();
		mainTabSet.setWidth100();
		mainTabSet.setHeight100();
		mainTabSet.setDestroyPanes(true);
		mainTabSet.setCanReorderTabs(true);

		addTab();
		
		mainLayout.addMember(mainTabSet);

		mainLayout.draw();
	}

	
	private void addTab(){
		
		MyTab t = new MyTab();
		
		final Button button = new Button("add after this tab");
		button.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				addTab();				
			}
			
		});

		t.fillTab(button);
		
		Integer selectedMainTabIndex = mainTabSet.getSelectedTabNumber();
		if (selectedMainTabIndex >= 0){
			mainTabSet.addTab(t, selectedMainTabIndex + 1);  	// http://forums.smartclient.com/showthread.php?p=132417&posted=1#post132417
//			mainTabSet.addTab(t); 								// this works
			mainTabSet.selectTab(t);
		}else{
			mainTabSet.addTab(t); 
			mainTabSet.selectTab(t);
		}	

	}
		
}
