package com.evolute.siprp.client.panels.apps.AnaliseAcidentesTrabalho.actual;

import com.evolute.siprp.client.panels.utils.permissoes.AccessConstants;
import com.evolute.siprp.client.panels.utils.permissoes.PermissionsController;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

public class ActualPanel extends Composite 
{

	private static ActualPanelUiBinder uiBinder = GWT.create( ActualPanelUiBinder.class );
	interface ActualPanelUiBinder extends UiBinder< Widget, ActualPanel > {  }

	private PermissionsController permsController;
	

	@UiField protected Button btnNewAnalysis;
	@UiField protected ActualTable tableActual;
	
	
	public ActualPanel() 
	{
		permsController = PermissionsController.getController();
		if ( permsController.hasPermissionTo( AccessConstants.VIEW_ACTUAL_PANEL ) )
		{
			setupComponents();
		}
		else
		{
			initWidget( new SimplePanel() );
		}
	}
	

	private void setupComponents()
	{
		initWidget( uiBinder.createAndBindUi( this ) );
		
		btnNewAnalysis.setText( "Criar nova an\u00E1lise de acidentes de trabalho" );		
		if ( ! permsController.hasPermissionTo( AccessConstants.VIEW_ACTUAL_PANEL_NOVA_ANALISE_BUTTON ) )
		{
			btnNewAnalysis.setVisible( false );
		}
	}
	
	
	@UiHandler( { "btnNewAnalysis" } )
	protected void onClick( ClickEvent e ) 
	{
		if ( e.getSource().equals( btnNewAnalysis ) )
		{
			Window.alert( "new analysis" );
		}

	}
	
}
