package de.usu.s3.web.client.login;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.CheckboxItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;

public class TestTabSetMissingPane implements EntryPoint{

	@Override
	public void onModuleLoad() {
		final TabSet tmpTabSet = new TabSet();
		tmpTabSet.setWidth100();
		tmpTabSet.setHeight100();
		tmpTabSet.setDestroyPanes(false);

		final Tab tab1 = new Tab();
		tab1.setTitle("Tab 1");
		tab1.setPane(new Label("...pane 1 content..."));
		final Tab tab2 = new Tab();
		tab2.setTitle("Tab 2");
		tab2.setPane(new Label("...pane 2 content..."));
		tmpTabSet.setTabs(tab1,tab2);

		//--- form with items to show/hide tabs
		DynamicForm form = new DynamicForm();
		form.setBackgroundColor("#ffffff");
		
		CheckboxItem switchTab1Item = new CheckboxItem("t1", "Show/Hide Tab 1");
		switchTab1Item.setDefaultValue(true);
		switchTab1Item.addChangedHandler(new ChangedHandler() {
			@Override
			public void onChanged(ChangedEvent event) {
				if ((Boolean)event.getValue()) {
					tmpTabSet.addTab(tab1, 0);
				} else {
					tmpTabSet.removeTab(tab1);
				}
			}
		});
		
		CheckboxItem switchTab2Item = new CheckboxItem("t2", "Show/Hide Tab 2");
		switchTab2Item.setDefaultValue(true);
		switchTab2Item.addChangedHandler(new ChangedHandler() {
			@Override
			public void onChanged(ChangedEvent event) {
				if ((Boolean)event.getValue()) {
					tmpTabSet.addTab(tab2);
				} else {
					tmpTabSet.removeTab(tab2);
				}
			}
		});
		form.setItems(switchTab1Item, switchTab2Item);
		//-----------------
		
		VLayout tmpCover = new VLayout();
		tmpCover.setWidth100();
		tmpCover.setHeight(200);
		
		tmpCover.addMember(tmpTabSet);
		tmpCover.addMember(form);
		tmpCover.draw();
	}

}
