/*
 * GestaoUtilizadores.java
 *
 * Created on November 30, 2007, 1:34 PM
 * Copyright lluis
 */
package analiseacidentestrabalho;

import com.sun.data.provider.RowKey;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.rave.web.ui.component.Body;
import com.sun.rave.web.ui.component.Button;
import com.sun.rave.web.ui.component.DropDown;
import com.sun.rave.web.ui.component.Form;
import com.sun.rave.web.ui.component.Head;
import com.sun.rave.web.ui.component.Html;
import com.sun.rave.web.ui.component.Hyperlink;
import com.sun.rave.web.ui.component.ImageComponent;
import com.sun.rave.web.ui.component.Link;
import com.sun.rave.web.ui.component.Page;
import com.sun.rave.web.ui.component.PanelGroup;
import com.sun.rave.web.ui.component.StaticText;
import com.sun.rave.web.ui.component.Table;
import com.sun.rave.web.ui.component.TableColumn;
import com.sun.rave.web.ui.component.TableRowGroup;
import com.sun.rave.web.ui.component.TextField;
import com.sun.rave.web.ui.model.SingleSelectOptionsList;
import db.AnalisesDataProvider;
import db.UtilizadoresActivosListDataProvider;
import db.UtilizadoresDataProvider;
import db.UtilizadoresInactivosListDataProvider;
import global.Global;
import java.util.ArrayList;
import javax.faces.FacesException;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.event.ValueChangeEvent;
import javax.servlet.http.HttpServletRequest;
import utils.Utils;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 */
public class GestaoUtilizadores extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
    private int __placeholder;
    
    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    
    private Page page1 = new Page();
    
    public Page getPage1() {
        return page1;
    }
    
    public void setPage1(Page p) {
        this.page1 = p;
    }
    
    private Html html1 = new Html();
    
    public Html getHtml1() {
        return html1;
    }
    
    public void setHtml1(Html h) {
        this.html1 = h;
    }
    
    private Head head1 = new Head();
    
    public Head getHead1() {
        return head1;
    }
    
    public void setHead1(Head h) {
        this.head1 = h;
    }
    
    private Link link1 = new Link();
    
    public Link getLink1() {
        return link1;
    }
    
    public void setLink1(Link l) {
        this.link1 = l;
    }
    
    private Body body1 = new Body();
    
    public Body getBody1() {
        return body1;
    }
    
    public void setBody1(Body b) {
        this.body1 = b;
    }
    
    private Form form1 = new Form();
    
    public Form getForm1() {
        return form1;
    }
    
    public void setForm1(Form f) {
        this.form1 = f;
    }

    private HtmlPanelGrid gridBase1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridBase1() {
        return gridBase1;
    }

    public void setGridBase1(HtmlPanelGrid hpg) {
        this.gridBase1 = hpg;
    }

    private HtmlPanelGrid gridLayout1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridLayout1() {
        return gridLayout1;
    }

    public void setGridLayout1(HtmlPanelGrid hpg) {
        this.gridLayout1 = hpg;
    }

    private HtmlPanelGrid gridPanel1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel1() {
        return gridPanel1;
    }

    public void setGridPanel1(HtmlPanelGrid hpg) {
        this.gridPanel1 = hpg;
    }

    private PanelGroup groupPanel1 = new PanelGroup();

    public PanelGroup getGroupPanel1() {
        return groupPanel1;
    }

    public void setGroupPanel1(PanelGroup pg) {
        this.groupPanel1 = pg;
    }

    private ImageComponent image1 = new ImageComponent();

    public ImageComponent getImage1() {
        return image1;
    }

    public void setImage1(ImageComponent ic) {
        this.image1 = ic;
    }

    private ImageComponent image2 = new ImageComponent();

    public ImageComponent getImage2() {
        return image2;
    }

    public void setImage2(ImageComponent ic) {
        this.image2 = ic;
    }

    private PanelGroup groupPanel2 = new PanelGroup();

    public PanelGroup getGroupPanel2() {
        return groupPanel2;
    }

    public void setGroupPanel2(PanelGroup pg) {
        this.groupPanel2 = pg;
    }

    private StaticText lblUser = new StaticText();

    public StaticText getLblUser() {
        return lblUser;
    }

    public void setLblUser(StaticText st) {
        this.lblUser = st;
    }

    private StaticText stSep1 = new StaticText();

    public StaticText getStSep1() {
        return stSep1;
    }

    public void setStSep1(StaticText st) {
        this.stSep1 = st;
    }

    private Hyperlink lnkNewUser1 = new Hyperlink();

    public Hyperlink getLnkNewUser1() {
        return lnkNewUser1;
    }

    public void setLnkNewUser1(Hyperlink h) {
        this.lnkNewUser1 = h;
    }

    private StaticText stSep2 = new StaticText();

    public StaticText getStSep2() {
        return stSep2;
    }

    public void setStSep2(StaticText st) {
        this.stSep2 = st;
    }

    private Hyperlink lnkEditUser1 = new Hyperlink();

    public Hyperlink getLnkEditUser1() {
        return lnkEditUser1;
    }

    public void setLnkEditUser1(Hyperlink h) {
        this.lnkEditUser1 = h;
    }

    private StaticText staticText1 = new StaticText();

    public StaticText getStaticText1() {
        return staticText1;
    }

    public void setStaticText1(StaticText st) {
        this.staticText1 = st;
    }

    private Hyperlink lnkLogout1 = new Hyperlink();

    public Hyperlink getLnkLogout1() {
        return lnkLogout1;
    }

    public void setLnkLogout1(Hyperlink h) {
        this.lnkLogout1 = h;
    }

    private HtmlPanelGrid gridConcluidos1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridConcluidos1() {
        return gridConcluidos1;
    }

    public void setGridConcluidos1(HtmlPanelGrid hpg) {
        this.gridConcluidos1 = hpg;
    }

    private HtmlPanelGrid gridPanel6 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel6() {
        return gridPanel6;
    }

    public void setGridPanel6(HtmlPanelGrid hpg) {
        this.gridPanel6 = hpg;
    }

    private StaticText staticText5 = new StaticText();

    public StaticText getStaticText5() {
        return staticText5;
    }

    public void setStaticText5(StaticText st) {
        this.staticText5 = st;
    }

    private HtmlPanelGrid gridPanel7 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel7() {
        return gridPanel7;
    }

    public void setGridPanel7(HtmlPanelGrid hpg) {
        this.gridPanel7 = hpg;
    }

    private PanelGroup groupPanel6 = new PanelGroup();

    public PanelGroup getGroupPanel6() {
        return groupPanel6;
    }

    public void setGroupPanel6(PanelGroup pg) {
        this.groupPanel6 = pg;
    }

    private StaticText staticText7 = new StaticText();

    public StaticText getStaticText7() {
        return staticText7;
    }

    public void setStaticText7(StaticText st) {
        this.staticText7 = st;
    }

    private TextField txtPor = new TextField();

    public TextField getTxtPor() {
        return txtPor;
    }

    public void setTxtPor(TextField tf) {
        this.txtPor = tf;
    }

    private PanelGroup groupPanel7 = new PanelGroup();

    public PanelGroup getGroupPanel7() {
        return groupPanel7;
    }

    public void setGroupPanel7(PanelGroup pg) {
        this.groupPanel7 = pg;
    }

    private StaticText staticText8 = new StaticText();

    public StaticText getStaticText8() {
        return staticText8;
    }

    public void setStaticText8(StaticText st) {
        this.staticText8 = st;
    }

    private TextField txtNome = new TextField();

    public TextField getTxtNome() {
        return txtNome;
    }

    public void setTxtNome(TextField tf) {
        this.txtNome = tf;
    }

    private Button butPesquisar = new Button();

    public Button getButPesquisar() {
        return butPesquisar;
    }

    public void setButPesquisar(Button b) {
        this.butPesquisar = b;
    }

    private HtmlPanelGrid gridPanel8 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel8() {
        return gridPanel8;
    }

    public void setGridPanel8(HtmlPanelGrid hpg) {
        this.gridPanel8 = hpg;
    }

    private Table table3 = new Table();

    public Table getTable3() {
        return table3;
    }

    public void setTable3(Table t) {
        this.table3 = t;
    }

    private TableRowGroup tableRowGroup3 = new TableRowGroup();

    public TableRowGroup getTableRowGroup3() {
        return tableRowGroup3;
    }

    public void setTableRowGroup3(TableRowGroup trg) {
        this.tableRowGroup3 = trg;
    }

    private TableColumn tableColumn11 = new TableColumn();

    public TableColumn getTableColumn11() {
        return tableColumn11;
    }

    public void setTableColumn11(TableColumn tc) {
        this.tableColumn11 = tc;
    }

    private Hyperlink lnkCategoriaActivos = new Hyperlink();

    public Hyperlink getLnkCategoriaActivos() {
        return lnkCategoriaActivos;
    }

    public void setLnkCategoriaActivos(Hyperlink h) {
        this.lnkCategoriaActivos = h;
    }

    private TableColumn tableColumn13 = new TableColumn();

    public TableColumn getTableColumn13() {
        return tableColumn13;
    }

    public void setTableColumn13(TableColumn tc) {
        this.tableColumn13 = tc;
    }

    private Hyperlink lnkPorActivos = new Hyperlink();

    public Hyperlink getLnkPorActivos() {
        return lnkPorActivos;
    }

    public void setLnkPorActivos(Hyperlink h) {
        this.lnkPorActivos = h;
    }

    private TableColumn tableColumn14 = new TableColumn();

    public TableColumn getTableColumn14() {
        return tableColumn14;
    }

    public void setTableColumn14(TableColumn tc) {
        this.tableColumn14 = tc;
    }

    private Hyperlink lnkNomeActivos = new Hyperlink();

    public Hyperlink getLnkNomeActivos() {
        return lnkNomeActivos;
    }

    public void setLnkNomeActivos(Hyperlink h) {
        this.lnkNomeActivos = h;
    }

    private TableColumn tableColumn15 = new TableColumn();

    public TableColumn getTableColumn15() {
        return tableColumn15;
    }

    public void setTableColumn15(TableColumn tc) {
        this.tableColumn15 = tc;
    }

    private Hyperlink lnkEstabelecimentoActivos = new Hyperlink();

    public Hyperlink getLnkEstabelecimentoActivos() {
        return lnkEstabelecimentoActivos;
    }

    public void setLnkEstabelecimentoActivos(Hyperlink h) {
        this.lnkEstabelecimentoActivos = h;
    }

    private StaticText txtSearchMsg1 = new StaticText();

    public StaticText getTxtSearchMsg1() {
        return txtSearchMsg1;
    }

    public void setTxtSearchMsg1(StaticText st) {
        this.txtSearchMsg1 = st;
    }

    private HtmlPanelGrid gridPanel9 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel9() {
        return gridPanel9;
    }

    public void setGridPanel9(HtmlPanelGrid hpg) {
        this.gridPanel9 = hpg;
    }

    private PanelGroup groupPanel8 = new PanelGroup();

    public PanelGroup getGroupPanel8() {
        return groupPanel8;
    }

    public void setGroupPanel8(PanelGroup pg) {
        this.groupPanel8 = pg;
    }

    private StaticText staticText9 = new StaticText();

    public StaticText getStaticText9() {
        return staticText9;
    }

    public void setStaticText9(StaticText st) {
        this.staticText9 = st;
    }

    private ImageComponent image3 = new ImageComponent();

    public ImageComponent getImage3() {
        return image3;
    }

    public void setImage3(ImageComponent ic) {
        this.image3 = ic;
    }

    private StaticText staticText10 = new StaticText();

    public StaticText getStaticText10() {
        return staticText10;
    }

    public void setStaticText10(StaticText st) {
        this.staticText10 = st;
    }

    private PanelGroup groupPanel3 = new PanelGroup();

    public PanelGroup getGroupPanel3() {
        return groupPanel3;
    }

    public void setGroupPanel3(PanelGroup pg) {
        this.groupPanel3 = pg;
    }

    private StaticText staticText2 = new StaticText();

    public StaticText getStaticText2() {
        return staticText2;
    }

    public void setStaticText2(StaticText st) {
        this.staticText2 = st;
    }

    private HtmlPanelGrid gridPanel2 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel2() {
        return gridPanel2;
    }

    public void setGridPanel2(HtmlPanelGrid hpg) {
        this.gridPanel2 = hpg;
    }

    private Table table1 = new Table();

    public Table getTable1() {
        return table1;
    }

    public void setTable1(Table t) {
        this.table1 = t;
    }

    private TableRowGroup tableRowGroup1 = new TableRowGroup();

    public TableRowGroup getTableRowGroup1() {
        return tableRowGroup1;
    }

    public void setTableRowGroup1(TableRowGroup trg) {
        this.tableRowGroup1 = trg;
    }

    private TableColumn tableColumn1 = new TableColumn();

    public TableColumn getTableColumn1() {
        return tableColumn1;
    }

    public void setTableColumn1(TableColumn tc) {
        this.tableColumn1 = tc;
    }

    private Hyperlink lnkPorInactivos = new Hyperlink();

    public Hyperlink getLnkPorInactivos() {
        return lnkPorInactivos;
    }

    public void setLnkPorInactivos(Hyperlink h) {
        this.lnkPorInactivos = h;
    }

    private TableColumn tableColumn2 = new TableColumn();

    public TableColumn getTableColumn2() {
        return tableColumn2;
    }

    public void setTableColumn2(TableColumn tc) {
        this.tableColumn2 = tc;
    }

    private Hyperlink lnkNomeInactivos = new Hyperlink();

    public Hyperlink getLnkNomeInactivos() {
        return lnkNomeInactivos;
    }

    public void setLnkNomeInactivos(Hyperlink h) {
        this.lnkNomeInactivos = h;
    }

    private TableColumn tableColumn3 = new TableColumn();

    public TableColumn getTableColumn3() {
        return tableColumn3;
    }

    public void setTableColumn3(TableColumn tc) {
        this.tableColumn3 = tc;
    }

    private Hyperlink lnkCategoriaInactivos = new Hyperlink();

    public Hyperlink getLnkCategoriaInactivos() {
        return lnkCategoriaInactivos;
    }

    public void setLnkCategoriaInactivos(Hyperlink h) {
        this.lnkCategoriaInactivos = h;
    }

    private TableColumn tableColumn4 = new TableColumn();

    public TableColumn getTableColumn4() {
        return tableColumn4;
    }

    public void setTableColumn4(TableColumn tc) {
        this.tableColumn4 = tc;
    }

    private Hyperlink lnkEstabelecimentoInactivos = new Hyperlink();

    public Hyperlink getLnkEstabelecimentoInactivos() {
        return lnkEstabelecimentoInactivos;
    }

    public void setLnkEstabelecimentoInactivos(Hyperlink h) {
        this.lnkEstabelecimentoInactivos = h;
    }

    private StaticText txtSearchMsg2 = new StaticText();

    public StaticText getTxtSearchMsg2() {
        return txtSearchMsg2;
    }

    public void setTxtSearchMsg2(StaticText st) {
        this.txtSearchMsg2 = st;
    }

    private DropDown drpEstabelecimentos = new DropDown();

    public DropDown getDrpEstabelecimentos() {
        return drpEstabelecimentos;
    }

    public void setDrpEstabelecimentos(DropDown dd) {
        this.drpEstabelecimentos = dd;
    }

    private SingleSelectOptionsList drpEstabelecimentosDefaultOptions = new SingleSelectOptionsList();

    public SingleSelectOptionsList getDrpEstabelecimentosDefaultOptions() {
        return drpEstabelecimentosDefaultOptions;
    }

    public void setDrpEstabelecimentosDefaultOptions(SingleSelectOptionsList ssol) {
        this.drpEstabelecimentosDefaultOptions = ssol;
    }
    
    // </editor-fold>
    boolean isPostback = false;

    private HtmlPanelGrid gridPanel3 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel3() {
        return gridPanel3;
    }

    public void setGridPanel3(HtmlPanelGrid hpg) {
        this.gridPanel3 = hpg;
    }

    private StaticText staticText3 = new StaticText();

    public StaticText getStaticText3() {
        return staticText3;
    }

    public void setStaticText3(StaticText st) {
        this.staticText3 = st;
    }

    private HtmlPanelGrid gridPanel5 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel5() {
        return gridPanel5;
    }

    public void setGridPanel5(HtmlPanelGrid hpg) {
        this.gridPanel5 = hpg;
    }

    private Button butNovoUtilizador = new Button();

    public Button getButNovoUtilizador() {
        return butNovoUtilizador;
    }

    public void setButNovoUtilizador(Button b) {
        this.butNovoUtilizador = b;
    }

    private HtmlPanelGrid gridMsg1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridMsg1() {
        return gridMsg1;
    }

    public void setGridMsg1(HtmlPanelGrid hpg) {
        this.gridMsg1 = hpg;
    }

    private StaticText txtMsg = new StaticText();

    public StaticText getTxtMsg() {
        return txtMsg;
    }

    public void setTxtMsg(StaticText st) {
        this.txtMsg = st;
    }

    private StaticText stSep3 = new StaticText();

    public StaticText getStSep3() {
        return stSep3;
    }

    public void setStSep3(StaticText st) {
        this.stSep3 = st;
    }

    private Hyperlink lnkAnalisesAcidente = new Hyperlink();

    public Hyperlink getLnkAnalisesAcidente() {
        return lnkAnalisesAcidente;
    }

    public void setLnkAnalisesAcidente(Hyperlink h) {
        this.lnkAnalisesAcidente = h;
    }
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public GestaoUtilizadores() {
    }
    
    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     *
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("GestaoUtilizadores Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
	if (!getSessionBean1().isLoggedIn()) {
	    try {
		getExternalContext().redirect("Login.jsp");
	    } catch(Exception e) {  
	    // . . .  handle exception . . .              
	    }
	}
        else
        {
                lblUser.setText( getSessionBean1().getCurrentUser().getLogin() );  

               HttpServletRequest request = (HttpServletRequest) getExternalContext().getRequest();
               String referer = request.getRequestURI();
               String pageFrom = Utils.getPageFrom(referer);

               boolean userDeleted = getSessionBean1().isUserDeleted();

               if(userDeleted)
               {
                   getSessionBean1().setUserDeleted(false);
               }

               if(!pageFrom.matches("GestaoUtilizadores.jsp") || userDeleted)        
               {
                   isPostback = false;
               }
               else
               {
                   isPostback = true;
               }            
        }

    }
    
    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    public void preprocess() {
    }
    
    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    public void prerender() {
        AnalisesDataProvider adp = new AnalisesDataProvider();
        UtilizadoresDataProvider udp = new UtilizadoresDataProvider();
        
        if(!isPostback)
        {
           try
           {
                com.sun.rave.web.ui.model.Option[] listOptions = adp.getEstabelecimentosList( getSessionBean1().getCurrentUser().getEmpresa_id(), new Boolean(false));
                listOptions[0].setLabel("-Todos-");
                getSessionBean1().setEstabelecimentosOptions( listOptions );                                           
                drpEstabelecimentos.setSelected(new Integer(-1));
           }
           catch(Exception ex)
           {
               //ex.printStackTrace();
           }             
           
           String isDirRh = "n";
           if(getSessionBean1().getCurrentUser().getTipo().intValue() == Global.TIPO_UTILIZADOR_DIRECTOR_GERAL_RH) // Director geral rh
           {
               isDirRh = "y";
           }
            try
            {
                ArrayList list = udp.getUtilizadoresList(null, null, null, "y", isDirRh);
                getSessionBean1().getUtilizadoresActivosListDataProvider().setList(list);
            }
            catch(Exception ex)
            {
                //ex.printStackTrace();
            }

            try
            {
                ArrayList list = udp.getUtilizadoresList(null, null, null, "n", isDirRh);
                getSessionBean1().getUtilizadoresInactivosListDataProvider().setList(list);
            }
            catch(Exception ex)
            {
                //ex.printStackTrace();
                getSessionBean1().getUtilizadoresInactivosListDataProvider().setList(new ArrayList());                
                table1.setRendered(false);
            }                   
            
        }
        txtMsg.setText(getSessionBean1().getMsg());
        getSessionBean1().setMsg("");
    }
    
    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1)getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1)getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1)getBean("ApplicationBean1");
    }

    public String lnkEditUser_action() {
        // TODO: Replace with your code
        
        getSessionBean1().setNavFrom("GestaoUtilizadores");
        getSessionBean1().setModoEdicaoUtilizador("edit");
        return "user";        
    }

    public String lnkLogout_action() {
        // TODO: Replace with your code
        
        javax.servlet.http.HttpSession session =
                (javax.servlet.http.HttpSession) getExternalContext().getSession(true);
        session.invalidate();
	    try {
		getExternalContext().redirect("Login.jsp");
	    } catch(Exception e) {}        
        //return "login";	
        return null;

    }

    public String butNovaAnalise_action() {
        // TODO: Process the button click action. Return value is a navigation
        // case name where null will return to the same page.
        
        return null;
    }

    public String lnkDataAcidente_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkNr_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkPor_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkNomeAcidentado_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkFase_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkDataAcidenteSeg_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkNrSeg_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkPorSeg_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkNomeAcidentadoSeg_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String lnkFaseSeg_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public void drpAno_processValueChange(ValueChangeEvent event) {
        // TODO: Replace with your code
        
    }

    public void drpMes_processValueChange(ValueChangeEvent event) {
        // TODO: Replace with your code
        
    }

    public void drpDia_processValueChange(ValueChangeEvent event) {
        // TODO: Replace with your code
        
    }

    public String butPesquisar_action() {
        // TODO: Process the button click action. Return value is a navigation
        // case name where null will return to the same page.
        
        String por = null;
        String nome = null;
        Integer estabelecimento_id = null;
        
        if(txtPor.getText() != null)
        {
            por = (String) txtPor.getText();
            if(por.trim().length() == 0)
            {
                por = null;
            }
            else
            {
                por = por.toLowerCase();
            }
        }
        
        if(txtNome.getText() != null)
        {
            nome = (String) txtNome.getText();
            if(nome.trim().length() == 0)
            {
                nome = null;
            }
            else
            {
                nome = nome.toLowerCase();
            }            
        }        
        
        estabelecimento_id = (Integer) drpEstabelecimentos.getSelected();
        if(estabelecimento_id.intValue() == -1)
        {
            estabelecimento_id = null;
        }
        
        String isDirRh = "n";
        
        if(getSessionBean1().getCurrentUser().getTipo().intValue() == 7) //director geral rh
        {
            isDirRh = "y";
        }
        
        UtilizadoresDataProvider udp = new UtilizadoresDataProvider();
        try
        {
            ArrayList list = udp.getUtilizadoresList(por, nome, estabelecimento_id, "y", isDirRh);
            getSessionBean1().getUtilizadoresActivosListDataProvider().setList(list);
        }
        catch(Exception ex)
        {
            //ex.printStackTrace();
            getSessionBean1().getUtilizadoresActivosListDataProvider().setList(new ArrayList());            
        }        
        
        try
        {
            ArrayList list = udp.getUtilizadoresList(por, nome, estabelecimento_id, "n", isDirRh);
            getSessionBean1().getUtilizadoresInactivosListDataProvider().setList(list);
        }
        catch(Exception ex)
        {
            //ex.printStackTrace();
            getSessionBean1().getUtilizadoresInactivosListDataProvider().setList(new ArrayList());            
        }                
        
        return null;
    }
    
    public String lnkPorActivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorActivoRowData(); 
        getSessionBean1().setEditUser(u);
        getSessionBean1().setModoEdicaoUtilizador("edit");
        getSessionBean1().setNavFrom("GestaoUtilizadores");
        return "user_fields";
    }
    
    public String lnkNomeActivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorActivoRowData();
        System.out.println("UTILIZADOR ID : " + u.getId());
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit");    
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    } 
    
    public String lnkCategoriaActivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorActivoRowData(); 
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit"); 
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    }   
    
    public String lnkEstabelecimentosActivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorActivoRowData(); 
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit");  
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    }   
    
    private Utilizador getUtilizadorActivoRowData()
    {
        RowKey rk = tableRowGroup3.getRowKey();
        int k = Integer.parseInt(rk.getRowId());        
        UtilizadoresActivosListDataProvider provider = (UtilizadoresActivosListDataProvider) tableRowGroup3.getSourceData();
        ArrayList list = (ArrayList) provider.getList();
        Utilizador u = (Utilizador)list.get(k);
        return u;
    }        
    

    public String lnkPorInactivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorInactivoRowData();  
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit");   
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    }

    public String lnkNomeInactivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorInactivoRowData(); 
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit");   
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    }
    
    public String lnkCategoriaInactivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorInactivoRowData(); 
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit");  
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    }   
    
    public String lnkEstabelecimentoInactivos_action() {
        // TODO: Replace with your code
        Utilizador u = getUtilizadorInactivoRowData(); 
        getSessionBean1().setEditUser(u);        
        getSessionBean1().setModoEdicaoUtilizador("edit");    
        getSessionBean1().setNavFrom("GestaoUtilizadores");        
        return "user_fields";
    }    
    
    private Utilizador getUtilizadorInactivoRowData()
    {
        RowKey rk = tableRowGroup1.getRowKey();
        int k = Integer.parseInt(rk.getRowId());        
        UtilizadoresInactivosListDataProvider provider = (UtilizadoresInactivosListDataProvider) tableRowGroup1.getSourceData();
        ArrayList list = (ArrayList) provider.getList();
        Utilizador u = (Utilizador)list.get(k);
        return u;
    }            


    public String lnkNewUser_action() {
        // TODO: Replace with your code
        
        return null;
    }

    public String butNovoUtilizador_action() {
        // TODO: Process the button click action. Return value is a navigation
        // case name where null will return to the same page.
        
        return "novo_utilizador";
    }

    public String lnkAnalisesAcidente_action() {
        // TODO: Replace with your code
        String nav_from = getSessionBean1().getNavFrom();
        Integer tipo_utilizador = getSessionBean1().getCurrentUser().getTipo();
        if(tipo_utilizador.intValue() == Global.TIPO_UTILIZADOR_DIRECTOR_SIPRP)
        {
            return "form_dir_siprp";
        }
        else if( tipo_utilizador.intValue() == Global.TIPO_UTILIZADOR_DIRECTOR_GERAL_RH )
        {
            return "form_dir_ger_rh";            
        }
        return null;
    }
}

