package com.evolute.siprp.client;

import com.evolute.siprp.client.panels.footer.FooterPanel;
import com.evolute.siprp.client.panels.utils.navigation.NavigationConstants;
import com.evolute.siprp.client.panels.utils.navigation.PageNavigation;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;



public class GestaoSHST implements EntryPoint, ValueChangeHandler< String >
{

	private String oldEvent = null;
	
	public void onModuleLoad()
	{
		PageNavigation.goPage( NavigationConstants.LOGIN_PANEL );
		
		RootPanel.get( "footer" ).add( new FooterPanel() );
		
	    History.addValueChangeHandler( this );
	    History.fireCurrentHistoryState();
	}

	@Override
	public void onValueChange( ValueChangeEvent< String > newEvent ) 
	{
		if ( oldEvent != null && newEvent.getValue().equals( oldEvent ) )
		{
			return ;
		}
		
		oldEvent = newEvent.getValue();
		Integer panelID = null;
		try
		{
			panelID = Integer.parseInt( oldEvent );
		} 
		catch ( Exception e )
		{
			return ;
		}
		
		PageNavigation.goPage( panelID );
	}
	
}
