diff --git a/trunk/PlanosActuacao/src/planosactuacao/ApplicationBean1.java b/trunk/PlanosActuacao/src/planosactuacao/ApplicationBean1.java new file mode 100644 index 00000000..c1b27cb7 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/ApplicationBean1.java @@ -0,0 +1,151 @@ +/* + * ApplicationBean1.java + * + * Created on Aug 25, 2008, 11:20:16 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractApplicationBean; +import java.sql.Connection; +import javax.faces.FacesException; + +/** + *

Application scope data bean for your application. Create properties + * here to represent cached data that should be made available to all users + * and pages in the application.

+ * + *

An instance of this class will be created for you automatically, + * the first time your application evaluates a value binding expression + * or method binding expression that references a managed bean using + * this class.

+ * + * @author lluis + */ +public class ApplicationBean1 extends AbstractApplicationBean { + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + //
+ + private boolean timerStarted = false; + private Connection localConnection = null; + private Connection connection = null; + + /** + *

Construct a new application data bean instance.

+ */ + public ApplicationBean1() { + } + + /** + *

This method is called when this bean is initially added to + * application scope. Typically, this occurs as a result of evaluating + * a value binding or method binding expression, which utilizes the + * managed bean facility to instantiate this bean and store it into + * application scope.

+ * + *

You may customize this method to initialize and cache application wide + * data values (such as the lists of valid options for dropdown list + * components), or to allocate resources that are required for the + * lifetime of the application.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("ApplicationBean1 Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

This method is called when this bean is removed from + * application scope. Typically, this occurs as a result of + * the application being shut down by its owning container.

+ * + *

You may customize this method to clean up resources allocated + * during the execution of the init() method, or + * at any later time during the lifetime of the application.

+ */ + @Override + public void destroy() { + } + + /** + *

Return an appropriate character encoding based on the + * Locale defined for the current JavaServer Faces + * view. If no more suitable encoding can be found, return + * "UTF-8" as a general purpose default.

+ * + *

The default implementation uses the implementation from + * our superclass, AbstractApplicationBean.

+ */ + @Override + public String getLocaleCharacterEncoding() { + return super.getLocaleCharacterEncoding(); + } + + /** + * @return the timerStarted + */ + public boolean isTimerStarted() { + return timerStarted; + } + + /** + * @param timerStarted the timerStarted to set + */ + public void setTimerStarted(boolean timerStarted) { + this.timerStarted = timerStarted; + } + + /** + * @return the connection + */ + public Connection getConnection() { + return connection; + } + + /** + * @param connection the connection to set + */ + public void setConnection(Connection connection) { + this.connection = connection; + } + + public Connection getLocalConnection() { + return localConnection; + } + + /** + * @param connection the connection to set + */ + public void setLocalConnection(Connection connection) { + this.localConnection = connection; + } + +} diff --git a/trunk/PlanosActuacao/src/planosactuacao/Bundle.properties b/trunk/PlanosActuacao/src/planosactuacao/Bundle.properties new file mode 100644 index 00000000..57ed665a --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Bundle.properties @@ -0,0 +1,3 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + diff --git a/trunk/PlanosActuacao/src/planosactuacao/Dummy.java b/trunk/PlanosActuacao/src/planosactuacao/Dummy.java new file mode 100644 index 00000000..65b41af8 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Dummy.java @@ -0,0 +1,254 @@ +/* + * Dummy.java + * + * Created on Oct 6, 2008, 10:43:13 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractPageBean; + +import com.sun.webui.jsf.component.Hyperlink; +import db.entidades.Utilizador; +import db.providers.UtilizadoresDataProvider; +import java.util.List; +import java.util.ListIterator; +import javax.faces.FacesException; +import javax.faces.event.ActionEvent; + +/** + *

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.

+ * + * @author lluis + */ +public class Dummy extends AbstractPageBean +{ + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + private Hyperlink hyperlink1 = new Hyperlink(); + + public Hyperlink getHyperlink1() { + return hyperlink1; + } + + public void setHyperlink1(Hyperlink h) { + this.hyperlink1 = h; + } + private Hyperlink link = new Hyperlink(); + + public Hyperlink getLink() { + return link; + } + + public void setLink(Hyperlink h) { + this.link = h; + } + + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public Dummy() + { +// connect(); + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("Dummy Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() { + + //Verbatim verbatim = new Verbatim(); + //printUsers(); + + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() { + return (RequestBean1) getBean("RequestBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() { + return (SessionBean1) getBean("SessionBean1"); + } + + public String lnkAnaliseAcidentes_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + return null; + } + + public void lnk_actionListener(ActionEvent e) { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + System.out.print("DUMMY LINK"); + } + + + private void printUsers() + { +// UtilizadoresDataProvider udp = new UtilizadoresDataProvider(); + + try + { + UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); + + List< Utilizador > list = udp.getUtilizadoresList(); + ListIterator iter = list.listIterator(); + System.out.println("=================================================================================="); + System.out.println("LOGIN\tEMAIL\tTIPO\tESTABELECIMENTO\tRESP. LOJA\tACTIVO\tAPAGADO"); + while(iter.hasNext()) + { + Utilizador u = (Utilizador) iter.next(); + System.out.print(u.getLogin() + "\t"); + System.out.print(u.getEmail() + "\t"); + System.out.print(u.getTipo() + "\t"); + System.out.print(u.getEstabelecimento_id() + "\t"); + System.out.print(u.getResponsavel_loja() + "\t"); + System.out.print(u.getActivo() + "\t"); + System.out.print(u.getApagado() + "\t\n"); + } + System.out.println(""); + System.out.println("=================================================================================="); + } + catch(Exception ex) + { + ErrorLogger.logException( ex ); + } + } + +// private void connect() +// { +// db.Db db = new db.Db(); +// try +// { +// Connection connection = db.connect(); +// } +// catch(Exception ex) +// { +// getSessionBean1().setMsg("Erro na ligação à Base de Dados"); +// //***** terminate session +// try { +// getExternalContext().redirect("faces/Erro.jsp"); +// } catch(Exception e) { +// // . . . handle exception . . . +// ErrorLogger.logException( e ); +// } +// ErrorLogger.logException( ex ); +// } +// } + + public String butImage_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + +// FacesContext fc = getFacesContext(); +// Logos logos = new Logos(); +// String logourl = logos.getLogo(fc); +// if(logourl != null) +// { +// image1.setUrl(logourl); +// } + + return null; + } + +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/EditarPlano.java b/trunk/PlanosActuacao/src/planosactuacao/EditarPlano.java new file mode 100644 index 00000000..888a3d9a --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/EditarPlano.java @@ -0,0 +1,2400 @@ +/* + * PlanoActuacao.java + * + * Created on Aug 26, 2008, 3:10:59 PM + */ +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.evolute.utils.strings.StringPlainer; +import com.sun.rave.web.ui.appbase.AbstractPageBean; + +import com.sun.webui.jsf.component.Button; + +import com.sun.webui.jsf.component.Checkbox; +import com.sun.webui.jsf.component.DropDown; +import com.sun.webui.jsf.component.PanelGroup; +import com.sun.webui.jsf.component.StaticText; +import com.sun.webui.jsf.component.TextArea; +import com.sun.webui.jsf.component.TextField; + +import com.sun.webui.jsf.model.Option; +import db.entidades.Area; +import db.entidades.EstadoMedida; +import db.entidades.Medida; +import db.entidades.PlanoActuacao; +import db.entidades.PostoTrabalho; +import db.entidades.Risco; +import db.entidades.Utilizador; +import db.entidades.Valor; +import db.providers.PlanosDataProvider; +import db.providers.RiscoLogic; +import db.providers.UtilizadoresDataProvider; +import db.providers.UtilizadoresLogic; +import utils.Global; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import javax.el.MethodExpression; +import javax.faces.FacesException; +import javax.faces.component.html.HtmlInputHidden; +import javax.faces.component.html.HtmlPanelGrid; +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.event.MethodExpressionActionListener; +import javax.faces.event.ValueChangeEvent; +import mail.Mail; +import mail.MailNextPhase; +import mail.MailNextPhase.RESPONSAVEL_SEGURANCA_TO_DIRECTOR_LOJA; +import org.richfaces.component.html.HtmlCalendar; +import pagination.Pagina; +import pagination.Pagination; +import pagination.PaginationNormais; +import pagination.PaginationPatrimoniais; +import planosactuacao.SessionBean1.PAGINATION_ENUM; +import utils.JSFUtils; +import utils.Utils; + +/** + *

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.

+ * + * @author lluis + */ +public class EditarPlano extends AbstractPageBean +{ + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception + { + } + //
+// PlanosDataProvider pdp = new PlanosDataProvider(); + HtmlPanelGrid grid; + PanelGroup pg; + StaticText st; + private HtmlPanelGrid gridLayout = new HtmlPanelGrid(); + //Plano actuacao + PlanoActuacao plano; + //HtmlPanelGrid gridPlano = new HtmlPanelGrid(); + HtmlPanelGrid gridArea; + HtmlPanelGrid gridRisco; + HtmlPanelGrid gridValor; + HtmlPanelGrid gridMedida; + HtmlPanelGrid gridPosto; + HtmlPanelGrid gridResponsavel; + int risco_id = 0; + int medida_id = 0; + int posto_id = 0; + //page components + TextField txtResponsavelExecucao; + TextField txtPor; + TextArea txtRecursos; + + HtmlCalendar dtInicio; + HtmlCalendar dtFim; + + TextArea txtParecerDns; + TextArea txtParecerDl; + TextArea txtVerificacaoSiprp; + + public HtmlPanelGrid getGridLayout() + { + return gridLayout; + } + + public void setGridLayout( HtmlPanelGrid hpg ) + { + this.gridLayout = hpg; + } + private Button butGravarPlano = new Button(); + + public Button getButGravarPlano() + { + return butGravarPlano; + } + + public void setButGravarPlano( Button b ) + { + this.butGravarPlano = b; + } + + +// private Button butGravarRisco = new Button(); +// public Button getButGravarRisco() +// { +// return butGravarRisco; +// } +// public void setButGravarRisco( Button b ) +// { +// this.butGravarRisco = b; +// } + + + private Button butEnviar = new Button(); + + public Button getButEnviar() + { + return butEnviar; + } + + public void setButEnviar( Button b ) + { + this.butEnviar = b; + } + private Button butLimparDados = new Button(); + + public Button getButLimparDados() + { + return butLimparDados; + } + + public void setButLimparDados( Button b ) + { + this.butLimparDados = b; + } + private Button butCancelar = new Button(); + + public Button getButCancelar() + { + return butCancelar; + } + + public void setButCancelar( Button b ) + { + this.butCancelar = b; + } + private StaticText lblMsg = new StaticText(); + + public StaticText getLblMsg() + { + return lblMsg; + } + + public void setLblMsg( StaticText st ) + { + this.lblMsg = st; + } + private HtmlPanelGrid gridValidar = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridValidar() + { + return gridValidar; + } + + public void setGridValidar( HtmlPanelGrid hpg ) + { + this.gridValidar = hpg; + } + + + private StaticText labelCheckValidacao = new StaticText(); + + public StaticText getLabelCheckValidacao() + { + return labelCheckValidacao; + } + + public void setLabelCheckValidacao( StaticText labelCheckValidacao ) + { + this.labelCheckValidacao = labelCheckValidacao; + } + + private Checkbox chkValidacao = new Checkbox(); + + public Checkbox getChkValidacao() + { + return chkValidacao; + } + + public void setChkValidacao( Checkbox c ) + { + this.chkValidacao = c; + } + private Checkbox chkDesactivar = new Checkbox(); + + public Checkbox getChkDesactivar() + { + return chkDesactivar; + } + + public void setChkDesactivar( Checkbox c ) + { + this.chkDesactivar = c; + } + private HtmlInputHidden hidValidacao = new HtmlInputHidden(); + + public HtmlInputHidden getHidValidacao() + { + return hidValidacao; + } + + public void setHidValidacao( HtmlInputHidden hih ) + { + this.hidValidacao = hih; + } + private PanelGroup grpPagination = new PanelGroup(); + + public PanelGroup getGrpPagination() + { + return grpPagination; + } + + public void setGrpPagination( PanelGroup pg ) + { + this.grpPagination = pg; + } + private HtmlPanelGrid gridPagination = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridPagination() + { + return gridPagination; + } + + public void setGridPagination( HtmlPanelGrid hpg ) + { + this.gridPagination = hpg; + } + private Button butEnviarCorrecao = new Button(); + + public Button getButEnviarCorrecao() + { + return butEnviarCorrecao; + } + + public void setButEnviarCorrecao( Button b ) + { + this.butEnviarCorrecao = b; + } + private StaticText lblObs = new StaticText(); + + public StaticText getLblObs() + { + return lblObs; + } + + public void setLblObs( StaticText st ) + { + this.lblObs = st; + } + private HtmlPanelGrid gridPlano2 = new HtmlPanelGrid(); + + public HtmlPanelGrid getgridPlano2() + { + return gridPlano2; + } + + public void setgridPlano2( HtmlPanelGrid hpg ) + { + this.gridPlano2 = hpg; + } + private HtmlPanelGrid gridPlano = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridPlano() + { + return gridPlano; + } + + public void setGridPlano( HtmlPanelGrid hpg ) + { + this.gridPlano = hpg; + } + private HtmlPanelGrid gridValidacoes = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridValidacoes() + { + return gridValidacoes; + } + + public void setGridValidacoes( HtmlPanelGrid hpg ) + { + this.gridValidacoes = hpg; + } + private HtmlPanelGrid gridValidar2 = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridValidar2() + { + return gridValidar2; + } + + public void setGridValidar2( HtmlPanelGrid hpg ) + { + this.gridValidar2 = hpg; + } + private HtmlPanelGrid gridObservacoes = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridObservacoes() + { + return gridObservacoes; + } + + public void setGridObservacoes( HtmlPanelGrid hpg ) + { + this.gridObservacoes = hpg; + } + private StaticText stNomeEmpresa = new StaticText(); + + public StaticText getStNomeEmpresa() + { + return stNomeEmpresa; + } + + public void setStNomeEmpresa( StaticText st ) + { + this.stNomeEmpresa = st; + } + + /** + *

Construct a new Page bean instance.

+ */ + public EditarPlano() + { + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try + { + _init(); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + log( "PlanoActuacao Initialization Failure", e ); + throw e instanceof FacesException ? ( FacesException ) e : new FacesException( e ); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + Utilizador u = getSessionBean1().getCurrentUser(); + if ( u.getTipo().intValue() != Global.DIRECTOR_NACIONAL_SEGURANCA && u.getTipo().intValue() != Global.DIRECTOR_LOJA ) + { + butEnviarCorrecao.setStyleClass( "hidden" ); + } + + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() + { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() + { + FacesContext fc = getFacesContext(); + //boolean isPostback = JSFUtils.isPostBack12(fc); + //boolean isPostback = JSFUtils.isPostBack(fc); + boolean isPostback = JSFUtils.isPostback(); + System.out.println( "POSTBACK : " + isPostback ); + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + + System.out.println( "\nEditarPlano . prerender() : " + p.getId() + "\n" ); + + getRiscosByPlano( p ); + if ( !isPostback ) + { + //initializePlano(); + fillValoresHash( p ); + initialize( p ); + showPlano( p ); + //fillPlano(); + } + else + { + Boolean validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() == true ) + { + butEnviarCorrecao.setDisabled( true ); + butEnviar.setDisabled( false ); + } + else + { + butEnviarCorrecao.setDisabled( false ); + butEnviar.setDisabled( true ); + } + } + } + + if ( gridPagination.getChildCount() > 0 ) + { + gridPagination.getChildren().clear(); + } + setPagination( PAGINATION_ENUM.NORMAL ); + setPagination( PAGINATION_ENUM.PATRIMONIAIS ); + + if ( p.getCorrecao().matches( "y" ) ) + { + lblObs.setText( p.getObs_correcao() ); + } + + String errorMessage = getSessionBean1().getMsg(); + lblMsg.setText( ( errorMessage != null && ! "".equals( errorMessage.trim() ) ? "
" : "" ) + errorMessage ); + getSessionBean1().setMsg( "" ); + + if ( p != null ) + { + if ( p.getFase() != null && p.getFase().intValue() == Global.FASE_CONCLUIDO ) + { + butEnviar.setRendered( false ); + chkDesactivar.setRendered( false ); + chkValidacao.setRendered( false ); + labelCheckValidacao.setRendered( false ); + } + } + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() + { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() + { + return ( RequestBean1 ) getBean( "RequestBean1" ); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() + { + return ( SessionBean1 ) getBean( "SessionBean1" ); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() + { + return ( ApplicationBean1 ) getBean( "ApplicationBean1" ); + } + + public String hyperlink1_action() + { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + return "lista_planos"; + } + + private void initialize( PlanoActuacao p ) + { + Utilizador u = getSessionBean1().getCurrentUser(); + + Pagination paginationNormal = new PaginationNormais( p, u ); + Pagination paginationPatrimoniais = new PaginationPatrimoniais( p, u ); + getSessionBean1().addPagination( PAGINATION_ENUM.NORMAL, paginationNormal ); + getSessionBean1().addPagination( PAGINATION_ENUM.PATRIMONIAIS, paginationPatrimoniais ); + + if ( u.getTipo().intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA ) + { + hidValidacao.setValue( "dns" ); + } + else if ( u.getTipo().intValue() == Global.DIRECTOR_LOJA ) + { + hidValidacao.setValue( "dir_loja" ); + } + if ( u.getTipo().intValue() == Global.TECNICO_HS ) + { + hidValidacao.setValue( "hs" ); + } + if ( u.getTipo().intValue() != Global.DIRECTOR_LOJA && u.getTipo().intValue() != Global.DIRECTOR_NACIONAL_SEGURANCA + && u.getTipo().intValue() != Global.TECNICO_HS ) + { + gridValidar.setRendered( false ); + } + +// int fase = p.getFase().intValue(); + switch ( /*fase*/ getFasePlano() ) + { + case Global.FASE_SEGURANCA_PREENCHIMENTO: + if ( p.getObservacoes_dl() != null ) + { + if ( p.getObservacoes_dl().trim().length() > 0 ) + { + pg = new PanelGroup(); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DL: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getObservacoes_dl() ); + pg.getChildren().add( st ); + } + } + + if ( p.getObservacoes_dns() != null ) + { + if ( p.getObservacoes_dns().trim().length() > 0 ) + { + pg = new PanelGroup(); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DNS: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getObservacoes_dns() ); + pg.getChildren().add( st ); + } + } + + if ( p.getCorrecao().matches( "n" ) ) + { + butEnviar.setText( "Enviar a Director de Loja>>" ); + } + else + { + if ( p.getFase_antes_correcao().intValue() == Global.FASE_DIR_LOJA_VALIDACAO ) + { + butEnviar.setText( "Enviar a Director de Loja>>" ); + } + else if ( p.getFase_antes_correcao().intValue() == Global.FASE_DNS_PARECER ) + { + butEnviar.setText( "Enviar a Director Nacional Segurança>>" ); + } + } + + break; + + case Global.FASE_DIR_LOJA_VALIDACAO: + //butEnviar.setText("Enviar a Director de Loja"); + pg = new PanelGroup(); + pg.setId( "pgObsDl" ); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DL: " ); + pg.getChildren().add( st ); + TextArea txtObservacoesDl = new TextArea(); + txtObservacoesDl.setId( "txtObservacoesDl" ); + txtObservacoesDl.setColumns( Global.MAX_TEXTAREA_CHARS ); + txtObservacoesDl.setText( p.getObservacoes_dl() ); + pg.getChildren().add( txtObservacoesDl ); + + if ( p.getObservacoes_dns() != null ) + { + if ( p.getObservacoes_dns().trim().length() > 0 ) + { + pg = new PanelGroup(); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DNS: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getObservacoes_dns() ); + pg.getChildren().add( st ); + } + } + + if ( p.getValidacao_director_loja().booleanValue() == true ) + { + chkValidacao.setSelected( new Boolean( true ) ); + butEnviarCorrecao.setDisabled( true ); + butEnviar.setDisabled( false ); + } + else + { + butEnviarCorrecao.setDisabled( false ); + butEnviar.setDisabled( true ); + } + butEnviar.setText( "Enviar a Director Nacional Segurança>>" ); + + if ( p.getCorrecao().matches( "y" ) ) + { + butEnviar.setText( "Enviar a Director Nacional Segurança>>" ); + } + + break; + + case Global.FASE_DNS_PARECER: + if ( p.getObservacoes_dl() != null ) + { + if ( p.getObservacoes_dl().trim().length() > 0 ) + { + pg = new PanelGroup(); + pg.setId( "pgObsDl" ); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DL: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getObservacoes_dl() ); + pg.getChildren().add( st ); + } + } + + pg = new PanelGroup(); + pg.setId( "pgObsDns" ); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DNS: " ); + pg.getChildren().add( st ); + TextArea txtObservacoesDns = new TextArea(); + txtObservacoesDns.setId( "txtObservacoesDns" ); + txtObservacoesDns.setColumns( Global.MAX_TEXTAREA_CHARS ); + txtObservacoesDns.setText( p.getObservacoes_dns() ); + pg.getChildren().add( txtObservacoesDns ); + if ( p.getValidacao_dns().booleanValue() == true ) + { + chkValidacao.setSelected( new Boolean( true ) ); + butEnviarCorrecao.setDisabled( true ); + butEnviar.setDisabled( false ); + } + else + { + butEnviarCorrecao.setDisabled( false ); + butEnviar.setDisabled( true ); + } + + butEnviar.setText( "Enviar para Técnico de HS>>" ); + break; + + case Global.FASE_SIPRP_CONCLUSAO: + if ( p.getObservacoes_dl() != null ) + { + if ( p.getObservacoes_dl().trim().length() > 0 ) + { + pg = new PanelGroup(); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DL: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getObservacoes_dl() ); + pg.getChildren().add( st ); + } + } + + + if ( p.getObservacoes_dns() != null ) + { + if ( p.getObservacoes_dns().trim().length() > 0 ) + { + pg = new PanelGroup(); + gridObservacoes.getChildren().add( pg ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Observações gerais DNS: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getObservacoes_dns() ); + pg.getChildren().add( st ); + } + } + + if ( p.getValidacao_hs().booleanValue() == true ) + { + chkValidacao.setSelected( new Boolean( true ) ); + butEnviar.setDisabled( false ); + } + else + { + butEnviar.setDisabled( true ); + } + butEnviar.setText( "Concluir" ); + break; + } + + chkDesactivar.setSelected( Boolean.FALSE ); + gridLayout.getChildren().add( gridPlano ); + } + + private void showPlano( PlanoActuacao p ) + { + gridArea = new HtmlPanelGrid(); + gridArea.setId( "gridArea" ); + gridArea.setColumns( 1 ); + gridArea.setColumnClasses( "gridColCenter" ); + gridArea.setWidth( "100%" ); + gridArea.setStyle( "background-color: #f6f4e8; border: solid 1px #766c6c" ); + + gridPlano.getChildren().add( gridArea ); + + if ( p.getAreas().size() > 0 ) + { + Area a = p.getAreas().get( 0 ); + showArea( a ); + if ( a.getRiscos().size() > 0 ) + { + Risco r = a.getRiscos().get( 0 ); + showRisco( r ); + showValor( r ); + showResponsavel( r ); + } + } + showPreviousValidacoes( p ); + + Utilizador currentUser = getSessionBean1().getCurrentUser(); + if ( currentUser.getTipo().intValue() == Global.TECNICO_HS || currentUser.getTipo().intValue() == Global.DIRECTOR_SIPRP ) + { + chkDesactivar.setId( "chkDesactivarPlano" ); + chkDesactivar.setLabel( "Desactivar Plano" ); + chkDesactivar.setSelected( p.getConcluidoPorDesactivacao() ); + chkDesactivar.setStyle( "float: left;" ); + gridPlano.getChildren().add( chkDesactivar ); + } + } + + private void showArea( Area a ) + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Área: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( Utils.unicodeToHTML( a.getDescricao() ) ); + pg.getChildren().add( st ); + gridArea.getChildren().add( pg ); + } + + private void showRisco( Risco r ) + { + System.out.println( "\nEditarPlano . showRisco() : " + r.getId() + " - " + r.getDescricao() ); + + getSessionBean1().setCurrentRisco( r ); + + String riscoText = "Risco" + ( r.getIsPatrimonial() ? " Patrimonial: " : ": " ); + + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns( 1 ); + grd.setWidth( "100%" ); + + gridRisco = new HtmlPanelGrid(); + gridRisco.setWidth( "98%" ); + gridRisco.setColumns( 1 ); + gridRisco.setColumnClasses( "gridColLeft" ); + gridArea.getChildren().add( gridRisco ); + + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( riscoText ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getDescricao() ); + pg.getChildren().add( st ); + gridRisco.getChildren().add( pg ); + } + + private void showValores( Risco r ) + { + List valores = r.getValores(); + + for ( Valor v : valores ) + { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns( 1 ); + grd.setColumnClasses( "gridColLeft" ); + grd.setWidth( "100%" ); + + gridValor = new HtmlPanelGrid(); + gridRisco.getChildren().add( gridValor ); + gridValor.setWidth( "100%" ); + gridValor.setColumns( 1 ); + gridValor.setColumnClasses( "gridColLeft" ); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Valor: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( v.getValorQuantitativo().toString() ); + pg.getChildren().add( st ); + gridValor.getChildren().add( pg ); + + showMedidas( r ); + } + } + + private void showValor( Risco r ) + { + getSessionBean1().setCurrentRisco( r ); + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns( 1 ); + grd.setColumnClasses( "gridColLeft" ); + grd.setWidth( "100%" ); + + gridValor = new HtmlPanelGrid(); + gridRisco.getChildren().add( gridValor ); + gridValor.setWidth( "100%" ); + gridValor.setColumns( 1 ); + gridValor.setColumnClasses( "gridColLeft" ); + + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Valor: " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( RiscoLogic.getInstance().getValor( r ) ); + + pg.getChildren().add( st ); + gridValor.getChildren().add( pg ); + + showMedidas( r ); + } + + private void showMedidas( Risco r ) + { + List medidas = r.getMedidas(); + for ( Medida m : medidas ) + { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns( 1 ); + grd.setWidth( "100%" ); + grd.setStyleClass( "centerBlock" ); + gridValor.getChildren().add( grd ); + + gridMedida = new HtmlPanelGrid(); + gridMedida.setId( "gridMedida_" + m.getId() ); + gridMedida.setStyleClass( "centerBlock" ); + gridMedida.setWidth( "98%" ); + gridMedida.setColumns( 1 ); + gridMedida.setColumnClasses( "gridColLeft" ); + grd.getChildren().add( gridMedida ); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Medida:  " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( m.getDescricao() ); + pg.getChildren().add( st ); + gridMedida.getChildren().add( pg ); + + showPostos( m ); + + Utilizador u = getSessionBean1().getCurrentUser(); + if ( getFasePlano() == Global.FASE_SIPRP_CONCLUSAO ) + { + List opts = null; + try + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + opts = pdp.getEstadoMedidas(); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + + DropDown drop = new DropDown(); + Option opt[] = null; + if ( opts != null ) + { + opt = new Option[ ( opts.size() + 1 ) ]; + opt[ 0 ] = new Option( 0, "" ); + for ( int i = 0; i < opts.size(); i++ ) + { + EstadoMedida em = opts.get( i ); + opt[ ( i + 1 ) ] = new Option( em.getId(), em.getDescricao() ); + } + } + else + { + opt = new Option[ 1 ]; + opt[ 0 ] = new Option( 0, "" ); + } + drop.setItems( opt ); + + drop.setId( "drop_" + r.getId() + "_" + m.getId() ); + drop.setSelected( m.getValidarMedidaId() == null ? 0 : m.getValidarMedidaId() ); + + StaticText dropLabel = new StaticText(); + dropLabel.setText( "Validar Medida: " ); + + PanelGroup valPG = new PanelGroup(); + valPG.setId( "valPG_" + m.getId() ); + valPG.getChildren().add( dropLabel ); + valPG.getChildren().add( drop ); + gridMedida.getChildren().add( valPG ); + } + } + + } + + private void showPostos( Medida m ) + { + List postos = m.getPostos(); + for ( PostoTrabalho p : postos ) + { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns( 1 ); + grd.setWidth( "100%" ); + grd.setStyleClass( "centerBlock" ); + gridMedida.getChildren().add( grd ); + + gridPosto = new HtmlPanelGrid(); + gridPosto.setStyleClass( "centerBlock" ); + gridPosto.setWidth( "98%" ); + gridPosto.setColumns( 1 ); + gridPosto.setColumnClasses( "gridColLeft" ); + grd.getChildren().add( gridPosto ); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Posto de trabalho:  " ); + pg.getChildren().add( st ); + st = new StaticText(); + st.setEscape( false ); + st.setText( p.getDescricao() ); + pg.getChildren().add( st ); + gridPosto.getChildren().add( pg ); + } + } + + private void showResponsavel( Risco r ) + { + System.out.println( "RISCO : " + r.getDescricao() + " RESPONSAVEL : " + r.getResponsavel_execucao() ); + + Utilizador u = getSessionBean1().getCurrentUser(); + gridResponsavel = new HtmlPanelGrid(); + gridResponsavel.setId( "gridResponsavel" ); + gridResponsavel.setWidth( "100%" ); + gridResponsavel.setColumns( 1 ); + gridResponsavel.setColumnClasses( "gridColLeft" ); + gridArea.getChildren().add( gridResponsavel ); + + pg = new PanelGroup(); + pg.setId( "pgResponsavel" ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Responsável de execução:" ); + pg.getChildren().add( st ); + if ( u.getTipo().intValue() == Global.RESPONSAVEL_SEGURANCA ) + { + txtResponsavelExecucao = new TextField(); + txtResponsavelExecucao.setId( "txtResponsavel" ); + txtResponsavelExecucao.setColumns( 100 ); + txtResponsavelExecucao.setText( r.getResponsavel_execucao() ); + pg.getChildren().add( txtResponsavelExecucao ); + } + else + { + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getResponsavel_execucao() ); + pg.getChildren().add( st ); + } + + st = new StaticText(); + st.setEscape( false ); + st.setText( " " ); + pg.getChildren().add( st ); + + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( (u.getTipo().intValue() == Global.RESPONSAVEL_SEGURANCA ? "
" : "") + "POR:" ); + pg.getChildren().add( st ); + + if ( u.getTipo().intValue() == Global.RESPONSAVEL_SEGURANCA ) + { + txtPor = new TextField(); + txtPor.setId( "txtPor" ); + txtPor.setColumns( 20 ); + txtPor.setText( r.getPor() ); + pg.getChildren().add( txtPor ); + } + else + { + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getPor() ); + pg.getChildren().add( st ); + } + + gridResponsavel.getChildren().add( pg ); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Recursos necessários à implementação da medida: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + if ( u.getTipo().intValue() == Global.RESPONSAVEL_SEGURANCA ) + { + txtRecursos = new TextArea(); + txtRecursos.setId( "txtRecursos" ); + txtRecursos.setColumns( Global.MAX_TEXTAREA_CHARS ); + txtRecursos.setText( r.getRecursos_necessarios() ); + gridResponsavel.getChildren().add( txtRecursos ); + } + else + { + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getRecursos_necessarios() ); + pg.getChildren().add( st ); + } + + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns( 2 ); + grd.setColumnClasses( "gridCol15, gridCol85" ); + grd.setId( "gridDtInicio" ); + grd.setStyle( "width: 100%" ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Data prevista de início:" ); + grd.getChildren().add( st ); + if ( u.getTipo().intValue() == Global.RESPONSAVEL_SEGURANCA ) + { + dtInicio = new HtmlCalendar(); + dtInicio.setId( "dtInicio" ); + + dtInicio.setDatePattern( "dd-MM-yyyy" ); + dtInicio.setValue( r.getData_inicio() ); + java.util.GregorianCalendar gcalendar = new java.util.GregorianCalendar(); + gcalendar.set( 2000, 1, 1 ); + +// dtInicio.setMinDate( gcalendar.getTime() ); + grd.getChildren().add( dtInicio ); + } + else + { + if ( r.getData_inicio() != null ) + { + st = new StaticText(); + st.setEscape( false ); + SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy" ); + String data_str = formatter.format( r.getData_inicio() ); + st.setText( data_str ); + grd.getChildren().add( st ); + } + } + + gridResponsavel.getChildren().add( grd ); + + grd = new HtmlPanelGrid(); + grd.setColumns( 2 ); + grd.setColumnClasses( "gridCol15, gridCol85" ); + grd.setId( "gridDtFim" ); + grd.setStyle( "width: 100%" ); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Data prevista de conclusão:" ); + grd.getChildren().add( st ); + if ( u.getTipo().intValue() == Global.RESPONSAVEL_SEGURANCA ) + { + dtFim = new HtmlCalendar(); + + dtFim.setId( "dtFim" ); + dtFim.setDatePattern( "dd-MM-yyyy" ); + java.util.GregorianCalendar gcalendar1 = new java.util.GregorianCalendar(); + gcalendar1.set( 2099, 1, 1 ); +// dtFim.setMaxDate( gcalendar1.getTime() ); + dtFim.setValue( r.getData_fim() ); + grd.getChildren().add( dtFim ); + } + else + { + if ( r.getData_fim() != null ) + { + st = new StaticText(); + st.setEscape( false ); + SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy" ); + String data_str = formatter.format( r.getData_fim() ); + st.setText( data_str ); + grd.getChildren().add( st ); + } + } + + gridResponsavel.getChildren().add( grd ); + + if ( u.getTipo().intValue() != Global.DIRECTOR_LOJA ) + { + if ( r.getParecer_dl() != null ) + { + if ( r.getParecer_dl().trim().length() > 0 ) + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Parecer Director de Loja: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getParecer_dl() ); + pg.getChildren().add( st ); + } + } + } + else + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Parecer Director de Loja: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + + txtParecerDl = new TextArea(); + txtParecerDl.setId( "txtParecerDl" ); + txtParecerDl.setColumns( Global.MAX_TEXTAREA_CHARS ); + txtParecerDl.setText( r.getParecer_dl() ); + gridResponsavel.getChildren().add( txtParecerDl ); + } + + + if ( u.getTipo().intValue() != Global.DIRECTOR_NACIONAL_SEGURANCA ) + { + if ( r.getParecer_dns() != null ) + { + if ( r.getParecer_dns().trim().length() > 0 ) + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Parecer Director Nacional de Segurança: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getParecer_dns() ); + pg.getChildren().add( st ); + } + } + } + else + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Parecer Director Nacional de Segurança: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + + txtParecerDns = new TextArea(); + txtParecerDns.setId( "txtParecerDns" ); + txtParecerDns.setColumns( Global.MAX_TEXTAREA_CHARS ); + txtParecerDns.setText( r.getParecer_dns() ); + gridResponsavel.getChildren().add( txtParecerDns ); + } + + //Verificacao SIPRP + if ( u.getTipo().intValue() != Global.TECNICO_HS ) + { + if ( r.getVerificacao_siprp() != null ) + { + if ( r.getVerificacao_siprp().trim().length() > 0 ) + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Verificação SIPRP: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + + st = new StaticText(); + st.setEscape( false ); + st.setText( r.getVerificacao_siprp() ); + pg.getChildren().add( st ); + } + } + } + else + { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape( false ); + st.setStyleClass( "label" ); + st.setText( "Verificação SIPRP: " ); + pg.getChildren().add( st ); + gridResponsavel.getChildren().add( pg ); + + txtVerificacaoSiprp = new TextArea(); + txtVerificacaoSiprp.setId( "txtVerificacaoSiprp" ); + txtVerificacaoSiprp.setColumns( Global.MAX_TEXTAREA_CHARS ); + txtVerificacaoSiprp.setText( r.getVerificacao_siprp() ); + gridResponsavel.getChildren().add( txtVerificacaoSiprp ); + } + + } + + private void showPreviousValidacoes( PlanoActuacao p ) + { + Utilizador u = getSessionBean1().getCurrentUser(); + int tipo = u.getTipo().intValue(); + + switch ( tipo ) + { + case Global.DIRECTOR_NACIONAL_SEGURANCA: + if ( p.getValidacao_director_loja().booleanValue() ) + { + StaticText st = new StaticText(); + st.setEscape( false ); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID( p.getUser_dir_loja() ); + st.setText( "Validado por " + nome + " (Director de Loja) a " + p.getData_validacao_dir_loja_str() ); + gridValidacoes.getChildren().add( st ); + } + break; + case Global.TECNICO_HS: + if ( p.getValidacao_director_loja().booleanValue() ) + { + StaticText st = new StaticText(); + st.setEscape( false ); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID( p.getUser_dir_loja() ); + st.setText( "Validado por " + nome + " (Director de Loja) a " + p.getData_validacao_dir_loja_str() ); + gridValidacoes.getChildren().add( st ); + } + + if ( p.getValidacao_dns().booleanValue() ) + { + StaticText st = new StaticText(); + st.setEscape( false ); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID( p.getUser_dns() ); + st.setText( "Validado por " + nome + " (Director Nacional de Segurança) a " + p.getData_validacao_dns_str() ); + gridValidacoes.getChildren().add( st ); + } + break; + } + } + private static final int MAX_PAGES_PER_LINE = 20; + + private void setPagination( PAGINATION_ENUM type ) + { + Class[] argtypes = new Class[ 1 ]; + argtypes[ 0] = ActionEvent.class; + MethodExpression me = ( MethodExpression ) this.getApplication().getExpressionFactory().createMethodExpression( + getFacesContext().getELContext(), "#{EditarPlano.paginacao_actionListener}", null, argtypes ); + + StaticText typeLabel = new StaticText(); + typeLabel.setText( type.getType() + ":" ); + gridPagination.getChildren().add( typeLabel ); + + PanelGroup group = new PanelGroup(); + + Risco currentRisco = getSessionBean1().getCurrentRisco(); + Pagination pagination = getSessionBean1().getPagination( type ); + List paginas = pagination.getPages( currentRisco ); + + for ( int p = 0; p < paginas.size(); p++ ) + { + Pagina pagina = paginas.get( p ); + + if ( p > 0 && p % MAX_PAGES_PER_LINE == 0 ) + { + gridPagination.getChildren().add( group ); + group = new PanelGroup(); + } + + if ( pagina.isPrevious() ) + { + pagina.addActionListener( new MethodExpressionActionListener( me ) ); + pagina.setPaginationType( type ); + group.getChildren().add( pagina ); + st = new StaticText(); + st.setEscape( false ); + st.setText( " " ); + group.getChildren().add( st ); + } + else if ( pagina.isNext() ) + { + st = new StaticText(); + st.setEscape( false ); + st.setText( " " ); + group.getChildren().add( st ); + pagina.addActionListener( new MethodExpressionActionListener( me ) ); + pagina.setPaginationType( type ); + group.getChildren().add( pagina ); + } + else + { + pagina.addActionListener( new MethodExpressionActionListener( me ) ); + pagina.setPaginationType( type ); + group.getChildren().add( pagina ); + if ( pagina.getPageNumber().intValue() < pagination.getTotalPages() ) + { + st = new StaticText(); + st.setEscape( false ); + st.setText( " | " ); + group.getChildren().add( st ); + } + } + } + + gridPagination.getChildren().add( group ); + } + + private int getFasePlano() + { + int result = -1; + + Utilizador user = getSessionBean1().getCurrentUser(); + Integer tipo = user.getTipo(); + int tipoUser = tipo == null ? -1 : tipo.intValue(); + + PlanoActuacao planoActuacao = getSessionBean1().getPlanoActuacao(); + Integer fase = planoActuacao.getFase(); + result = fase.equals( Global.FASE_CONCLUIDO ) && ( tipoUser == Global.TECNICO_HS || tipoUser == Global.DIRECTOR_SIPRP ) ? + Global.FASE_SIPRP_CONCLUSAO : fase.intValue(); + + return result; + } + + public String butGravarPlano_action() + { + String page = null; + try + { + page = gravarPlano(); + getSessionBean1().setMsg( "Os dados do Plano de Actuação foram guardados" ); + } + catch ( Exception ex ) + { + ErrorLogger.logException( new Exception( "Erro na gravacao do plano!" ) ); + ErrorLogger.logException( ex ); + getSessionBean1().setMsg( "Erro na gravação do plano!" ); + } + + return page; + } + + private String gravarPlano() throws Exception + { + String returnToPage = null; + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + int fase = p.getFase().intValue(); + switch ( fase ) + { + case Global.FASE_DIR_LOJA_VALIDACAO: + PanelGroup pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDl" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDl" ); + if ( txtObs != null ) + { + p.setObservacoes_dl( "" ); + if ( txtObs.getText() != null ) + { + p.setObservacoes_dl( ( String ) txtObs.getText() ); + } + } + } + + + Boolean validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() ) + { + p.setValidacao_director_loja( new Boolean( true ) ); + } + } + break; + + case Global.FASE_DNS_PARECER: + pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDns" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDns" ); + if ( txtObs != null ) + { + p.setObservacoes_dns( "" ); + if ( txtObs.getText() != null ) + { + p.setObservacoes_dns( ( String ) txtObs.getText() ); + } + } + } + + validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() ) + { + p.setValidacao_dns( new Boolean( true ) ); + } + } + break; + + case Global.FASE_SIPRP_CONCLUSAO: + validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() ) + { + p.setValidacao_hs( new Boolean( true ) ); + } + } + } + + Utilizador currentUser = getSessionBean1().getCurrentUser(); + if ( currentUser.getTipo().intValue() == Global.TECNICO_HS || currentUser.getTipo().intValue() == Global.DIRECTOR_SIPRP ) + { + Checkbox chkD = ( Checkbox ) gridPlano.findComponent( "form1:chkDesactivarPlano" ); + if ( chkD != null ) + { + Boolean desactivar = ( Boolean ) chkD.getSelected(); + if ( desactivar != null && desactivar ) + { + p.setFase( Global.FASE_CONCLUIDO ); + p.setConcluidoPorDesactivacao( Boolean.TRUE ); + returnToPage = "lista_planos"; + } + } + } + + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + pdp.updatePlano( p ); + + //Valor curValor = getSessionBean1().getCurrentValor(); + Risco curValor = getSessionBean1().getCurrentRisco(); + curValor = fillValorFields( curValor ); +// getSessionBean1().getValoresHash().remove(curValor.getId()); +// getSessionBean1().getValoresHash().put(curValor.getId(), curValor); + getSessionBean1().getRiscosHash().remove( curValor.getId() ); + getSessionBean1().getRiscosHash().put( curValor.getId(), curValor ); + +// HashMap valores = getSessionBean1().getValoresHash(); +// Iterator iter = valores.keySet().iterator(); +// while(iter.hasNext()) +// { +// Integer id = iter.next(); +// Valor v = valores.get(id); +// pdp.updateValor(v); +// } + + HashMap valores = getSessionBean1().getRiscosHash(); + Iterator iter = valores.keySet().iterator(); + while ( iter.hasNext() ) + { + Integer id = iter.next(); + Risco r = valores.get( id ); + pdp.updateRisco( r ); + + if ( getFasePlano() == Global.FASE_SIPRP_CONCLUSAO ) + { + pdp.updateMedidas( r ); + } + } + + return returnToPage; + } + + public String butGravarRisco_action() + { + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + int fase = p.getFase().intValue(); + switch ( fase ) + { + case Global.FASE_DIR_LOJA_VALIDACAO: + PanelGroup pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDl" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDl" ); + if ( txtObs != null ) + { + p.setObservacoes_dl( "" ); + if ( txtObs.getText() != null ) + { + p.setObservacoes_dl( ( String ) txtObs.getText() ); + } + } + } + + Boolean validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() ) + { + p.setValidacao_director_loja( new Boolean( true ) ); + } + } + break; + + case Global.FASE_DNS_PARECER: + pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDns" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDns" ); + if ( txtObs != null ) + { + p.setObservacoes_dns( "" ); + if ( txtObs.getText() != null ) + { + p.setObservacoes_dns( ( String ) txtObs.getText() ); + } + } + } + + validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() ) + { + p.setValidacao_dns( new Boolean( true ) ); + } + } + break; + + case Global.FASE_SIPRP_CONCLUSAO: + validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao != null ) + { + if ( validacao.booleanValue() ) + { + p.setValidacao_hs( new Boolean( true ) ); + } + } + break; + } + + try + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + pdp.updatePlano( p ); + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + + try + { + Risco r = getSessionBean1().getCurrentRisco(); + r = fillValorFields( r ); + + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + pdp.updateRisco( r ); + +// if ( fase == Global.FASE_SIPRP_CONCLUSAO ) + if ( getFasePlano() == Global.FASE_SIPRP_CONCLUSAO ) + { + pdp.updateMedidas( r ); + } + getSessionBean1().getRiscosHash().remove( r.getId() ); + getSessionBean1().getRiscosHash().put( r.getId(), r ); + +// Pagination pagination = getSessionBean1().getPagination(); + Pagination pagination = getSessionBean1().getPagination( r.getIsPatrimonial() ? PAGINATION_ENUM.PATRIMONIAIS : PAGINATION_ENUM.NORMAL ); + + r = pagination.getNextRisco(); + Area a = getSessionBean1().getAreasHash().get( r.getArea_id() ); + if ( r != null ) + { + gridArea = ( HtmlPanelGrid ) gridPlano.findComponent( "form1:gridArea" ); + if ( gridArea.getChildren() != null ) + { + gridArea.getChildren().clear(); + } + showArea( a ); + showRisco( r ); + showValor( r ); + showResponsavel( r ); + } + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + return null; + } + +// private void fillPlanoFields() +// { +// PlanoActuacao p = getSessionBean1().getPlanoActuacao(); +// +// int fase = p.getFase().intValue(); +// switch(fase) +// { +// case Global.FASE_DIR_LOJA_VALIDACAO: +// Boolean validacao = (Boolean)chkValidacao.getSelected(); +// p.setValidacao_hs(validacao); +// +// TextArea txtObs = (TextArea) pg.findComponent("txtObservacoesDl"); +// if(txtObs != null) +// { +// if(txtObs.getText() != null) +// { +// p.setObservacoes_dl((String) txtObs.getText()); +// } +// } +// break; +// +// case Global.DIRECTOR_NACIONAL_SEGURANCA: +// validacao = (Boolean)chkValidacao.getSelected(); +// p.setValidacao_hs(validacao); +// +// txtObs = (TextArea) pg.findComponent("txtObservacoesDns"); +// if(txtObs != null) +// { +// if(txtObs.getText() != null) +// { +// p.setObservacoes_dns((String) txtObs.getText()); +// } +// } +// break; +// +// case Global.FASE_SIPRP_CONCLUSAO: +// validacao = (Boolean)chkValidacao.getSelected(); +// p.setValidacao_hs(validacao); +// break; +// +// +// } +// } +// private Valor fillValorFields(Valor v) + private Risco fillValorFields( Risco r ) + { + //gridPlano = (HtmlPanelGrid) gridLayout.findComponent("form1:gridPlano"); + gridArea = ( HtmlPanelGrid ) gridPlano.findComponent( "form1:gridArea" ); + gridResponsavel = ( HtmlPanelGrid ) gridArea.findComponent( "form1:gridResponsavel" ); + + TextField txtResponsavel = ( TextField ) gridResponsavel.findComponent( "form1:pgResponsavel:txtResponsavel" ); + if ( txtResponsavel != null ) + { + if ( txtResponsavel.getText() != null ) + { + r.setResponsavel_execucao( ( String ) txtResponsavel.getText() ); + } + } + + TextField txtPor = ( TextField ) gridResponsavel.findComponent( "form1:pgResponsavel:txtPor" ); + if ( txtPor != null ) + { + if ( txtPor.getText() != null ) + { + r.setPor( ( String ) txtPor.getText() ); + } + } + + TextArea txtRecursos = ( TextArea ) gridResponsavel.findComponent( "form1:txtRecursos" ); + if ( txtRecursos != null ) + { + if ( txtRecursos.getText() != null ) + { + r.setRecursos_necessarios( ( String ) txtRecursos.getText() ); + } + } + + HtmlCalendar dtInicio = ( HtmlCalendar ) gridResponsavel.findComponent( "form1:dtInicio:" ); + if ( dtInicio != null ) + { + Object value = dtInicio.getValue(); + Date currentDate = value instanceof Date ? ( Date ) value : null; + + r.setData_inicio( currentDate ); +// r.setData_inicio( dtInicio.getSelectedDate() ); + } + + HtmlCalendar dtFim = ( HtmlCalendar ) gridResponsavel.findComponent( "form1:dtFim" ); + if ( dtFim != null ) + { + Object value = dtFim.getValue(); + Date currentDate = value instanceof Date ? ( Date ) value : null; + + r.setData_fim( currentDate ); +// r.setData_fim( dtFim.getSelectedDate() ); + } + + TextArea txtParecerDl = ( TextArea ) gridResponsavel.findComponent( "form1:txtParecerDl" ); + if ( txtParecerDl != null ) + { + if ( txtParecerDl.getText() != null ) + { + r.setParecer_dl( ( String ) txtParecerDl.getText() ); + } + } + + TextArea txtParecerDns = ( TextArea ) gridResponsavel.findComponent( "form1:txtParecerDns" ); + if ( txtParecerDns != null ) + { + if ( txtParecerDns.getText() != null ) + { + r.setParecer_dns( ( String ) txtParecerDns.getText() ); + } + } + + TextArea txtVerificacaoSiprp = ( TextArea ) gridResponsavel.findComponent( "form1:txtVerificacaoSiprp" ); + if ( txtVerificacaoSiprp != null ) + { + if ( txtVerificacaoSiprp.getText() != null ) + { + r.setVerificacao_siprp( ( String ) txtVerificacaoSiprp.getText() ); + } + } + + if ( getFasePlano() == Global.FASE_SIPRP_CONCLUSAO ) + { + for ( Medida m : r.getMedidas() ) + { + gridMedida = ( HtmlPanelGrid ) gridArea.findComponent( "form1:gridMedida_" + m.getId() ); + if ( gridMedida != null ) + { + PanelGroup gridValPG = ( PanelGroup ) gridMedida.findComponent( "valPG_" + m.getId() ); + if ( gridValPG != null ) + { + DropDown drop = ( DropDown ) gridValPG.findComponent( "drop_" + r.getId() + "_" + m.getId() ); + if ( drop != null ) + { + Integer optID = ( Integer ) drop.getSelected(); + m.setValidarMedidaId( optID.intValue() == 0 ? null : optID ); + } + } + } + } + } + + return r; + } + + public String butEnviar_action() + { + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + + if ( planoValidationOk( p ) ) + { + Risco curValor = getSessionBean1().getCurrentRisco(); + curValor = fillValorFields( curValor ); + getSessionBean1().getRiscosHash().remove( curValor.getId() ); + getSessionBean1().getRiscosHash().put( curValor.getId(), curValor ); + if ( ! checkCamposObrigatorios() ) + { + getSessionBean1().setMsg( "Faltam preencher alguns riscos/valor. Por favor preencha todos os campos antes de prosseguir" ); + return null; + } + try //save current valor + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + + HashMap valores = getSessionBean1().getRiscosHash(); + Iterator iter = valores.keySet().iterator(); + while ( iter.hasNext() ) + { + Integer id = iter.next(); + Risco r = valores.get( id ); + pdp.updateRisco( r ); + } + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + try + { + processEnviar( p ); + return "lista_planos"; + } + catch ( Exception ex ) + { + getSessionBean1().setMsg( "Erro no envio do Plano" ); + ErrorLogger.logException( ex ); + } + } + + return null; + } + + private boolean planoValidationOk( PlanoActuacao p ) + { + boolean ok = true; + boolean processo_validado = true; + int dns_next_fase = 2; + + int fase = p.getFase().intValue(); + p.setFase_anterior( new Integer( fase ) ); + switch ( fase ) + { + case Global.FASE_SEGURANCA_PREENCHIMENTO: + gridArea = ( HtmlPanelGrid ) gridPlano.findComponent( "form1:gridArea" ); + gridResponsavel = ( HtmlPanelGrid ) gridArea.findComponent( "form1:gridResponsavel" ); + HtmlPanelGrid gridDtInicio = ( HtmlPanelGrid ) gridResponsavel.findComponent( "form1:gridDtInicio" ); + HtmlCalendar calDtInicio = ( HtmlCalendar ) gridDtInicio.findComponent( "form1:dtInicio" ); + HtmlPanelGrid gridDtFim = ( HtmlPanelGrid ) gridResponsavel.findComponent( "form1:gridDtFim" ); + HtmlCalendar calDtFim = ( HtmlCalendar ) gridDtFim.findComponent( "form1:dtFim" ); +// Date dtInicio = calDtInicio.getSelectedDate(); + Date dataInicio = ( Date ) calDtInicio.getValue(); +// Date dtFim = calDtFim.getSelectedDate(); + Date dataFim = ( Date ) calDtFim.getValue(); + if ( dataInicio != null && dataFim != null ) + { + if ( dataInicio.after( dataFim ) ) + { + getSessionBean1().setMsg( "Data Início não pode ser superior à data fim!" ); + ok = false; + } + else + { + fase++; + } + } + if ( ok ) + { + p.setData_validacao_seg( new Date() ); + p.setUser_seg( getSessionBean1().getCurrentUser().getId() ); + } + + break; + + case Global.FASE_SIPRP_CONCLUSAO: + Boolean validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao == null ) + { + processo_validado = false; + ok = false; + } + else + { + processo_validado = false; + if ( validacao.booleanValue() ) + { + processo_validado = true; + p.setValidacao_hs( new Boolean( true ) ); + Date today = new Date(); + p.setData_validacao_hs( today ); + p.setUser_hs( getSessionBean1().getCurrentUser().getId() ); + } + } + + if ( processo_validado ) + { + fase++; + } + else + { + getSessionBean1().setMsg( "É necessário validar o processo antes de dar seguimento para a fase seguinte!" ); + ok = false; + } + break; + + case Global.FASE_DIR_LOJA_VALIDACAO: + validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao == null ) + { + processo_validado = false; + } + else + { + processo_validado = false; + if ( validacao.booleanValue() ) + { + processo_validado = true; + p.setValidacao_director_loja( new Boolean( true ) ); + p.setData_validacao_dir_loja( new Date() ); + p.setUser_dir_loja( getSessionBean1().getCurrentUser().getId() ); + + PanelGroup pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDl" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDl" ); + if ( txtObs != null ) + { + p.setObservacoes_dl( "" ); + if ( txtObs.getText() != null ) + { + p.setObservacoes_dl( ( String ) txtObs.getText() ); + } + } + } + + } + } + + if ( processo_validado ) + { + fase++; + } + else + { + fase = Global.FASE_SEGURANCA_PREENCHIMENTO; //fase 2 + } + break; + + case Global.FASE_DNS_PARECER: + validacao = ( Boolean ) chkValidacao.getSelected(); + if ( validacao == null ) + { + processo_validado = false; + } + else + { + processo_validado = false; + if ( validacao.booleanValue() ) + { + processo_validado = true; + p.setValidacao_dns( new Boolean( true ) ); + Date today = new Date(); + p.setData_validacao_dns( today ); + p.setUser_dns( getSessionBean1().getCurrentUser().getId() ); + + PanelGroup pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDns" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDns" ); + if ( txtObs != null ) + { + p.setObservacoes_dns( "" ); + if ( txtObs.getText() != null ) + { + p.setObservacoes_dns( ( String ) txtObs.getText() ); + } + } + } + } + } + + if ( processo_validado ) + { + fase++; + } + else + { + getSessionBean1().setMsg( "É necessário validar o processo antes de dar seguimento para a fase seguinte!" ); + ok = false; + } + break; + } + + if ( ok ) + { + if ( p.getCorrecao().matches( "y" ) ) + { + fase = p.getFase_antes_correcao().intValue(); + p.setCorrecao( "n" ); + p.setObs_correcao( "" ); + } + p.setFase( new Integer( fase ) ); + } + + return ok; + } + + private boolean checkCamposObrigatorios() + { + boolean result = true; + + Utilizador user = getSessionBean1().getCurrentUser(); + + HashMap< Integer, Risco > valores = getSessionBean1().getRiscosHash(); + Iterator< Integer > iter = valores.keySet().iterator(); + while ( result && iter.hasNext() ) + { + Risco risco = valores.get( iter.next() ); + result = RiscoLogic.getInstance().isRiscoTratado( risco, user, false ); + } + return result; + } + + private void processEnviar( PlanoActuacao p ) throws Exception + { + p.setObs_correcao( "" ); + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + pdp.updatePlano( p ); + enviarMail( p ); + } + + private void enviarMail( PlanoActuacao p ) + { + Mail mail = new Mail(); + String assunto = ""; + String mail_text = ""; + + int fase = p.getFase().intValue(); + int tipo_utilizador = 0; + switch ( fase ) + { + case Global.FASE_SEGURANCA_PREENCHIMENTO : + if ( p.getFase_anterior() == null ) + { + assunto = "PLANOS - SEGURANCA (PREENCHIMENTO) - " + p.getData_visita_str() + " - " + p.getNome_estabelecimento(); + mail_text = "Notifica-se que o Plano passou para a fase Segurançãa(Preenchimento)"; + } + else + { + switch ( p.getFase_anterior().intValue() ) + { + case Global.FASE_DIR_LOJA_VALIDACAO: + tipo_utilizador = Global.DIRECTOR_LOJA; + assunto = "Plano de Actuacao da Avaliacao de Riscos de " + p.getData_visita_str() + " - " + p.getNome_estabelecimento() + " - Pedido de Correccao"; + mail_text = "

Exmo. (a) Senhor (a),

"; + mail_text += "

O Plano de Actuação referente à auditoria de Avaliação de Riscos Laborais realizada no passado dia " + p.getData_visita_str() + " foi devolvido para correcção.

"; + mail_text += "

Proceda, por favor, em www.siprp.com à(s) respectiva(s) correcção(ões) de acordo com as indicações e volte a reenviar o processo para a fase seguinte.

"; + mail_text += "

Caso tenha alguma dúvida ou necessite de qualquer esclarecimento, contacte, por favor, a Área Técnica da SIPRP através do telefone 213 504 540.

"; + mail_text += "

Cumprimentos,

"; + mail_text += "

A equipa da SIPRP

"; + mail_text += "

Por favor não responda a esta mensagem, dado tratar-se de um e-mail automático

"; + break; + } + } + break; + + case Global.FASE_DIR_LOJA_VALIDACAO : // RS para DL + { + tipo_utilizador = Global.DIRECTOR_LOJA; + MailNextPhase nextPhase = new RESPONSAVEL_SEGURANCA_TO_DIRECTOR_LOJA( p ); + assunto = nextPhase.getSubject(); + mail_text = nextPhase.getBody(); + break; + } + case Global.FASE_DNS_PARECER : // DL para DNS + { + tipo_utilizador = Global.DIRECTOR_NACIONAL_SEGURANCA; + MailNextPhase nextPhase = new MailNextPhase.DIRECTOR_LOJA_TO_DIRECTOR_NACIONAL_SEGURANCA( p ); + assunto = nextPhase.getSubject(); + mail_text = nextPhase.getBody(); + break; + } + case Global.FASE_SIPRP_CONCLUSAO : + tipo_utilizador = Global.TECNICO_HS; + assunto = "Plano de Actuacao da Avaliacao de Riscos de " + p.getData_visita_str() + " - " + p.getNome_estabelecimento(); + mail_text = "

Exmo. (a) Senhor (a),

"; + mail_text += "

Encontra-se disponível em www.siprp.com o Plano de Actuação referente à auditoria de Avaliação de Riscos Laborais realizada no passado dia " + p.getData_visita_str() + " para que possa efectuar a sua verificação.

"; + mail_text += "

Por favor não responda a esta mensagem, dado tratar-se de um e-mail automático

"; + break; + + case Global.FASE_CONCLUIDO : + assunto = "Plano de Actuacao da Avaliacao de Riscos de " + p.getData_visita_str() + " - " + p.getNome_estabelecimento() + " - Processo finalizado"; + mail_text = "

Exmo. (a) Senhor (a),

"; + mail_text += "

Encontra-se disponível em www.siprp.com o Plano de Actuação referente à auditoria de Avaliação de Riscos Laborais realizada no passado dia " + p.getData_visita_str() + " finalizado após verificação pelos Técnicos Superiores de Higiene e Segurança da SIPRP.

"; + mail_text += "

Aproveitamos para agradecer toda a disponibilidade e ficamos ao vosso dispor, caso tenha alguma dúvida ou necessite de qualquer esclarecimento, através do telefone 213 504 540.

"; + mail_text += "

Cumprimentos,

"; + mail_text += "

Por favor não responda a esta mensagem, dado tratar-se de um e-mail automático

"; + break; + } + assunto = StringPlainer.convertString( assunto, true, false ); + if ( fase < Global.FASE_CONCLUIDO ) + { + String responsavel_loja = "n"; + if ( tipo_utilizador == Global.RESPONSAVEL_SEGURANCA ) + { + responsavel_loja = "y"; + } + try + { + UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); + List list = udp.getUtilizadoresListByTipo( tipo_utilizador, responsavel_loja, p.getEstabelecimento_id() ); + ListIterator iter = list.listIterator(); + while ( iter.hasNext() ) + { + Utilizador u = ( Utilizador ) iter.next(); + System.out.println( "\nUSER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail() ); + try + { + mail.send( u.getEmail(), Mail.ENDERECO_ENVIO, assunto, mail_text ); + System.out.println( "\tEMAIL ENVIADO !!" ); + } + catch ( Exception ex1 ) + { + ErrorLogger.logException( ex1 ); + System.out.println( "\tMAIL ERROR : " + ex1.getMessage() ); + } + + } + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + } + else //fase concluido + { + int[] users = new int[] { Global.RESPONSAVEL_SEGURANCA, Global.DIRECTOR_LOJA, Global.DIRECTOR_NACIONAL_SEGURANCA }; + for ( int i = 0; i < users.length; i++ ) + { + tipo_utilizador = users[i]; + + String responsavel_loja = "n"; + if ( tipo_utilizador == Global.RESPONSAVEL_SEGURANCA ) + { + responsavel_loja = "y"; + } + try + { + UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); + List list = udp.getUtilizadoresListByTipo( tipo_utilizador, responsavel_loja, p.getEstabelecimento_id() ); + ListIterator iter = list.listIterator(); + while ( iter.hasNext() ) + { + Utilizador u = ( Utilizador ) iter.next(); + System.out.println( "\nUSER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail() ); + try + { + mail.send( u.getEmail(), Mail.ENDERECO_ENVIO, assunto, mail_text ); + System.out.println( "\tEMAIL ENVIADO !!" ); + } + catch ( Exception ex1 ) + { + ErrorLogger.logException( ex1 ); + System.out.println( "\tMAIL ERROR : " + ex1.getMessage() ); + } + + } + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + + } + } + } + + public void chkValidacao_processValueChange( ValueChangeEvent event ) + { +// if(chkValidacao.getSelected() != null) +// { +// Boolean selected = (Boolean) chkValidacao.getSelected(); +// if(selected.booleanValue()) +// { +// //txtParecer.setRendered(true); +// gridParecer.setStyleClass("visible"); +// } +// else +// { +// //txtParecer.setRendered(false); +// gridParecer.setStyleClass("hidden"); +// } +// } +// else +// { +// //txtParecer.setRendered(false); +// gridParecer.setStyleClass("hidden"); +// } + } + + public void drpIrPara_processValueChange( ValueChangeEvent event ) + { + + } + + private void getRiscosByPlano( PlanoActuacao p ) + { + HashMap areasHash = new HashMap(); + HashMap riscosHash = new HashMap(); + + for ( Area a : p.getAreas() ) + { + areasHash.put( a.getId(), a ); + for ( Risco r : a.getRiscos() ) + { + riscosHash.put( r.getId(), r ); + } + } + + getSessionBean1().setAreasHash( areasHash ); + getSessionBean1().setRiscosHash( riscosHash ); + } + + private void fillValoresHash( PlanoActuacao p ) + { + HashMap riscosHash = new HashMap(); + for ( Area a : p.getAreas() ) + { + for ( Risco r : a.getRiscos() ) + { +// for(Valor v : r.getValores()) +// { +// valoresHash.put(v.getId(), v); +// } + riscosHash.put( r.getId(), r ); + } + } + //getSessionBean1().setValoresHash(valoresHash); + getSessionBean1().setRiscosHash( riscosHash ); + } + + public void paginacao_actionListener( ActionEvent e ) + { + Risco curValor = getSessionBean1().getCurrentRisco(); + curValor = fillValorFields( curValor ); + getSessionBean1().getRiscosHash().remove( curValor.getId() ); + getSessionBean1().getRiscosHash().put( curValor.getId(), curValor ); + + gridArea = ( HtmlPanelGrid ) gridPlano.findComponent( "form1:gridArea" ); + if ( gridArea.getChildren() != null ) + { + gridArea.getChildren().clear(); + } + Pagina pagina = ( Pagina ) e.getSource(); + PAGINATION_ENUM type = pagina.getPaginationType(); + +// Pagination pagination = getSessionBean1().getPagination(); + Pagination pagination = getSessionBean1().getPagination( type ); + if ( pagination != null ) + { + Risco r = pagination.getRisco( pagina ); + r = getSessionBean1().getRiscosHash().get( r.getId() ); + + Area a = getSessionBean1().getAreasHash().get( r.getArea_id() ); + showArea( a ); + showRisco( r ); + showValor( r ); + showResponsavel( r ); + } + } + + public String butCancelar_action() + { + return "lista_planos"; + } + + public String butLimparDados_action() + { + gridArea = ( HtmlPanelGrid ) gridPlano.findComponent( "form1:gridArea" ); + gridResponsavel = ( HtmlPanelGrid ) gridArea.findComponent( "form1:gridResponsavel" ); + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + int fase = p.getFase().intValue(); + switch ( fase ) + { + case Global.FASE_SEGURANCA_PREENCHIMENTO: + TextField txtResponsavel = ( TextField ) gridResponsavel.findComponent( "form1:pgResponsavel:txtResponsavel" ); + TextArea txtRecursos = ( TextArea ) gridResponsavel.findComponent( "form1:txtRecursos" ); + HtmlCalendar dtInicio = ( HtmlCalendar ) gridResponsavel.findComponent( "form1:dtInicio:" ); + HtmlCalendar dtFim = ( HtmlCalendar ) gridResponsavel.findComponent( "form1:dtFim" ); + txtResponsavel.setText( "" ); + txtRecursos.setText( "" ); + dtInicio.setValue( null ); + dtFim.setValue( null ); + break; + + case Global.FASE_DIR_LOJA_VALIDACAO: + TextArea txtParecerDl = ( TextArea ) gridResponsavel.findComponent( "form1:txtParecerDl" ); + txtParecerDl.setText( "" ); + PanelGroup pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDl" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDl" ); + txtObs.setText( "" ); + } + break; + + case Global.FASE_DNS_PARECER: + TextArea txtParecerDns = ( TextArea ) gridResponsavel.findComponent( "form1:txtParecerDns" ); + txtParecerDns.setText( "" ); + pg = ( PanelGroup ) gridObservacoes.findComponent( "pgObsDns" ); + if ( pg != null ) + { + TextArea txtObs = ( TextArea ) pg.findComponent( "txtObservacoesDns" ); + txtObs.setText( "" ); + } + break; + + case Global.FASE_SIPRP_CONCLUSAO: + TextArea txtVerificacaoSiprp = ( TextArea ) gridResponsavel.findComponent( "form1:txtVerificacaoSiprp" ); + txtVerificacaoSiprp.setText( "" ); + break; + } + + return null; + } + + public String butEnviarCorrecao_action() + { + System.out.println( "BUT ENVIAR CORRECAO" ); + return "enviar_correcao"; + } +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/EnviarCorrecao.java b/trunk/PlanosActuacao/src/planosactuacao/EnviarCorrecao.java new file mode 100644 index 00000000..8da48918 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/EnviarCorrecao.java @@ -0,0 +1,384 @@ +/* + * EnviarCorrecao.java + * + * Created on Nov 13, 2008, 11:26:00 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import com.sun.webui.jsf.component.Button; +import com.sun.webui.jsf.component.DropDown; +import com.sun.webui.jsf.component.StaticText; +import com.sun.webui.jsf.component.TextArea; +import com.sun.webui.jsf.model.Option; +import db.entidades.PlanoActuacao; +import db.entidades.Utilizador; +import db.providers.PlanosDataProvider; +import db.providers.UtilizadoresDataProvider; +import utils.Global; +import java.util.List; +import java.util.ListIterator; +import javax.faces.FacesException; +import javax.faces.event.ValueChangeEvent; +import mail.Mail; + +/** + *

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.

+ * + * @author lluis + */ +public class EnviarCorrecao extends AbstractPageBean +{ + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception + { + + } + + private StaticText lblMsg = new StaticText(); + + public StaticText getLblMsg() + { + return lblMsg; + } + + public void setLblMsg(StaticText st) + { + this.lblMsg = st; + } + + private TextArea txtObservacoes = new TextArea(); + + public TextArea getTxtObservacoes() + { + return txtObservacoes; + } + + public void setTxtObservacoes(TextArea ta) + { + this.txtObservacoes = ta; + } + + private DropDown drpIrPara = new DropDown(); + + public DropDown getDrpIrPara() + { + return drpIrPara; + } + + public void setDrpIrPara(DropDown dd) + { + this.drpIrPara = dd; + } + + private Button butCancelar = new Button(); + + public Button getButCancelar() + { + return butCancelar; + } + + public void setButCancelar(Button b) + { + this.butCancelar = b; + } + + private Button butEnviar = new Button(); + + public Button getButEnviar() + { + return butEnviar; + } + + public void setButEnviar(Button b) + { + this.butEnviar = b; + } + + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public EnviarCorrecao() + { + + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try + { + _init(); + } + catch (Exception e) + { + ErrorLogger.logException( e ); + log("EnviarCorrecao Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() + { + + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() + { + initialize(); + lblMsg.setText(getSessionBean1().getMsg()); + getSessionBean1().setMsg(""); + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() + { + + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() + { + return (SessionBean1) getBean("SessionBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() + { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() + { + return (RequestBean1) getBean("RequestBean1"); + } + + public void drpIrPara_processValueChange(ValueChangeEvent event) + { + + } + + private void initialize() + { + Utilizador u = getSessionBean1().getCurrentUser(); + com.sun.webui.jsf.model.Option[] listOptions = null; + + if(u.getTipo().intValue() == Global.DIRECTOR_LOJA) + { + listOptions = new com.sun.webui.jsf.model.Option[1]; + listOptions[0] = new Option(new Integer(Global.FASE_SEGURANCA_PREENCHIMENTO), "Responsavel de seguranca"); + } + else if(u.getTipo().intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA) + { + listOptions = new com.sun.webui.jsf.model.Option[2]; + listOptions[0] = new Option(new Integer(Global.FASE_SEGURANCA_PREENCHIMENTO), "Responsavel de seguranca"); + listOptions[1] = new Option(new Integer(Global.FASE_DIR_LOJA_VALIDACAO), "Director de loja"); + } + + getSessionBean1().setIrParaOptions(listOptions); + getSessionBean1().setIrParaChoice(new Integer( Global.FASE_SEGURANCA_PREENCHIMENTO )); + //drpIrPara.setItems(listOptions); + //drpIrPara.setSelected(new Integer( Global.FASE_SEGURANCA_PREENCHIMENTO )); + } + + public String butCancelar_action() + { + return "editar_plano"; + } + + public String butEnviar_action() + { + Utilizador u = getSessionBean1().getCurrentUser(); +// PlanosDataProvider pdp = new PlanosDataProvider(); + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + p.setFase_anterior( p.getFase() ); + int dns_next_fase = 0; + int fase = 0; + Integer irPara = ( Integer ) drpIrPara.getSelected(); + fase = irPara.intValue(); + if ( u.getTipo().intValue() == Global.DIRECTOR_LOJA ) + { + p.setValidacao_director_loja( new Boolean( false ) ); + } + else if ( u.getTipo().intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA ) + { + p.setValidacao_dns( new Boolean( false ) ); + } + p.setCorrecao( "y" ); + p.setFase_antes_correcao( p.getFase() ); + p.setFase( new Integer( fase ) ); + String observacoes = ""; + if ( txtObservacoes.getText() != null ) + { + if ( u.getTipo().intValue() == Global.DIRECTOR_LOJA ) + { + observacoes = "Observações do Director de Loja: "; + } + else if ( u.getTipo().intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA ) + { + observacoes = "Observações do Director Nacional de Segurança: "; + } + observacoes += ( String ) txtObservacoes.getText(); + p.setObs_correcao( observacoes ); + } + try + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + pdp.updatePlano( p ); + enviarMail( p ); + return "lista_planos"; + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + getSessionBean1().setMsg( "Erro no envio do plano para a fase " + Global.FASES_TEXTO[ fase - 1 ] ); + } + return null; + } + + private void enviarMail( PlanoActuacao p ) + { + String assunto = ""; + String mail_text = ""; + + int fase = p.getFase().intValue(); + int tipo_utilizador = 0; + switch( fase ) + { + case Global.FASE_SEGURANCA_PREENCHIMENTO : // enviar para correccao para responsavel de seguranca + tipo_utilizador = Global.RESPONSAVEL_SEGURANCA; + assunto = "Plano de Actuacao da Avaliacao de Riscos de " + p.getData_visita_str() + " - " + p.getNome_estabelecimento() + " - Pedido de Correcao"; + mail_text = "

Exmo. (a) Senhor (a),

"; + mail_text += "

O Plano de Actuação referente à auditoria de Avaliação de Riscos Laborais realizada no passado dia " + p.getData_visita_str() + " foi devolvido para correcção.

"; + mail_text += "

Proceda, por favor, em www.siprp.com à(s) respectiva(s) correcção(ões) de acordo com as indicações e volte a reenviar o processo para a fase seguinte.

"; + mail_text += "

Caso tenha alguma dúvida ou necessite de qualquer esclarecimento, contacte, por favor, a Área Técnica da SIPRP através do telefone 213 504 540.

"; + mail_text += "

Cumprimentos,

"; + mail_text += "

A equipa da SIPRP

"; + mail_text += "

Por favor não responda a esta mensagem, dado tratar-se de um e-mail automático

"; + break; + + case Global.FASE_DIR_LOJA_VALIDACAO : // enviar para correccao para director de loja + tipo_utilizador = Global.DIRECTOR_LOJA; + assunto = "Plano de Actuacao da Avaliacao de Riscos de " + p.getData_visita_str() + " - " + p.getNome_estabelecimento() + " - Pedido de Correccao"; + mail_text = "

Exmo. (a) Senhor (a),

"; + mail_text += "

O Plano de Actuação referente à auditoria de Avaliação de Riscos Laborais realizada no passado dia " + p.getData_visita_str() + " foi devolvido para correcção.

"; + mail_text += "

Proceda, por favor, em www.siprp.com à(s) respectiva(s) correcção(ões) de acordo com as indicações do Director Nacional de Segurança e volte a reenviar o processo para a fase seguinte.

"; + mail_text += "

Cumprimentos.

"; + mail_text += "

Por favor não responda a esta mensagem, dado tratar-se de um e-mail automático

"; + break; + } + + String responsavel_loja = "n"; + if ( tipo_utilizador == Global.RESPONSAVEL_SEGURANCA ) + { + responsavel_loja = "y"; + } + try + { + Mail mail = new Mail(); + + UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); + List< Utilizador > list = udp.getUtilizadoresListByTipo( tipo_utilizador, responsavel_loja, p.getEstabelecimento_id() ); + ListIterator iter = list.listIterator(); + while ( iter.hasNext() ) + { + Utilizador u = ( Utilizador ) iter.next(); + System.out.println( "USER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail() ); + try + { + mail.send( u.getEmail(), Mail.ENDERECO_ENVIO, assunto, mail_text ); + System.out.println( "EMAIL ENVIADO !!" ); + } + catch ( Exception ex1 ) + { + ErrorLogger.logException( ex1 ); + System.out.println( "MAIL ERROR : " + ex1.getMessage() ); + } + } + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + } + +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/Erro.java b/trunk/PlanosActuacao/src/planosactuacao/Erro.java new file mode 100644 index 00000000..895eaa51 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Erro.java @@ -0,0 +1,153 @@ +/* + * Erro.java + * + * Created on Aug 26, 2008, 10:54:11 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import com.sun.webui.jsf.component.StaticText; +import javax.faces.FacesException; + +/** + *

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.

+ * + * @author lluis + */ +public class Erro extends AbstractPageBean { + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + private StaticText txtMsg = new StaticText(); + + public StaticText getTxtMsg() { + return txtMsg; + } + + public void setTxtMsg(StaticText st) { + this.txtMsg = st; + } + + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public Erro() { + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("Erro Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() { + txtMsg.setText( getSessionBean1().getMsg() ); + getSessionBean1().setMsg(""); + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() { + return (RequestBean1) getBean("RequestBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() { + return (SessionBean1) getBean("SessionBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java b/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java new file mode 100644 index 00000000..3931a827 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Estatistica.java @@ -0,0 +1,300 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package planosactuacao; + +import com.evolute.utils.data.Mappable; +import com.evolute.utils.strings.UnicodeChecker; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import com.sun.webui.jsf.component.Button; +import com.sun.webui.jsf.component.DropDown; +import com.sun.webui.jsf.component.Table; +import com.sun.webui.jsf.component.TableRowGroup; +import com.sun.webui.jsf.model.Option; +import db.entidades.LinhaEstatistica; +import db.providers.PlanosDataProvider; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import javax.faces.FacesException; + +/** + *

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.

+ * + * @version Estatistica.java + * @version Created on Mar 27, 2012, 2:22:42 PM + * @author fpalma + */ + +public class Estatistica extends AbstractPageBean { + // + + private DropDown dropEstabelecimento = new DropDown(); + private Date calInicioDate = null; + private Date calFimDate = null; + private Button buttonPesquisar;// = new Button(); + private Table tableEstatistica = new Table(); + private TableRowGroup tableRowGroupEstatisticas = new TableRowGroup(); + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public Estatistica() { + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + fillEstabelecimentosDrop(); + } catch (Exception e) { + log("Estatistica Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() { + + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() { + + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() + { + return ( ApplicationBean1 ) getBean( "ApplicationBean1" ); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() + { + return ( SessionBean1 ) getBean( "SessionBean1" ); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() + { + return ( RequestBean1 ) getBean( "RequestBean1" ); + } + + public Button getButtonPesquisar() + { + return buttonPesquisar; + } + + public void setButtonPesquisar( Button buttonPesquisar ) + { + this.buttonPesquisar = buttonPesquisar; + } + + public Date getCalFimDate() + { + return calFimDate; + } + + public void setCalFimDate( Date calFimDate ) + { + this.calFimDate = calFimDate; + } + + public Date getCalInicioDate() + { + return calInicioDate; + } + + public void setCalInicioDate( Date calInicioDate ) + { + this.calInicioDate = calInicioDate; + } + + public DropDown getDropEstabelecimento() + { + return dropEstabelecimento; + } + + public void setDropEstabelecimento( DropDown dropEstabelecimento ) + { + this.dropEstabelecimento = dropEstabelecimento; + } + + public Table getTableEstatistica() + { + return tableEstatistica; + } + + public void setTableEstatistica( Table tableEstatistica ) + { + this.tableEstatistica = tableEstatistica; + } + + public TableRowGroup getTableRowGroupEstatisticas() + { + return tableRowGroupEstatisticas; + } + + public void setTableRowGroupEstatisticas( TableRowGroup tableRowGroupEstatisticas ) + { + this.tableRowGroupEstatisticas = tableRowGroupEstatisticas; + } + + public String buttonPesquisar_action() + { + System.out.println( "ACTION" ); + List linhasEstatistica = null; + try + { + Integer estabelecimentoId = null; + if ( dropEstabelecimento.getSelected() != null ) + { + String estabelecimento = ( String ) dropEstabelecimento.getSelected(); + if ( estabelecimento != null ) + { + try { + estabelecimentoId = Integer.parseInt( estabelecimento ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + } + linhasEstatistica = PlanosDataProvider.getInstance().getEstatisticaForEstabelecimentoIdAndDateInterval( estabelecimentoId, calInicioDate, calFimDate ); + System.out.println( "LINHAS: " + linhasEstatistica.size() ); + } + catch( Exception ex ) + { + System.out.println( "EXCEPTION" ); + ex.printStackTrace(); + linhasEstatistica = new ArrayList(); + } + getSessionBean1().getEstatisticaPlanoDataProvider().setList( linhasEstatistica ); + return null; + } + + protected void fillEstabelecimentosDrop() + { +// List estabelecimentos = null; + List estabelecimentos = null; + try + { + estabelecimentos = PlanosDataProvider.getInstance().getEstabelecimentosForEstatistica( getSessionBean1().getCurrentUser() ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + return; + } +// Option[] options = new Option[ estabelecimentos.size() > 1 ? estabelecimentos.size() + 1 : 1 ]; + Option[] options = new Option[ estabelecimentos.size() ]; + int off = 0; +// if( options.length > 1 ) +// { +// options[ 0 ] = new Option( null, "Todos" ); +// off = 1; +// } + for( int i = 0; i + off < options.length; i++ ) + { + options[ i + off ] = new Option( estabelecimentos.get( i ).getID(), ( String ) estabelecimentos.get( i ).getValue() ); + } + if ( estabelecimentos != null ) + { + dropEstabelecimento.setItems( options ); + } + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected EditarPlano getEditarPlano() + { + return ( EditarPlano ) getBean( "EditarPlano" ); + } +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/Footer.java b/trunk/PlanosActuacao/src/planosactuacao/Footer.java new file mode 100644 index 00000000..1f529e12 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Footer.java @@ -0,0 +1,141 @@ +/* + * Footer.java + * + * Created on Oct 6, 2008, 3:01:32 PM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import javax.faces.FacesException; + +/** + *

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.

+ * + * @author lluis + */ +public class Footer extends AbstractPageBean { + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public Footer() { + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("Footer Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() { + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() { + return (RequestBean1) getBean("RequestBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() { + return (SessionBean1) getBean("SessionBean1"); + } + +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/Header.java b/trunk/PlanosActuacao/src/planosactuacao/Header.java new file mode 100644 index 00000000..bacd8562 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Header.java @@ -0,0 +1,253 @@ +/* + * Header.java + * + * Created on Oct 6, 2008, 10:35:36 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractFragmentBean; +import com.sun.webui.jsf.component.ImageComponent; +import com.sun.webui.jsf.component.StaticText; +import db.entidades.Utilizador; +import utils.Global; +import javax.faces.FacesException; +import javax.faces.context.FacesContext; +import utils.JSFHTTPUtils; +import utils.JSFUtils; + +/** + *

Fragment bean that corresponds to a similarly named JSP page + * fragment. This class contains component definitions (and initialization + * code) for all components that you have defined on this fragment, as well as + * lifecycle methods and event handlers where you may add behavior + * to respond to incoming events.

+ * + * @author lluis + */ +public class Header extends AbstractFragmentBean { + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + private StaticText stDataPlano = new StaticText(); + + public StaticText getStDataPlano() { + return stDataPlano; + } + + public void setStDataPlano(StaticText st) { + this.stDataPlano = st; + } + private ImageComponent imgLogoEmpresa = new ImageComponent(); + + public ImageComponent getImgLogoEmpresa() { + return imgLogoEmpresa; + } + + public void setImgLogoEmpresa(ImageComponent ic) { + this.imgLogoEmpresa = ic; + } + //
+ + public Header() { + } + + /** + *

Callback method that is called whenever a page containing + * this page fragment is navigated to, either directly via a URL, + * or indirectly via page navigation. Override this method to acquire + * resources that will be needed for event handlers and lifecycle methods.

+ * + *

The default implementation does nothing.

+ */ + @Override + 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 + + FacesContext fc = getFacesContext(); + String referer = JSFHTTPUtils.getReferer(fc); + System.out.println("HEADER - REFERER : " + referer); + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("Page1 Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called. Override this + * method to release resources acquired in the init() + * resources that will be needed for event handlers and lifecycle methods.

+ * + *

The default implementation does nothing.

+ */ + @Override + public void destroy() { + } + + public String lnkLogout_action() + { + FacesContext fc = getFacesContext(); + try + { + JSFUtils.logout( fc ); + try + { + JSFUtils.redirect( fc, Global.ANALISE_ACIDENTES_URL + "Login.jsp" ); + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + return null; + } + + public String lnkAnaliseAcidentes_action() + { + FacesContext fc = getFacesContext(); + SessionBean1 session = JSFUtils.getSessionBean(fc); + Utilizador u = session.getCurrentUser(); + + String url = Global.ANALISE_ACIDENTES_URL; + int tipo = u.getTipo().intValue(); + switch(tipo) + { + case Global.RESPONSAVEL_SEGURANCA: + url += "FormSeguranca.jsp?user=" + u.getId().intValue(); + break; + + case Global.RH: + url += "FormRH.jsp?user=" + u.getId().intValue(); + break; + + case Global.TECNICO_HS: + url += "FormHS.jsp?user=" + u.getId().intValue(); + break; + + case Global.GESTOR: + url += "FormGestor.jsp?user=" + u.getId().intValue(); + break; + + case Global.DIRECTOR_LOJA: + url += "FormGestor.jsp?user=" + u.getId().intValue(); + break; + case Global.DIRECTOR_GERAL_RH: + url += "FormDirGerRh.jsp?user=" + u.getId().intValue(); + break; + + case Global.DIRECTOR_SIPRP: + url += "FormDirSiprp.jsp?user=" + u.getId().intValue(); +// url += "Acesso.jsp"; + break; + + case Global.DIRECTOR_NACIONAL_SEGURANCA: + url += "FormGestor.jsp?user=" + u.getId().intValue(); + break; + } + + try + { + JSFUtils.redirect(fc.getCurrentInstance(), url); + } + catch(Exception ex) + { + ErrorLogger.logException( ex ); + } + return null; + } + + public String lnkPlanosActuacao1_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + return "lista_planos"; + } + + public String lnkGerirUtilizadores1_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + FacesContext fc = getFacesContext(); + SessionBean1 session = JSFUtils.getSessionBean(fc); + Utilizador u = session.getCurrentUser(); + + String url = Global.ANALISE_ACIDENTES_URL; + //int tipo = u.getTipo().intValue(); + + url += "GestaoUtilizadores.jsp?user=" + u.getId().intValue(); + try + { + JSFUtils.redirect(fc.getCurrentInstance(), url); + } + catch(Exception ex) + { + ErrorLogger.logException( ex ); + } + + return null; + } + + public String lnkDadosUtilizador1_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + FacesContext fc = getFacesContext(); + SessionBean1 session = JSFUtils.getSessionBean(fc); + Utilizador u = session.getCurrentUser(); + + String url = Global.ANALISE_ACIDENTES_URL; + int tipo = u.getTipo().intValue(); + + url += "FichaUtilizador.jsp?user=" + u.getId().intValue() + "&mode=edit"; + try + { + JSFUtils.redirect(fc.getCurrentInstance(), url); + } + catch(Exception ex) + { + ErrorLogger.logException( ex ); + } + + return null; + } + + public String lnkAjuda_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + return "planos_actuacao_ajuda.pdf"; + } + + + public String lnkEstatisticas_action() { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + return "estatistica"; + } + +} diff --git a/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java b/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java new file mode 100644 index 00000000..7f39f3a9 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/ListaPlanos.java @@ -0,0 +1,1092 @@ +/* + * ListaPlanos.java + * + * Created on Aug 29, 2008, 2:57:16 PM + */ +package planosactuacao; + +import com.evolute.utils.date.DateUtils; +import com.evolute.utils.error.ErrorLogger; +import com.sun.data.provider.RowKey; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import com.sun.webui.jsf.component.Button; +import com.sun.webui.jsf.component.DropDown; +import com.sun.webui.jsf.component.PanelGroup; +import com.sun.webui.jsf.component.Table; +import com.sun.webui.jsf.component.TableColumn; +import com.sun.webui.jsf.component.TableRowGroup; +import com.sun.webui.jsf.component.TextField; +import com.sun.webui.jsf.model.Option; +import db.entidades.PlanoActuacao; +import db.entidades.Utilizador; +import db.providers.PlanosDataProvider; +import utils.Global; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import javax.faces.FacesException; +import javax.faces.component.html.HtmlPanelGrid; +import javax.faces.context.FacesContext; +import javax.faces.event.ValueChangeEvent; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import shst.higiene.planoactuacao.print.PlanoActuacaoPDFCreator; +import tabledataproviders.PlanosActualDataProvider; +import tabledataproviders.PlanosConcluidosDataProvider; +import tabledataproviders.PlanosSeguimentoDataProvider; +import utils.JSFUtils; +import utils.Utils; + +/** + *

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.

+ * + * @author lluis + */ +public class ListaPlanos extends AbstractPageBean +{ + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception + { + } + 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 TableRowGroup tableRowGroup2 = new TableRowGroup(); + + public TableRowGroup getTableRowGroup2() + { + return tableRowGroup2; + } + + public void setTableRowGroup2( TableRowGroup trg ) + { + this.tableRowGroup2 = trg; + } + private TableRowGroup tableRowGroup3 = new TableRowGroup(); + + public TableRowGroup getTableRowGroup3() + { + return tableRowGroup3; + } + + public void setTableRowGroup3( TableRowGroup trg ) + { + this.tableRowGroup3 = trg; + } + private HtmlPanelGrid gridActual = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridActual() + { + return gridActual; + } + + public void setGridActual( HtmlPanelGrid hpg ) + { + this.gridActual = hpg; + } + private TableColumn tableColumn55 = new TableColumn(); + + public TableColumn getTableColumn55() + { + return tableColumn55; + } + + public void setTableColumn55( TableColumn c ) + { + this.tableColumn55 = c; + } + private Button buttonDesactivar = new Button(); + + public Button getButtonDesactivar() + { + return buttonDesactivar; + } + + public void setButtonDesactivar( Button b ) + { + this.buttonDesactivar = b; + } + + + private TableColumn tableColumn56 = new TableColumn(); + + public TableColumn getTableColumn56() + { + return tableColumn56; + } + + public void setTableColumn56( TableColumn c ) + { + this.tableColumn56 = c; + } + private Button buttonDesactivarSeguimento = new Button(); + + public Button getButtonDesactivarSeguimento() + { + return buttonDesactivarSeguimento; + } + + public void setButtonDesactivarSeguimento( Button b ) + { + this.buttonDesactivarSeguimento = b; + } + + + private TableColumn tableColumnConcluidos6 = new TableColumn(); + + public TableColumn getTableColumnConcluidos6() + { + return tableColumnConcluidos6; + } + + public void setTableColumnConcluidos6( TableColumn c ) + { + this.tableColumnConcluidos6 = c; + } + + private Button buttonPreencherVerificacao = new Button(); + + public Button getButtonPreencherVerificacao() + { + return buttonPreencherVerificacao; + } + + public void setButtonPreencherVerificacao( Button buttonPreencherVerificacao ) + { + this.buttonPreencherVerificacao = buttonPreencherVerificacao; + } + + + + private HtmlPanelGrid gridPanelFilterActual = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridPanelFilterActual() + { + return this.gridPanelFilterActual; + } + + public void setGridPanelFilterActual( HtmlPanelGrid pg ) + { + this.gridPanelFilterActual = pg; + } + private PanelGroup groupPanelFilterActual = new PanelGroup(); + + public PanelGroup getGroupPanelFilterActual() + { + return this.groupPanelFilterActual; + } + + public void setGroupPanelFilterActual( PanelGroup pg ) + { + this.groupPanelFilterActual = pg; + } + private TextField textFilterNameActual = new TextField(); + + public TextField getTextFilterNameActual() + { + return this.textFilterNameActual; + } + + public void setTextFilterNameActual( TextField tf ) + { + this.textFilterNameActual = tf; + } + private TextField textFilterEstabelecimentoActual = new TextField(); + + public TextField getTextFilterEstabelecimentoActual() + { + return textFilterEstabelecimentoActual; + } + + public void setTextFilterEstabelecimentoActual( TextField textFilterEstabelecimentoActual ) + { + this.textFilterEstabelecimentoActual = textFilterEstabelecimentoActual; + } + + + private Date calFilterDate = null; + public Date getCalFilterDate() + { + return calFilterDate; + } + public void setCalFilterDate( Date calFilterDate ) + { + this.calFilterDate = calFilterDate; + } + + +// private com.sun.webui.jsf.component.Calendar calFilterDateActual = new com.sun.webui.jsf.component.Calendar(); +// public com.sun.webui.jsf.component.Calendar getCalFilterDateActual() +// { +// return calFilterDateActual; +// } +// public void setCalFilterDateActual( com.sun.webui.jsf.component.Calendar calFilterDateActual ) +// { +// this.calFilterDateActual = calFilterDateActual; +// } + + + private Button buttonFilterActual = new Button(); + + public Button getButtonFilterActual() + { + return this.buttonFilterActual; + } + + public void setButtonFilterActual( Button b ) + { + this.buttonFilterActual = b; + } + private HtmlPanelGrid gridPanelFilterSeg = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridPanelFilterSeg() + { + return this.gridPanelFilterSeg; + } + + public void setGridPanelFilterSeg( HtmlPanelGrid pg ) + { + this.gridPanelFilterSeg = pg; + } + private PanelGroup groupPanelFilterSeg = new PanelGroup(); + + public PanelGroup getGroupPanelFilterSeg() + { + return this.groupPanelFilterSeg; + } + + public void setGroupPanelFilterSeg( PanelGroup pg ) + { + this.groupPanelFilterSeg = pg; + } + private TextField textFilterNameSeg = new TextField(); + + public TextField getTextFilterNameSeg() + { + return this.textFilterNameSeg; + } + + public void setTextFilterNameSeg( TextField tf ) + { + this.textFilterNameSeg = tf; + } + private TextField textFilterEstabelecimentoSeg = new TextField(); + + public TextField getTextFilterEstabelecimentoSeg() + { + return textFilterEstabelecimentoSeg; + } + + public void setTextFilterEstabelecimentoSeg( TextField textFilterEstabelecimentoSeg ) + { + this.textFilterEstabelecimentoSeg = textFilterEstabelecimentoSeg; + } + + + private Date calFilterDateSeguimento = null; + public Date getCalFilterDateSeguimento() + { + return calFilterDateSeguimento; + } + public void setCalFilterDateSeguimento( Date calFilterDateSeguimento ) + { + this.calFilterDateSeguimento = calFilterDateSeguimento; + } + +// private com.sun.webui.jsf.component.Calendar calFilterDateSeg = new com.sun.webui.jsf.component.Calendar(); +// public com.sun.webui.jsf.component.Calendar getCalFilterDateSeg() +// { +// return calFilterDateSeg; +// } +// public void setCalFilterDateSeg( com.sun.webui.jsf.component.Calendar calFilterDateSeg ) +// { +// this.calFilterDateSeg = calFilterDateSeg; +// } + + + private Button buttonFilterSeg = new Button(); + + public Button getButtonFilterSeg() + { + return this.buttonFilterSeg; + } + + public void setButtonFilterSeg( Button b ) + { + this.buttonFilterSeg = b; + } + private HtmlPanelGrid gridPanelFilterConc = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridPanelFilterConc() + { + return this.gridPanelFilterConc; + } + + public void setGridPanelFilterConc( HtmlPanelGrid pg ) + { + this.gridPanelFilterConc = pg; + } + private PanelGroup groupPanelFilterConc = new PanelGroup(); + + public PanelGroup getGroupPanelFilterConc() + { + return this.groupPanelFilterConc; + } + + public void setGroupPanelFilterConc( PanelGroup pg ) + { + this.groupPanelFilterConc = pg; + } + private TextField textFilterNameConc = new TextField(); + + public TextField getTextFilterNameConc() + { + return this.textFilterNameConc; + } + + public void setTextFilterNameConc( TextField tf ) + { + this.textFilterNameConc = tf; + } + private TextField textFilterEstabelecimentoConc = new TextField(); + + public TextField getTextFilterEstabelecimentoConc() + { + return textFilterEstabelecimentoConc; + } + + public void setTextFilterEstabelecimentoConc( TextField textFilterEstabelecimentoConc ) + { + this.textFilterEstabelecimentoConc = textFilterEstabelecimentoConc; + } + + + private Date calFilterDateConcluidos = null; + public Date getCalFilterDateConcluidos() + { + return calFilterDateConcluidos; + } + public void setCalFilterDateConcluidos( Date calFilterDateConcluidos ) + { + this.calFilterDateConcluidos = calFilterDateConcluidos; + } + +// private com.sun.webui.jsf.component.Calendar calFilterDateConc = new com.sun.webui.jsf.component.Calendar(); +// public com.sun.webui.jsf.component.Calendar getCalFilterDateConc() +// { +// return calFilterDateConc; +// } +// public void setCalFilterDateConc( com.sun.webui.jsf.component.Calendar calFilterDateConc ) +// { +// this.calFilterDateConc = calFilterDateConc; +// } + + + private Button buttonFilterConc = new Button(); + + public Button getButtonFilterConc() + { + return this.buttonFilterConc; + } + + public void setButtonFilterConc( Button b ) + { + this.buttonFilterConc = b; + } + + private DropDown dropCurrentYear = new DropDown(); + + public DropDown getDropCurrentYear() + { + return dropCurrentYear; + } + + public void setDropCurrentYear( DropDown dropCurrentYear ) + { + this.dropCurrentYear = dropCurrentYear; + } + + private static final DateFormat D_F = new SimpleDateFormat( "yyyy-MM-dd" ); + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public ListaPlanos() + { + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try + { + _init(); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + log( "ListaPlanos Initialization Failure", e ); + throw e instanceof FacesException ? ( FacesException ) e : new FacesException( e ); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() + { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() + { + System.out.println( "LISTA PLANOS - PRERENDER" ); + HttpServletRequest request = ( HttpServletRequest ) getExternalContext().getRequest(); + String referer = request.getRequestURI(); + String pageFrom = Utils.getPageFrom( referer ); + if ( !pageFrom.matches( "FormMedico.jsp" ) + || dropCurrentYear.getItems() == null ) + { + fillCurrentYearDrop(); + fillInitialForm(); + } + } + + private void fillInitialForm() + { + Utilizador u = getSessionBean1().getCurrentUser(); + System.out.println( "\tUser Logged In : " + ( u == null ? "NONE !" : "[" + u.getId() + "] : " + u.getLogin() ) ); + + FacesContext fc = getFacesContext(); + String estab_gestor = JSFUtils.getRequestParameter( fc, "estab_gestor" ); + + boolean renderOrNot = false; + boolean renderPreencherVerificacao = false; + + if ( u != null ) + { + if ( u.getTipo() != null && u.getTipo().intValue() == Global.GESTOR ) + { + try + { + Integer estabelecimento_gestor = new Integer( Integer.parseInt( estab_gestor ) ); + System.out.println( "ESTABELECIMENTO GESTOR : " + estabelecimento_gestor.intValue() ); + u.setEstabelecimento_gestor( estabelecimento_gestor ); + } + catch ( Exception ex2 ) + { + ErrorLogger.logException( ex2 ); + } + } + + if ( u.getTipo().intValue() == Global.DIRECTOR_SIPRP || u.getTipo().intValue() == Global.RH || u.getTipo().intValue() == Global.DIRECTOR_GERAL_RH || u.getTipo().intValue() == Global.GESTOR ) + { + gridActual.setRendered( false ); + tableRowGroup2.setEmptyDataMsg( "Sem registos" ); + tableRowGroup3.setEmptyDataMsg( "Sem registos" ); + } + + if ( u.getTipo().intValue() != Global.DIRECTOR_SIPRP && u.getTipo().intValue() != Global.RH && u.getTipo().intValue() != Global.DIRECTOR_GERAL_RH ) + { + getSessionBean1().setDisableMenuUtilizadores( true ); + tableRowGroup1.setEmptyDataMsg( "Sem registos" ); + tableRowGroup2.setEmptyDataMsg( "Sem registos" ); + tableRowGroup3.setEmptyDataMsg( "Sem registos" ); + } + + //Column para desactivar plano - mostra se o utilizador for DIRECTOR SIPRP + if ( u.getTipo() != null ) + { + int uType = u.getTipo(); + renderOrNot = uType == Global.DIRECTOR_SIPRP || uType == Global.TECNICO_HS; + renderPreencherVerificacao = uType == Global.DIRECTOR_SIPRP || uType == Global.TECNICO_HS; + } + + initialize(); + } + else + { + getSessionBean1().setMsg( "Utilizador inválido." ); + } + + tableColumn55.setRendered( renderOrNot ); + buttonDesactivar.setRendered( renderOrNot ); + tableColumn56.setRendered( renderOrNot ); + buttonDesactivarSeguimento.setRendered( renderOrNot ); + + tableColumnConcluidos6.setRendered( renderPreencherVerificacao); + buttonPreencherVerificacao.setRendered( renderPreencherVerificacao); + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() + { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() + { + return ( RequestBean1 ) getBean( "RequestBean1" ); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() + { + return ( ApplicationBean1 ) getBean( "ApplicationBean1" ); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() + { + return ( SessionBean1 ) getBean( "SessionBean1" ); + } + + public String hyperlink1_action() + { + // TODO: Process the action. Return value is a navigation + // case name where null will return to the same page. + return "editar_plano"; + } + + public String goDesactivarPlano_action() + { + System.out.println( "\ngoDesactivarPlano_action():" ); + PlanoActuacao p = getTableActivosRowData(); + desactivarPlano( p ); +// System.out.println( "\tPlanoActuacao: " + p.getId() ); + return null; + } + + public String goDesactivarPlanoSeguimento_action() + { + System.out.println( "\ngoDesactivarPlanoSeguimento_action():" ); + PlanoActuacao p = getTableSeguimentoRowData(); + desactivarPlano( p ); +// System.out.println( "\tPlanoActuacao: " + p.getId() ); + return null; + } + + public String goPreencherVerificacao_action() + { + PlanoActuacao p = getTableConcluidosRowData(); + getSessionBean1().setPlanoActuacao( p ); + +// getSessionBean1().setFase( Global.FASE_SIPRP_CONCLUSAO ); + return "editar_plano"; + } + + private void desactivarPlano( PlanoActuacao p ) + { + Utilizador currentUser = getSessionBean1().getCurrentUser(); + if ( currentUser.getTipo().intValue() == Global.DIRECTOR_SIPRP || currentUser.getTipo().intValue() == Global.TECNICO_HS ) + { + p.setFase( Global.FASE_CONCLUIDO ); + p.setConcluidoPorDesactivacao( Boolean.TRUE ); + p.setDataDesactivacao( new Date() ); + try + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + pdp.updatePlano( p ); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + } + } + + public String goEditarPlano_action() + { + PlanoActuacao p = getTableActivosRowData(); + getSessionBean1().setPlanoActuacao( p ); + + return "editar_plano"; + } + + public String goVerPlanoFromSeguimento_action() + { + PlanoActuacao p = getTableSeguimentoRowData(); + getSessionBean1().setPlanoActuacao( p ); + return "ver_plano"; + } + + public String goVerPlanoFromConcluidos_action() + { + PlanoActuacao p = getTableConcluidosRowData(); + getSessionBean1().setPlanoActuacao( p ); + return "ver_plano"; + } + + //**** IMPRIMIR PLANO SEM RISCOS PATRIMONIAIS ****// + public String goImprimirPlano_action() + { + PlanoActuacao p = getTableActivosRowData(); + createPdf( p.getId() ); + return null; + } + + public String goImprimirPlanoFromSeguimento_action() + { + PlanoActuacao p = getTableSeguimentoRowData(); + createPdf( p.getId() ); + return null; + } + + public String goImprimirPlanoFromConcluidos_action() + { + Utilizador currentUser = getSessionBean1().getCurrentUser(); + + PlanoActuacao p = getTableConcluidosRowData(); + if ( canPrint( p, currentUser ) ) + { + createPdf( p.getId() ); + } + return null; + } + + //*** IMPRIMIR PLANO COM RISCOS PATRIMONIAIS ***// + public String goImprimirPlanoPatrimoniais_action() + { + PlanoActuacao p = getTableActivosRowData(); + createPdf( p.getId(), true ); + return null; + } + + public String goImprimirPlanoSeguimentoPatrimoniais_action() + { + PlanoActuacao p = getTableSeguimentoRowData(); + createPdf( p.getId(), true ); + return null; + } + + public String goImprimirPlanoConcluidoPatrimoniais_action() + { + Utilizador currentUser = getSessionBean1().getCurrentUser(); + + PlanoActuacao p = getTableConcluidosRowData(); + if ( canPrint( p, currentUser ) ) + { + createPdf( p.getId(), true ); + } + return null; + } + + private boolean canPrint( PlanoActuacao p, Utilizador user ) + { + int userType = user == null ? -1 : user.getTipo(); + return ! p.getConcluidoPorDesactivacao() || ( userType == Global.DIRECTOR_SIPRP || userType == Global.TECNICO_HS ); + } + + + private void createPdf( Integer pID ) + { + createPdf( pID, false ); + } + + private void createPdf( Integer pID, boolean withPatrimoniais ) + { + try + { + PlanoActuacaoPDFCreator pdfCreator = new PlanoActuacaoPDFCreator(); + + System.out.println( "CREATING PDF ..." ); + byte[] pdf = pdfCreator.createPDF( pID, true, withPatrimoniais ); + System.out.println( "\t.. DONE !" ); + showPdf( pdf, withPatrimoniais ); + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + System.out.println( "\n\tError creating PDF : " + ex.getMessage() ); + } + } + + private void showPdf( byte[] pdf, boolean isPatrimoniais ) throws Exception + { + String filename = isPatrimoniais ? "Plano_Patrimoniais.pdf" : "Plano.pdf"; + System.out.println( "\nPDF LEN : " + pdf.length ); + System.out.println( "FileName : " + filename ); + + FacesContext context = FacesContext.getCurrentInstance(); + HttpServletResponse response = ( HttpServletResponse ) context.getExternalContext().getResponse(); + + response.setHeader( "Expires", "0" ); + response.setHeader( "Cache-Control", "must-revalidate, post-check=0, pre-check=0" ); + response.setHeader( "Pragma", "public" ); + response.setContentType( "application/pdf" ); + response.addHeader( "Content-disposition", "attachment;filename=\"" + filename + "\"" ); + response.setContentLength( pdf.length ); + + response.getOutputStream().write( pdf ); + response.getOutputStream().flush(); + response.getOutputStream().close(); + context.responseComplete(); + + System.out.println( "SHOW PDF done." ); + } + + private void initialize() + { + Utilizador u = getSessionBean1().getCurrentUser(); + Integer ano = getSelectedYear(); + +// Integer estabelecimento_id = null; +// if ( u.getTipo().intValue() != Global.TECNICO_HS ) +// { +// estabelecimento_id = u.getEstabelecimento_id(); +// } + + System.out.println( "INITIALIZE:" ); + + if ( !getSessionBean1().getIsSearchingPlanosActuacao() ) + { + System.out.println( "\tGETTING INITIAL VALUES FOR EACH TABLE." ); + long startedTime = System.currentTimeMillis(); + + List< PlanoActuacao > listPlanosActivos = getPlanosActivos( u, ano ); + getSessionBean1().getPlanosActualDataProvider().setList( listPlanosActivos ); + + List< PlanoActuacao > listPlanosSeguimento = getPlanosSeguimento( u, ano ); + getSessionBean1().getPlanosSeguimentoDataProvider().setList( listPlanosSeguimento ); + + List< PlanoActuacao > listPlanosConcluidos = getPlanosConcluidos( u, ano ); + getSessionBean1().getPlanosConcluidosDataProvider().setList( listPlanosConcluidos ); + + long endedTime = System.currentTimeMillis(); + System.out.println( "\nGot Planos List in : " + getTime( startedTime, endedTime ) ); + } + //checkPlanosDelayed(); + } + + private String getTime( long start, long end ) + { + return DateUtils.getTimePassed( start, end ); + } + + private PlanoActuacao getTableActivosRowData() + { + RowKey rk = tableRowGroup1.getRowKey(); + int k = Integer.parseInt( rk.getRowId() ); + PlanosActualDataProvider provider = ( PlanosActualDataProvider ) tableRowGroup1.getSourceData(); + List< PlanoActuacao > list = ( LinkedList< PlanoActuacao > ) provider.getList(); + PlanoActuacao p = ( PlanoActuacao ) list.get( k ); + return p; + } + + private PlanoActuacao getTableSeguimentoRowData() + { + RowKey rk = tableRowGroup2.getRowKey(); + int k = Integer.parseInt( rk.getRowId() ); + PlanosSeguimentoDataProvider provider = ( PlanosSeguimentoDataProvider ) tableRowGroup2.getSourceData(); + List< PlanoActuacao > list = ( LinkedList< PlanoActuacao > ) provider.getList(); + PlanoActuacao p = ( PlanoActuacao ) list.get( k ); + + return p; + } + + private PlanoActuacao getTableConcluidosRowData() + { + RowKey rk = tableRowGroup3.getRowKey(); + int k = Integer.parseInt( rk.getRowId() ); + PlanosConcluidosDataProvider provider = ( PlanosConcluidosDataProvider ) tableRowGroup3.getSourceData(); + List< PlanoActuacao > list = ( LinkedList< PlanoActuacao > ) provider.getList(); + PlanoActuacao p = ( PlanoActuacao ) list.get( k ); + return p; + } + + + private List< PlanoActuacao > searchPlanosActivos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + { + List< PlanoActuacao > list = null; + try + { + if ( u.getTipo().intValue() != Global.DIRECTOR_SIPRP && u.getTipo().intValue() != Global.GESTOR && u.getTipo().intValue() != Global.DIRECTOR_GERAL_RH ) + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + list = pdp.searchPlanosActivos( u, nome, estabelecimento, dataVisita, ano ); + } + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + return list == null ? new LinkedList< PlanoActuacao >() : list; + } + + private List getPlanosActivos( Utilizador u, Integer ano ) + { + return searchPlanosActivos( u, null, null, null, ano ); + } + + private List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + { + List< PlanoActuacao > list = null; + try + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + list = pdp.searchPlanosSeguimento( u, nome, estabelecimento, dataVisita, ano ); + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + return list == null ? new LinkedList< PlanoActuacao >() : list; + } + + private List< PlanoActuacao > getPlanosSeguimento( Utilizador u, Integer ano ) + { + return searchPlanosSeguimento( u, null, null, null, ano ); + } + + private List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano ) + { + List< PlanoActuacao > list = null; + try + { + PlanosDataProvider pdp = PlanosDataProvider.getInstance(); + list = pdp.searchPlanosConcluidos( u, nome, estabelecimento, dataVisita, ano ); + } + catch ( Exception ex ) + { + ErrorLogger.logException( ex ); + } + return list == null ? new LinkedList< PlanoActuacao >() : list; + } + + private List< PlanoActuacao > getPlanosConcluidos( Utilizador u, Integer ano ) + { + return searchPlanosConcluidos( u, null, null, null, ano ); + } + + public String buttonFilterActual_action() + { + String nome = null; + if ( textFilterNameActual.getText() != null ) + { + nome = ( ( String ) textFilterNameActual.getText() ).trim(); + if ( nome.length() == 0 ) + { + nome = null; + } + } + + String estabelecimento = null; + if ( textFilterEstabelecimentoActual.getText() != null ) + { + estabelecimento = ( ( String ) textFilterEstabelecimentoActual.getText() ).trim(); + if ( estabelecimento.length() == 0 ) + { + estabelecimento = null; + } + } + + String visitaDateStr = calFilterDate == null ? null : D_F.format( calFilterDate ); + + Integer ano = getSelectedYear(); + + getSessionBean1().setIsSearchingPlanosActuacao( Boolean.TRUE ); + getSessionBean1().getPlanosActualDataProvider().setList( + searchPlanosActivos( getSessionBean1().getCurrentUser(), nome, estabelecimento, visitaDateStr, ano ) ); + + return null; + } + + public String buttonFilterSeg_action() + { + String nome = null; + if ( textFilterNameSeg.getText() != null ) + { + nome = ( ( String ) textFilterNameSeg.getText() ).trim(); + if ( nome.length() == 0 ) + { + nome = null; + } + } + + String estabelecimento = null; + if ( textFilterEstabelecimentoSeg.getText() != null ) + { + estabelecimento = ( ( String ) textFilterEstabelecimentoSeg.getText() ).trim(); + if ( estabelecimento.length() == 0 ) + { + estabelecimento = null; + } + } + + String visitaDateStr = calFilterDateSeguimento == null ? null : D_F.format( calFilterDateSeguimento ); + + Integer ano = getSelectedYear(); + + getSessionBean1().setIsSearchingPlanosActuacao( Boolean.TRUE ); + getSessionBean1().getPlanosSeguimentoDataProvider().setList( + searchPlanosSeguimento( getSessionBean1().getCurrentUser(), nome, estabelecimento, visitaDateStr, ano ) ); + + return null; + } + + public String buttonFilterConc_action() + { + String nome = null; + if ( textFilterNameConc.getText() != null ) + { + nome = ( ( String ) textFilterNameConc.getText() ).trim(); + if ( nome.length() == 0 ) + { + nome = null; + } + } + + String estabelecimento = null; + if ( textFilterEstabelecimentoConc.getText() != null ) + { + estabelecimento = ( ( String ) textFilterEstabelecimentoConc.getText() ).trim(); + if ( estabelecimento.length() == 0 ) + { + estabelecimento = null; + } + } + + String visitaDateStr = calFilterDateConcluidos == null ? null : D_F.format( calFilterDateConcluidos ); + + Integer ano = getSelectedYear(); + + getSessionBean1().setIsSearchingPlanosActuacao( Boolean.TRUE ); + getSessionBean1().getPlanosConcluidosDataProvider().setList( + searchPlanosConcluidos( getSessionBean1().getCurrentUser(), nome, estabelecimento, visitaDateStr, ano ) ); + + return null; + } + + public void dropCurrentYear_valueChangeListener( ValueChangeEvent event ) + { + Object oldValue = event.getOldValue(); + Object newValue = event.getNewValue(); + + if ( newValue != null && newValue instanceof Integer ) + { + Integer newYear = ( Integer ) newValue; + getSessionBean1().setAnoChoice( newYear); + Integer oldYear = oldValue != null && oldValue instanceof Integer ? ( Integer ) oldValue : null; + if ( oldYear == null || !newYear.equals( oldYear ) ) + { + fillInitialForm(); + } + } + } + + private Integer getSelectedYear() + { + Integer result = getSessionBean1().getAnoChoice(); + if ( result == null && dropCurrentYear != null ) + { + Object selected = dropCurrentYear.getSelected(); + if ( selected != null && selected instanceof Integer ) + { + result = ( Integer ) selected; + } + } + return result; + } + + private void fillCurrentYearDrop() + { + Integer selectedYear = getSelectedYear(); + + Option[] opts = Utils.getYearDropValues(); + dropCurrentYear.setItems( opts ); + + dropCurrentYear.setSelected( selectedYear != null ? selectedYear : Utils.getDefaultSelectedYear() ); + } +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/Login.java b/trunk/PlanosActuacao/src/planosactuacao/Login.java new file mode 100644 index 00000000..d483ac1d --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Login.java @@ -0,0 +1,271 @@ +/* + * Login.java + * + * Created on Aug 26, 2008, 11:21:02 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import com.sun.webui.jsf.component.Button; +import com.sun.webui.jsf.component.PasswordField; +import com.sun.webui.jsf.component.TextField; +import db.entidades.Utilizador; +import db.providers.UtilizadoresDataProvider; +import javax.faces.FacesException; +import utils.Utils; + +/** + *

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.

+ * + * @author lluis + */ +public class Login extends AbstractPageBean +{ + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + private TextField txtUtilizador = new TextField(); + + public TextField getTxtUtilizador() { + return txtUtilizador; + } + + public void setTxtUtilizador(TextField tf) { + this.txtUtilizador = tf; + } + private PasswordField txtPassword = new PasswordField(); + + public PasswordField getTxtPassword() { + return txtPassword; + } + + public void setTxtPassword(PasswordField pf) { + this.txtPassword = pf; + } + private Button butLogin = new Button(); + + public Button getButLogin() { + return butLogin; + } + + public void setButLogin(Button b) { + this.butLogin = b; + } + + //
+ + /** + *

Construct a new Page bean instance.

+ */ + public Login() + { +// connect(); + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("Login Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() { + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() { + return (RequestBean1) getBean("RequestBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() { + return (SessionBean1) getBean("SessionBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + +// private void connect() +// { +// Db db = Db.getInstance(); +// try +// { +// Connection connection = db.connect(); +// } +// catch ( Exception ex ) +// { +// getSessionBean1().setMsg("Erro na ligação à Base de Dados"); +// //***** terminate session +// try { +// getExternalContext().redirect("faces/Erro.jsp"); +// } catch(Exception e) { +// // . . . handle exception . . . +// ErrorLogger.logException( e ); +// } +// ErrorLogger.logException( ex ); +// } +// } + + public String lnkPasswordRecovery_action() + { + return null; + } + + public String butLogin_action() + { + String sRet = null; + + if(txtUtilizador.getText() != null) + { + String utilizador = (String) txtUtilizador.getText(); + if(utilizador.trim().length() > 0) + { + if(txtPassword.getText() != null) + { + String password = (String) txtPassword.getText(); + if( password.trim().length() > 0 ) + { + try + { + UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); + + Utilizador u = udp.getUtilizador( utilizador ); + if( u != null && "y".equals( u.getActivo() ) ) + { + if ( ! password.equals( u.getPassword() ) ) + { + getSessionBean1().setMsg( "Palavra-chave inválida !" ); + } + else + { + Utils.doLogin( u ); + + getSessionBean1().setCurrentUser( u ); + getSessionBean1().setLoggedIn( true ); + + sRet = "lista_planos"; + } + } + else + { + getSessionBean1().setMsg("Utilizador inválido ! "); + } + } + catch(Exception ex) + { + ErrorLogger.logException( ex ); + getSessionBean1().setMsg("Utilizador inválido ! "); + } + } + else + { + getSessionBean1().setMsg("Falta palavra-chave !"); + } + } + else + { + getSessionBean1().setMsg("Falta palavra-chave !"); + } + } + else + { + getSessionBean1().setMsg("Falta utilizador !"); + } + } + else + { + getSessionBean1().setMsg("Falta utilizador !"); + } + return sRet; + } + +} + diff --git a/trunk/PlanosActuacao/src/planosactuacao/RequestBean1.java b/trunk/PlanosActuacao/src/planosactuacao/RequestBean1.java new file mode 100644 index 00000000..dd5b6d32 --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/RequestBean1.java @@ -0,0 +1,110 @@ +/* + * RequestBean1.java + * + * Created on Aug 25, 2008, 11:20:16 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractRequestBean; +import javax.faces.FacesException; + +/** + *

Request scope data bean for your application. Create properties + * here to represent data that should be made available across different + * pages in the same HTTP request, so that the page bean classes do not + * have to be directly linked to each other.

+ * + *

An instance of this class will be created for you automatically, + * the first time your application evaluates a value binding expression + * or method binding expression that references a managed bean using + * this class.

+ * + * @author lluis + */ +public class RequestBean1 extends AbstractRequestBean { + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + //
+ + /** + *

Construct a new request data bean instance.

+ */ + public RequestBean1() { + } + + /** + *

This method is called when this bean is initially added to + * request scope. Typically, this occurs as a result of evaluating + * a value binding or method binding expression, which utilizes the + * managed bean facility to instantiate this bean and store it into + * request scope.

+ * + *

You may customize this method to allocate resources that are required + * for the lifetime of the current request.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("RequestBean1 Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

This method is called when this bean is removed from + * request scope. This occurs automatically when the corresponding + * HTTP response has been completed and sent to the client.

+ * + *

You may customize this method to clean up resources allocated + * during the execution of the init() method, or + * at any later time during the lifetime of the request.

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() { + return (SessionBean1) getBean("SessionBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + +} diff --git a/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java b/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java new file mode 100644 index 00000000..8737a21d --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/SessionBean1.java @@ -0,0 +1,485 @@ +/* + * SessionBean1.java + * + * Created on Aug 25, 2008, 11:20:16 AM + */ + +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractSessionBean; +import db.entidades.Area; +import db.entidades.PlanoActuacao; +import db.entidades.Risco; +import db.entidades.Utilizador; +import db.entidades.Valor; +import java.util.HashMap; +import java.util.Map; +import javax.faces.FacesException; +import pagination.Pagination; + +/** + *

Session scope data bean for your application. Create properties + * here to represent cached data that should be made available across + * multiple HTTP requests for an individual user.

+ * + *

An instance of this class will be created for you automatically, + * the first time your application evaluates a value binding expression + * or method binding expression that references a managed bean using + * this class.

+ * + * @author lluis + */ +public class SessionBean1 extends AbstractSessionBean { + + private boolean loggedIn = false; + private Utilizador currentUser = null; + private String msg; + private String aatSessionID = null; + + private Integer planoId; + private PlanoActuacao planoActuacao = null; + private Risco currentRisco = null; + private Valor currentValor = null; + + + private tabledataproviders.PlanosActualDataProvider planosActualDataProvider; + private tabledataproviders.PlanosSeguimentoDataProvider planosSeguimentoDataProvider; + private tabledataproviders.PlanosConcluidosDataProvider planosConcluidosDataProvider; + private tabledataproviders.EstatisticaPlanoDataProvider estatisticaPlanoDataProvider; + // + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + //
+ + //menu + private boolean disableMenu = false; + private boolean disableMenuAnalises = false; + private boolean disableMenuPlanos = false; + private boolean disableMenuUtilizadores = false; + private boolean disableMenuDadosUtilizador = false; + private boolean disableMenuEstatisticas = false; + + private boolean renderSubHeader = false; + private boolean renderTopMenuImages = true; + + //fase + private int fase = 1; + + private HashMap valoresHash; + private HashMap areasHash; + private HashMap riscosHash; + + private Integer anoChoice; + + public enum PAGINATION_ENUM + { + NORMAL( 0, "Normal" ), + PATRIMONIAIS( 1, "Patrimoniais" ) + ; + + private Integer code = null; + private String type = null; + + PAGINATION_ENUM( Integer code, String type ) + { + this.code = code; + this.type = type; + } + + public Integer getCode() + { + return code; + } + + public String getType() + { + return type; + } + + } + + private Map< PAGINATION_ENUM, Pagination > paginationMap = null; +// private Pagination pagination = null; + + private String logoEmpresaUrl = ""; + + private Boolean isSearchingPlanosActuacao = Boolean.FALSE; + + + /** + *

Construct a new session data bean instance.

+ */ + public SessionBean1() { + msg = ""; + + planosActualDataProvider = new tabledataproviders.PlanosActualDataProvider(); + planosSeguimentoDataProvider = new tabledataproviders.PlanosSeguimentoDataProvider(); + planosConcluidosDataProvider = new tabledataproviders.PlanosConcluidosDataProvider(); + estatisticaPlanoDataProvider = new tabledataproviders.EstatisticaPlanoDataProvider(); + planoId = null; + + } + + /** + *

This method is called when this bean is initially added to + * session scope. Typically, this occurs as a result of evaluating + * a value binding or method binding expression, which utilizes the + * managed bean facility to instantiate this bean and store it into + * session scope.

+ * + *

You may customize this method to initialize and cache data values + * or resources that are required for the lifetime of a particular + * user session.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException( e ); + log("SessionBean1 Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e: new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

This method is called when the session containing it is about to be + * passivated. Typically, this occurs in a distributed servlet container + * when the session is about to be transferred to a different + * container instance, after which the activate() method + * will be called to indicate that the transfer is complete.

+ * + *

You may customize this method to release references to session data + * or resources that can not be serialized with the session itself.

+ */ + @Override + public void passivate() { + } + + /** + *

This method is called when the session containing it was + * reactivated.

+ * + *

You may customize this method to reacquire references to session + * data or resources that could not be serialized with the + * session itself.

+ */ + @Override + public void activate() { + } + + /** + *

This method is called when this bean is removed from + * session scope. Typically, this occurs as a result of + * the session timing out or being terminated by the application.

+ * + *

You may customize this method to clean up resources allocated + * during the execution of the init() method, or + * at any later time during the lifetime of the application.

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public boolean isLoggedIn() { + return loggedIn; + } + + public void setLoggedIn(boolean loggedIn) { + this.loggedIn = loggedIn; + } + + public tabledataproviders.PlanosActualDataProvider getPlanosActualDataProvider() { + return planosActualDataProvider; + } + + public void setPlanosActualDataProvider(tabledataproviders.PlanosActualDataProvider planosActualDataProvider) { + this.planosActualDataProvider = planosActualDataProvider; + } + + public tabledataproviders.PlanosSeguimentoDataProvider getPlanosSeguimentoDataProvider() { + return planosSeguimentoDataProvider; + } + + public void setPlanosSeguimentoDataProvider(tabledataproviders.PlanosSeguimentoDataProvider planosSeguimentoDataProvider) { + this.planosSeguimentoDataProvider = planosSeguimentoDataProvider; + } + + public tabledataproviders.PlanosConcluidosDataProvider getPlanosConcluidosDataProvider() { + return planosConcluidosDataProvider; + } + + public void setPlanosConcluidosDataProvider(tabledataproviders.PlanosConcluidosDataProvider planosConcluidosDataProvider) { + this.planosConcluidosDataProvider = planosConcluidosDataProvider; + } + + public tabledataproviders.EstatisticaPlanoDataProvider getEstatisticaPlanoDataProvider() { + return estatisticaPlanoDataProvider; + } + + public void setEstatisticaPlanoDataProvider(tabledataproviders.EstatisticaPlanoDataProvider estatisticaPlanoDataProvider) { + this.estatisticaPlanoDataProvider = estatisticaPlanoDataProvider; + } + + public Integer getPlanoId() { + return planoId; + } + + public void setPlanoId(Integer planoId) { + this.planoId = planoId; + } + + public Utilizador getCurrentUser() { + return currentUser; + } + + public void setCurrentUser(Utilizador currentUser) { + this.currentUser = currentUser; + } + + public boolean isDisableMenu() { + return disableMenu; + } + + public void setDisableMenu(boolean disableMenu) { + System.out.println("DISABLE MENU : " + disableMenu); + setDisableMenuAnalises(disableMenu); + //setDisableMenuPlanos(disableMenu); + setDisableMenuUtilizadores(disableMenu); + setDisableMenuDadosUtilizador(disableMenu); + this.disableMenu = disableMenu; + } + + public boolean isDisableMenuAnalises() { + return disableMenuAnalises; + } + + public void setDisableMenuAnalises(boolean disableMenuAnalises) { + this.disableMenuAnalises = disableMenuAnalises; + } + + public boolean isDisableMenuPlanos() { + return disableMenuPlanos; + } + + public void setDisableMenuPlanos(boolean disableMenuPlanos) { + this.disableMenuPlanos = disableMenuPlanos; + } + + public boolean isDisableMenuUtilizadores() { + return disableMenuUtilizadores; + } + + public void setDisableMenuUtilizadores(boolean disableMenuUtilizadores) { + this.disableMenuUtilizadores = disableMenuUtilizadores; + } + + public boolean isDisableMenuDadosUtilizador() { + return disableMenuDadosUtilizador; + } + + public void setDisableMenuDadosUtilizador(boolean disableMenuDadosUtilizador) { + this.disableMenuDadosUtilizador = disableMenuDadosUtilizador; + } + + public boolean isDisableMenuEstatisticas() { + return disableMenuEstatisticas; + } + + public void setDisableMenuEstatisticas(boolean disableMenuEstatisticas) { + this.disableMenuEstatisticas = disableMenuEstatisticas; + } + + public int getFase() { + return fase; + } + + public void setFase(int fase) { + this.fase = fase; + } + + public PlanoActuacao getPlanoActuacao() { + return planoActuacao; + } + + public void setPlanoActuacao(PlanoActuacao planoActuacao) { + this.planoActuacao = planoActuacao; + } + + private Integer irParaChoice; + + public Integer getIrParaChoice() { + return irParaChoice; + } + + public void setIrParaChoice(Integer irParaChoice) { + this.irParaChoice = irParaChoice; + } + + private com.sun.webui.jsf.model.Option[] irParaOptions; + + public com.sun.webui.jsf.model.Option[] getIrParaOptions() { + return irParaOptions; + } + + public void setIrParaOptions(com.sun.webui.jsf.model.Option[] irParaOptions) { + this.irParaOptions = irParaOptions; + } + + public HashMap getAreasHash() { + return areasHash; + } + + public void setAreasHash(HashMap areasHash) { + this.areasHash = areasHash; + } + + public HashMap getRiscosHash() { + return riscosHash; + } + + public void setRiscosHash(HashMap riscosHash) { + this.riscosHash = riscosHash; + } + + + public void addPagination( PAGINATION_ENUM type, Pagination pagination ) + { + if ( paginationMap == null ) + { + paginationMap = new HashMap< PAGINATION_ENUM, Pagination >(); + } + + paginationMap.put( type, pagination ); + } + + public Pagination getPagination( PAGINATION_ENUM type ) + { + Pagination pagination = null; + if ( paginationMap != null ) + { + pagination = paginationMap.get( type ); + } + return pagination; + } +// public Pagination getPagination() { +// return pagination; +// } +// +// public void setPagination(Pagination pagination) { +// this.pagination = pagination; +// } + + public Risco getCurrentRisco() { + return currentRisco; + } + + public void setCurrentRisco(Risco currentRisco) { + this.currentRisco = currentRisco; + } + + public boolean isRenderSubHeader() { + return renderSubHeader; + } + + public void setRenderSubHeader(boolean renderSubHeader) { + this.renderSubHeader = renderSubHeader; + } + + public boolean isRenderTopMenuImages() { + return renderTopMenuImages; + } + + public void setRenderTopMenuImages(boolean renderTopMenuImages) { + this.renderTopMenuImages = renderTopMenuImages; + } + + public Valor getCurrentValor() { + return currentValor; + } + + public void setCurrentValor(Valor currentValor) { + this.currentValor = currentValor; + } + + public HashMap getValoresHash() { + return valoresHash; + } + + public void setValoresHash(HashMap valoresHash) { + this.valoresHash = valoresHash; + } + + public String getLogoEmpresaUrl() { + return logoEmpresaUrl; + } + + public void setLogoEmpresaUrl(String logoEmpresaUrl) { + this.logoEmpresaUrl = logoEmpresaUrl; + } + + public Boolean getIsSearchingPlanosActuacao() { + return isSearchingPlanosActuacao; + } + + public void setIsSearchingPlanosActuacao(Boolean isSearchingPlanosActuacao) { + this.isSearchingPlanosActuacao = isSearchingPlanosActuacao; + } + + public String getAatSessionID() { + return aatSessionID; + } + + public void setAatSessionID(String aatSessionID) { + this.aatSessionID = aatSessionID; + } + + public Integer getAnoChoice() + { + return anoChoice; + } + + public void setAnoChoice( Integer anoChoice ) + { + this.anoChoice = anoChoice; + } + +} diff --git a/trunk/PlanosActuacao/src/planosactuacao/Test.java b/trunk/PlanosActuacao/src/planosactuacao/Test.java new file mode 100644 index 00000000..41f0d9db --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/Test.java @@ -0,0 +1,74 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package planosactuacao; + +import db.entidades.Area; +import db.entidades.Medida; +import db.entidades.PlanoActuacao; +import db.entidades.PostoTrabalho; +import db.entidades.Risco; +import db.entidades.Valor; +import java.util.List; + +/** + * + * @author lluis + */ +public class Test { + private PlanoActuacao p; + + public static void showPlanoTree(PlanoActuacao p) + { + System.out.println("====================================================="); + System.out.println(" PLANO : " + p.getData_visita_str()); + showAreas(p.getAreas()); + System.out.println("====================================================="); + } + + private static void showAreas(List areas) + { + for(Area a : areas) + { + System.out.println("\t" + a.getDescricao()); + showRiscos(a.getRiscos()); + } + } + + private static void showRiscos(List riscos) + { + for(Risco r : riscos) + { + System.out.println("\t\t" + r.getDescricao()); + showValores(r.getValores()); + } + } + + private static void showValores(List valores) + { + for(Valor v : valores) + { + System.out.println("\t\t\t" + v.getValorQuantitativo()); +// showMedidas(v.getMedidas()); + } + } + + private static void showMedidas(List medidas) + { + for(Medida m : medidas) + { + System.out.println("\t\t\t" + m.getDescricao()); + showPostos(m.getPostos()); + } + } + + private static void showPostos(List postos) + { + for(PostoTrabalho p : postos) + { + System.out.println("\t\t\t\t" + p.getDescricao()); + } + } +} diff --git a/trunk/PlanosActuacao/src/planosactuacao/ViewPlano.java b/trunk/PlanosActuacao/src/planosactuacao/ViewPlano.java new file mode 100644 index 00000000..4a1e6dde --- /dev/null +++ b/trunk/PlanosActuacao/src/planosactuacao/ViewPlano.java @@ -0,0 +1,1021 @@ +/* + * ViewPlano.java + * + * Created on Oct 20, 2008, 10:39:31 AM + */ +package planosactuacao; + +import com.evolute.utils.error.ErrorLogger; +import com.sun.rave.web.ui.appbase.AbstractPageBean; +import com.sun.webui.jsf.component.Button; +import com.sun.webui.jsf.component.PageSeparator; +import com.sun.webui.jsf.component.PanelGroup; +import com.sun.webui.jsf.component.StaticText; +import com.sun.webui.jsf.component.Table; +import com.sun.webui.jsf.component.TableRowGroup; +import db.entidades.Area; +import db.entidades.LinhaEstatistica; +import db.entidades.Medida; +import db.entidades.PlanoActuacao; +import db.entidades.PostoTrabalho; +import db.entidades.Risco; +import db.providers.PlanosDataProvider; +import db.providers.RiscoLogic; +import db.providers.UtilizadoresLogic; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import javax.faces.FacesException; +import javax.faces.component.html.HtmlPanelGrid; +import utils.Global; + +/** + *

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.

+ * + * @author lluis + */ +public class ViewPlano extends AbstractPageBean { + // + + private Table tableEstatistica = new Table(); + private TableRowGroup tableRowGroupEstatisticas = new TableRowGroup(); + protected boolean concluido = true; + + /** + *

Automatically managed component initialization. WARNING: + * This method is automatically generated, so any user-specified code inserted + * here is subject to being replaced.

+ */ + private void _init() throws Exception { + } + + public Table getTableEstatistica() + { + return tableEstatistica; + } + + public void setTableEstatistica( Table tableEstatistica ) + { + this.tableEstatistica = tableEstatistica; + } + + public TableRowGroup getTableRowGroupEstatisticas() + { + return tableRowGroupEstatisticas; + } + + public void setTableRowGroupEstatisticas( TableRowGroup tableRowGroupEstatisticas ) + { + this.tableRowGroupEstatisticas = tableRowGroupEstatisticas; + } + + private Button butVoltar = new Button(); + + public Button getButVoltar() { + return butVoltar; + } + + public void setButVoltar(Button b) { + this.butVoltar = b; + } + private HtmlPanelGrid gridLayout = new HtmlPanelGrid(); + + public HtmlPanelGrid getGridLayout() { + return gridLayout; + } + + public void setGridLayout(HtmlPanelGrid hpg) { + this.gridLayout = hpg; + } + //
+ HtmlPanelGrid gridPlano; + HtmlPanelGrid gridArea; + HtmlPanelGrid gridAreaContainer; + HtmlPanelGrid gridRisco; + HtmlPanelGrid gridValor; + HtmlPanelGrid gridMedida; + HtmlPanelGrid gridPosto; + HtmlPanelGrid gridResponsavel; + PanelGroup pg; + StaticText st; + + + + /** + *

Construct a new Page bean instance.

+ */ + public ViewPlano() { + } + + /** + *

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.

+ * + *

Note that, if the current request is a postback, the property + * values of the components do not represent any + * values submitted with this request. Instead, they represent the + * property values that were saved for this view when it was rendered.

+ */ + @Override + 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 + + // + // Initialize automatically managed components + // *Note* - this logic should NOT be modified + try { + _init(); + } catch (Exception e) { + ErrorLogger.logException(e); + log("ViewPlano Initialization Failure", e); + throw e instanceof FacesException ? (FacesException) e : new FacesException(e); + } + + // + // Perform application initialization that must complete + // *after* managed components are initialized + // TODO - add your own initialization code here + } + + /** + *

Callback method that is called after the component tree has been + * restored, but before any event processing takes place. This method + * will only 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.

+ */ + @Override + public void preprocess() { + } + + /** + *

Callback method that is called just before rendering takes place. + * This method will only 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.

+ */ + @Override + public void prerender() { + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + showPlano(p); + } + + /** + *

Callback method that is called after rendering is completed for + * this request, if init() was called (regardless of whether + * or not this was the page that was actually rendered). Customize this + * method to release resources acquired in the init(), + * preprocess(), or prerender() methods (or + * acquired during execution of an event handler).

+ */ + @Override + public void destroy() { + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected SessionBean1 getSessionBean1() { + return (SessionBean1) getBean("SessionBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected ApplicationBean1 getApplicationBean1() { + return (ApplicationBean1) getBean("ApplicationBean1"); + } + + /** + *

Return a reference to the scoped data bean.

+ * + * @return reference to the scoped data bean + */ + protected RequestBean1 getRequestBean1() { + return (RequestBean1) getBean("RequestBean1"); + } + + private void showPlano(PlanoActuacao p) { + System.out.println("\nViewPlano . showPlano( " + p.getId() + " ) : \n"); + + gridPlano = new HtmlPanelGrid(); + gridPlano.setId("gridPlano"); + gridPlano.setWidth("100%"); + gridPlano.setColumns(1); + gridPlano.setStyle("background-color: #f6f4e8; border: solid 1px #000000"); + gridPlano.setColumnClasses("gridColCenter"); + //lblTop.setText("Plano de actuação da auditoria " + p.getData_visita_str()); + + if (p.getConcluidoPorDesactivacao()) { + StaticText st = new StaticText(); + st.setText("N\u00E3o realizado por falta de cumprimento do prazo."); + st.setStyle("color: #FF0000; font-weight: bold; font-size: 13px;"); + gridPlano.getChildren().add(st); + } + concluido = p.getFase() != null && p.getFase().intValue() == Global.FASE_CONCLUIDO && !p.getConcluidoPorDesactivacao(); + gridLayout.getChildren().add(gridPlano); + showAreas(p.getAreas()); + showValidacoes(gridPlano, p); + List linhasEstatistica = null; + try + { + linhasEstatistica = PlanosDataProvider.getInstance().getEstatisticaForPlanoId( p.getId() ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + linhasEstatistica = new ArrayList(); + } + getSessionBean1().getEstatisticaPlanoDataProvider().setList( linhasEstatistica ); + } + + private void showAreas(List areas) { + int i = 0; + for (Area area : areas) { + i++; + gridArea = new HtmlPanelGrid(); + gridArea.setColumns(1); + gridArea.setColumnClasses("gridColCenter"); + gridArea.setWidth("100%"); + + gridPlano.getChildren().add(gridArea); + + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Área: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setId("fakeLink" + i); + st.setStyleClass("fakeLink"); + st.setOnMouseOver("this.style.textDecoration = 'underline'"); + st.setOnMouseOut("this.style.textDecoration = 'none'"); + st.setOnClick("expand(this)"); + st.setEscape(false); + st.setText( area.getDescricao() ); + pg.getChildren().add(st); + + gridArea.getChildren().add(pg); + + gridAreaContainer = new HtmlPanelGrid(); + gridAreaContainer.setId("area_container" + i); + ////gridAreaContainer.setStyle("border: solid 1px #000000; width: 100%;"); + gridAreaContainer.setStyleClass("hidden"); + //gridAreaContainer.setStyleClass("visible"); + gridAreaContainer.setColumns(1); + gridAreaContainer.setColumnClasses("gridColLeft"); + gridAreaContainer.setWidth("100%"); + + gridArea.getChildren().add(gridAreaContainer); + showRiscos(area.getRiscos()); + } + } + + private void showRiscos(List riscos) { + int rCount = 0; + Collections.sort(riscos, new Comparator() { + + @Override + public int compare(Risco o1, Risco o2) { + // false first, true after + return o1.getIsPatrimonial().compareTo(o2.getIsPatrimonial()); + } + }); + + for (Risco risco : riscos) { + boolean isPatrimonial = risco.getIsPatrimonial(); + String riscoTitle = "Risco" + (isPatrimonial ? " Patrimonial" : "") + ": "; + + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setColumnClasses("gridColLeft"); + //grd.setStyle("border: solid 1px #0000FF; display: inline; width: 100%"); + grd.setStyle("display: block; width: 100%"); + grd.setWidth("100%"); + //grd.setStyleClass("centerBlock"); + //gridArea.getChildren().add(grd); + gridAreaContainer.getChildren().add(grd); + + gridRisco = new HtmlPanelGrid(); + //gridRisco.setStyleClass("centerBlock"); + gridRisco.setStyle("display: block; width: 98%"); + gridRisco.setWidth("98%"); + gridRisco.setColumns(1); + gridRisco.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridRisco); + + + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText(riscoTitle); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText( risco.getDescricao() ); + pg.getChildren().add(st); + gridRisco.getChildren().add(pg); + //showValores(risco.getValores()); + showValor(risco); + //showMedidas(risco.getMedidas()); + + if (rCount < riscos.size() - 1) { + showSeparator(); + } + + rCount++; + } + } + + private void showValor(Risco r) { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + grd.setStyleClass("centerBlock"); + grd.setStyle("display: block"); + //gridRisco.getChildren().add(grd); + + gridValor = new HtmlPanelGrid(); + gridRisco.getChildren().add(gridValor); + //gridValor.setStyleClass("centerBlock"); + gridValor.setStyle("display: block"); + gridValor.setWidth("100%"); + gridValor.setColumns(1); + gridValor.setColumnClasses("gridColLeft"); + //grd.getChildren().add(gridValor); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Valor: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(RiscoLogic.getInstance().getValor(r)); + + pg.getChildren().add(st); + gridValor.getChildren().add(pg); + + showMedidas(r.getMedidas()); + + grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + //grd.setStyleClass("centerBlock"); + gridValor.getChildren().add(grd); + HtmlPanelGrid gridParecer = new HtmlPanelGrid(); + gridParecer.setStyleClass("centerBlock"); + gridParecer.setStyle("display: block"); + gridParecer.setWidth("98%"); + gridParecer.setColumns(1); + gridParecer.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridParecer); + + if (r.getResponsavel_execucao() != null) { + if (r.getResponsavel_execucao().trim().length() > 0) { + pg = new PanelGroup(); + + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Responsável de execução: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(r.getResponsavel_execucao().toString()); + pg.getChildren().add(st); + + if (r.getPor() != null) { + if (r.getPor().trim().length() > 0) { + st = new StaticText(); + st.setEscape(false); + st.setText(" "); + pg.getChildren().add(st); + + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("POR:  "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(r.getPor().toString()); + pg.getChildren().add(st); + } + } + + gridParecer.getChildren().add(pg); + } + } + + if (r.getRecursos_necessarios() != null) { + if (r.getRecursos_necessarios().trim().length() > 0) { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Recursos necessários: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(r.getRecursos_necessarios().toString()); + pg.getChildren().add(st); + gridParecer.getChildren().add(pg); + } + } + + if (r.getData_inicio() != null) { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Data início: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + String data_str = ""; + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + data_str = formatter.format(r.getData_inicio()); + st.setText(data_str); + pg.getChildren().add(st); + gridParecer.getChildren().add(pg); + } + + if (r.getData_fim() != null) { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Data fim: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + String data_str = ""; + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + data_str = formatter.format(r.getData_fim()); + st.setText(data_str); + pg.getChildren().add(st); + gridParecer.getChildren().add(pg); + } + + if (r.getParecer_dl() != null) { + if (r.getParecer_dl().trim().length() > 0) { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Parecer DL: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(r.getParecer_dl().toString()); + pg.getChildren().add(st); + gridParecer.getChildren().add(pg); + } + } + + if (r.getParecer_dns() != null) { + if (r.getParecer_dns().trim().length() > 0) { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Parecer DNS: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(r.getParecer_dns().toString()); + pg.getChildren().add(st); + gridParecer.getChildren().add(pg); + + } + } + + if (r.getVerificacao_siprp() != null) { + if (r.getVerificacao_siprp().trim().length() > 0) { + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Verificação SIPRP: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText(r.getVerificacao_siprp().toString()); + pg.getChildren().add(st); + gridParecer.getChildren().add(pg); + } + } + } + +// private void showValores( List< Valor > valores ) +// { +// for ( Valor valor : valores ) +// { +// HtmlPanelGrid grd = new HtmlPanelGrid(); +// grd.setColumns( 1 ); +// grd.setWidth( "100%" ); +// //grd.setStyleClass("centerBlock"); +// //gridRisco.getChildren().add(grd); +// +// gridValor = new HtmlPanelGrid(); +// gridRisco.getChildren().add( gridValor ); +// ////gridValor.setStyleClass("centerBlock"); +// gridValor.setWidth( "100%" ); +// gridValor.setColumns( 1 ); +// gridValor.setColumnClasses( "gridColLeft" ); +// //grd.getChildren().add(gridValor); +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Valor: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// if(valor.getValorQuantitativo() == null) +// { +// st.setText(" - "); +// } +// else +// { +// st.setText(valor.getValorQuantitativo().toString()); +// } +// pg.getChildren().add(st); +// gridValor.getChildren().add(pg); +// +// showMedidas(valor.getMedidas()); +// +// grd = new HtmlPanelGrid(); +// grd.setColumns(1); +// grd.setWidth("100%"); +// ////grd.setStyleClass("centerBlock"); +// gridValor.getChildren().add(grd); +// HtmlPanelGrid gridParecer = new HtmlPanelGrid(); +// gridParecer.setStyleClass("centerBlock"); +// gridParecer.setWidth("98%"); +// gridParecer.setColumns(1); +// gridParecer.setColumnClasses("gridColLeft"); +// grd.getChildren().add(gridParecer); +// +// if(valor.getResponsavel_execucao() != null) +// { +// if(valor.getResponsavel_execucao().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Responsável de execução: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(valor.getResponsavel_execucao().toString()); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// } +// } +// +// if(valor.getRecursos_necessarios() != null) +// { +// if(valor.getRecursos_necessarios().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Recursos necessários: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(valor.getRecursos_necessarios().toString()); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// } +// } +// +// if(valor.getData_inicio() != null) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Data início: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// String data_str = ""; +// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); +// data_str = formatter.format(valor.getData_inicio()); +// st.setText(data_str); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// } +// +// if(valor.getData_fim() != null) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Data fim: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// String data_str = ""; +// SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); +// data_str = formatter.format(valor.getData_fim()); +// st.setText(data_str); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// } +// +// if(valor.getParecer_dl() != null) +// { +// if(valor.getParecer_dl().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Parecer DL: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(valor.getParecer_dl().toString()); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// +// } +// } +// +// if(valor.getParecer_dns() != null) +// { +// if(valor.getParecer_dns().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Parecer DNS: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(valor.getParecer_dns().toString()); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// +// } +// } +// +// if(valor.getVerificacao_siprp() != null) +// { +// if(valor.getVerificacao_siprp().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Verificação SIPRP: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(valor.getVerificacao_siprp().toString()); +// pg.getChildren().add(st); +// gridParecer.getChildren().add(pg); +// +// } +// } +// // +// } +// } + private void showMedidas(List medidas) { + for (Medida medida : medidas) { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + ////grd.setStyleClass("centerBlock"); + grd.setStyle("display: block"); + gridValor.getChildren().add(grd); + + gridMedida = new HtmlPanelGrid(); + ////gridMedida.setStyleClass("centerBlock"); + gridMedida.setStyle("display: block"); + gridMedida.setWidth("98%"); + gridMedida.setColumns(1); + gridMedida.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridMedida); + + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Medida: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText( medida.getDescricao() ); + pg.getChildren().add(st); + gridMedida.getChildren().add(pg); + + showPostos(medida.getPostos()); + } + } + + private void showPostos(List postos) { + for (PostoTrabalho posto : postos) { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setStyle("display: block"); + grd.setWidth("100%"); + gridMedida.getChildren().add(grd); + + gridPosto = new HtmlPanelGrid(); + gridPosto.setStyle("display: block"); + gridPosto.setWidth("98%"); + gridPosto.setColumns(1); + gridPosto.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridPosto); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setStyleClass("label"); + st.setText("Posto de trabalho: "); + pg.getChildren().add(st); + st = new StaticText(); + st.setEscape(false); + st.setText( posto.getDescricao() ); + pg.getChildren().add(st); + gridPosto.getChildren().add(pg); + } + } + + private void showValidacoes(HtmlPanelGrid grid, PlanoActuacao p) { + SimpleDateFormat DF = new SimpleDateFormat("dd-MM-yyyy"); + + HtmlPanelGrid gridValidacoes = new HtmlPanelGrid(); + gridValidacoes.setColumns(1); + gridValidacoes.setColumnClasses("gridColLeft"); + gridValidacoes.setWidth("100%"); + + // 1 + System.out.println("showValidacoes() : 1. (Auditoria) " + p.getData_visita()); + if (p.getData_visita() != null) { + StaticText visitaText = new StaticText(); + visitaText.setEscape(false); + visitaText.setText("Data da auditoria: " + (p.getData_visita() == null ? "" : DF.format(p.getData_visita()))); + gridValidacoes.getChildren().add(visitaText); + } + + // 2 + System.out.println("showValidacoes() : 2. (Disponibilizacao) " + p.getData_disponibilizacao()); + if (p.getData_disponibilizacao() != null) { + StaticText dispText = new StaticText(); + dispText.setEscape(false); + dispText.setText("Data de disponibilizacao online: " + (p.getData_disponibilizacao() == null ? "" : DF.format(p.getData_disponibilizacao()))); + gridValidacoes.getChildren().add(dispText); + } + + // 3 + System.out.println("showValidacoes() : 3. (Validacao Seg) " + p.getData_validacao_seg()); + if (p.getData_validacao_seg() != null) { + StaticText segText = new StaticText(); + segText.setEscape(false); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID(p.getUser_seg()); + segText.setText("Validado por " + nome + " (Segurança)" + (p.getData_validacao_seg() == null ? "" : " a " + DF.format(p.getData_validacao_seg()))); + gridValidacoes.getChildren().add(segText); + } + + // 4 + System.out.println("showValidacoes() : 4. (Validacao DL) " + p.getValidacao_director_loja()); + if (p.getValidacao_director_loja()) { + StaticText valDirLojaText = new StaticText(); + valDirLojaText.setEscape(false); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID(p.getUser_dir_loja()); + + + String validacaoText = "Validado por " + nome + " (Director de Loja)" + + (p.getData_validacao_dir_loja() == null ? "" : " a " + DF.format(p.getData_validacao_dir_loja())); + valDirLojaText.setText(validacaoText); + gridValidacoes.getChildren().add(valDirLojaText); + + if (p.getObservacoes_dl() != null && !"".equals(p.getObservacoes_dl().trim())) { + StaticText obsTitleText = new StaticText(); + obsTitleText.setEscape(false); + obsTitleText.setText("Observações gerais DL: "); + + StaticText obsText = new StaticText(); + obsText.setEscape(false); + obsText.setText(p.getObservacoes_dl()); + + gridValidacoes.getChildren().add(obsTitleText); + gridValidacoes.getChildren().add(obsText); + } + } + + // 5 + System.out.println("showValidacoes() : 5. (Validacao DNS) " + p.getValidacao_dns()); + if (p.getValidacao_dns()) { + StaticText valDnsText = new StaticText(); + valDnsText.setEscape(false); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID(p.getUser_dns()); + valDnsText.setText("Validado por " + nome + " (Director Nacional de Segurança)" + (p.getData_validacao_dns() == null ? "" : " a " + DF.format(p.getData_validacao_dns()))); + gridValidacoes.getChildren().add(valDnsText); + + if (p.getObservacoes_dns() != null && !"".equals(p.getObservacoes_dns().trim())) { + StaticText obsTitleText = new StaticText(); + obsTitleText.setEscape(false); + obsTitleText.setText("Observações gerais DNS: "); + + StaticText obsText = new StaticText(); + obsText.setEscape(false); + obsText.setText(p.getObservacoes_dns()); + + gridValidacoes.getChildren().add(obsTitleText); + gridValidacoes.getChildren().add(obsText); + } + } + + // 6 + System.out.println("showValidacoes() : 6. (Validacao HS) " + p.getValidacao_hs()); + if (p.getValidacao_hs()) { + StaticText valHsText = new StaticText(); + valHsText.setEscape(false); + String nome = UtilizadoresLogic.getInstance().getNomeUtilizadorByID(p.getUser_hs()); + valHsText.setText("Validado por " + nome + " (Técnico Superior de SHST)" + (p.getData_validacao_hs() == null ? "" : " a " + DF.format(p.getData_validacao_hs()))); + gridValidacoes.getChildren().add(valHsText); + } + + grid.getChildren().add(gridValidacoes); + } + +// private void showValidacoes(HtmlPanelGrid grid, PlanoActuacao p) +// { +// boolean hasValidations = false; +// HtmlPanelGrid grd = new HtmlPanelGrid(); +// grd.setColumns(1); +// grd.setColumnClasses("gridColLeft"); +// grd.setWidth("100%"); +// if(p.getValidacao_director_loja().booleanValue()) +// { +// hasValidations = true; +// StaticText st = new StaticText(); +// st.setEscape(false); +// //st.setStyleClass("label"); +// String nome = ""; +// try +// { +// UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); +// Utilizador user = udp.getUtilizador(p.getUser_dir_loja()); +// nome = user.getNome(); +// } +// catch(Exception ex) +// { +// ErrorLogger.logException( ex ); +// } +// st.setText("Validado por " + nome + " (Director de Loja) a " + p.getData_validacao_dir_loja_str()); +// grd.getChildren().add(st); +// +// if(p.getObservacoes_dl() != null) +// { +// if(p.getObservacoes_dl().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setText("Observações gerais DL: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(p.getObservacoes_dl()); +// pg.getChildren().add(st); +// grd.getChildren().add(pg); +// } +// } +// } +// +// if(p.getValidacao_dns().booleanValue()) +// { +// hasValidations = true; +// StaticText st = new StaticText(); +// st.setEscape(false); +// //st.setStyleClass("label"); +// String nome = ""; +// try +// { +// UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); +// Utilizador user = udp.getUtilizador(p.getUser_dns()); +// nome = user.getNome(); +// } +// catch(Exception ex) +// { +// ErrorLogger.logException( ex ); +// } +// st.setText("Validado por " + nome + " (Director Nacional de Segurança) a " + p.getData_validacao_dns_str()); +// grd.getChildren().add(st); +// +// if(p.getObservacoes_dns() != null) +// { +// if(p.getObservacoes_dns().trim().length() > 0) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setText("Observações gerais DNS: "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(p.getObservacoes_dns()); +// pg.getChildren().add(st); +// grd.getChildren().add(pg); +// } +// } +// } +// +// if(p.getValidacao_hs().booleanValue()) +// { +// hasValidations = true; +// StaticText st = new StaticText(); +// st.setEscape(false); +// //st.setStyleClass("label"); +// String nome = ""; +// try +// { +// UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance(); +// Utilizador user = udp.getUtilizador(p.getUser_hs()); +// nome = user.getNome(); +// } +// catch(Exception ex) +// { +// ErrorLogger.logException( ex ); +// } +// st.setText("Validado por " + nome + " (Técnico de SHS) a " + p.getData_validacao_hs_str()); +// grd.getChildren().add(st); +// +//// if(p.getVerificacao_siprp() != null) +//// { +//// if(p.getVerificacao_siprp().trim().length() > 0) +//// { +//// pg = new PanelGroup(); +//// st = new StaticText(); +//// st.setEscape(false); +//// st.setText("Verificação SIPRP: "); +//// pg.getChildren().add(st); +//// st = new StaticText(); +//// st.setEscape(false); +//// st.setText(p.getVerificacao_siprp()); +//// pg.getChildren().add(st); +//// grd.getChildren().add(pg); +//// } +//// } +// } +// +// if(hasValidations) +// { +// grid.getChildren().add(grd); +// } +// } + private void showSeparator() { + PageSeparator separator = new PageSeparator(); +// separator.setStyle( "margin-bottom: 50px;" ); + gridAreaContainer.getChildren().add(separator); + } + + public String butVoltar_action() { + return "lista_planos"; + } + + public boolean isConcluido() + { + return concluido; + } + + public void setConcluido( boolean concluido ) + { + this.concluido = concluido; + } + + +} +