/**
 * <I>
 * TODO Décrire ici le rôle de la classe au sein du système.
 * <p>
 * <b>COMPOSANT</b><BR>
 * <I>
 * IHM
 * </I>
 * <p>
 * <b>INDICATION D'UTILISATION</b><BR>
 * <I>
 * Sans objet.<br>
 * </I>
 * <p>
 * <b>DOCUMENTS DE REFERENCE</b><BR>
 * <I>Sans objet</I>
 * <p>
 * <b>DATE CREATION</b><BR>
 * <I>22 févr. 2012</I>
 * <p>
 * <b>AUTEUR</b><BR>
 * <I>Groupe SQLI</I>
 * <p>
 */
package com.test.gpda.ihm.client;

import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class IHM implements EntryPoint {

	
	public void initApp() {
		final Button sendButton = new Button("Google Map");
		// We can add style names to widgets
		sendButton.addStyleName("sendButton");

		sendButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				drawMap();
			}
		});

		// Add the nameField and sendButton to the RootPanel
		// Use RootPanel.get() to get the entire body element
		RootPanel.get("enteteContenuPanel").add(sendButton);

		final Button sendButton2 = new Button("Clear Google Map");
		// We can add style names to widgets
		sendButton2.addStyleName("sendButton");

		sendButton2.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				RootPanel.get("contenuDeLaPage").clear();

				try {
					Element element = Document.get().getElementById(
							"map_container");
					
					Window.alert("element " +element);
					element.removeFromParent();

				} catch (Exception e) {

				}
			}
		});

		RootPanel.get("enteteContenuPanel").add(sendButton2);
	}

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		try {
			AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
			options.setOtherParms("sensor=false&language=fr");
			Runnable callback = new Runnable() {
				public void run() {
					try {
						initApp();
					} catch (Throwable e) {
						GWT.log(e.getMessage(), e);
					}
				}
			};
			AjaxLoader.loadApi("maps", "3", callback, options);
		} catch (Exception e) {
			Window.alert("e " + e.getMessage());
		}
	}

	public static void drawMap() {
		MapWidgetV3 mapV3 = new MapWidgetV3(48.85661, 2.35222);
		RootPanel.get("contenuDeLaPage").add(mapV3);
	}

	// public static void initApp() {
	// UIPage.getINSTANCE().setUserName(nomUserConnecte);
	// SecuriteUtil.getInstance().setRoles(lstRoles);
	// UIPage.displaySearchAutomateAcceuil();
	// }

	// public static void deconnexion() {
	// Cookies.removeCookie(ISecuriteConstante.USER);
	// Cookies.removeCookie(ISecuriteConstante.ROLES);
	// Cookies.removeCookie(ISecuriteConstante.NATIONAL);
	// Cookies.removeCookie(ISecuriteConstante.CLOISONNEMENT_CLASSE);
	// Cookies.removeCookie(ISecuriteConstante.HEADER_APPLICATION);
	// Cookies.removeCookie(ISecuriteConstante.MAIL_TO);
	// Cookies.removeCookie(ISecuriteConstante.HELP_URL);
	// Cookies.removeCookie(ISecuriteConstante.LISTE_LANGUE_POSSIBLE);
	// UIPage.getINSTANCE().getWindowsClosingHandler().removeHandler();
	// if (GWT.isProdMode()) {
	// Window.Location.replace(GWT.getHostPageBaseURL() + "securite/login.jsp");
	// } else {
	// Window.Location.assign(GWT.getHostPageBaseURL() +
	// "securite/login.jsp?gwt.codesvr=" +
	// Window.Location.getParameter("gwt.codesvr"));
	// }
	// }

}
