package com.mediasol.testcases.smartgwt.tabset.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.smartgwt.client.util.EventHandler;
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.HLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;

public class TabsTestCase implements EntryPoint {
	
	@Override
	public void onModuleLoad() {
		initializeClickHandler();
		
		HLayout mainLayout = new HLayout();
		mainLayout.setWidth100();
		mainLayout.setHeight100();
		
		final TabSet tabSet = new TabSet();
		
		Tab tab1 = new Tab();
		tab1.setCanClose(false);
		tab1.setTitle("Tab 1");
		Button myButton = new Button();
		myButton.setTitle("Test Bug");
		tab1.setPane(myButton);
		tabSet.addTab(tab1);
		
		myButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				Tab tab2 = new Tab();
				tab2.setCanClose(false);
				tab2.setTitle("Tab 2");
				Label myLabel = new Label("Test content");
				tab2.setPane(myLabel);
				tabSet.addTab(tab2);
				tabSet.selectTab(tab2);
			}
			
		});
		
		mainLayout.addMember(tabSet);
		RootLayoutPanel.get().add(mainLayout);
	}
	
	public static native void initializeClickHandler()/*-{
		$wnd.globalClickHandler = @com.mediasol.testcases.smartgwt.tabset.client.TabsTestCase::globalClickHandler();
		$wnd.isc.Page.setEvent("mouseDown", "globalClickHandler()");
	}-*/;
	
	public static void globalClickHandler() {
		Canvas target = EventHandler.getTarget(); // Comment this line to make it working again
	}
	
}
