/* * ViewPlano.java * * Created on Oct 20, 2008, 10:39:31 AM */ package planosactuacao; 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.PageSeparator; import com.sun.webui.jsf.component.PanelGroup; import com.sun.webui.jsf.component.StaticText; import db.entidades.Area; 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.UtilizadoresDataProvider; import java.text.SimpleDateFormat; import java.util.List; import javax.faces.FacesException; import javax.faces.component.html.HtmlPanelGrid; /** *

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 { // /** *

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 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) { 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) { gridPlano = new HtmlPanelGrid(); gridPlano.setId("gridPlano"); gridPlano.setWidth("100%"); gridPlano.setColumns(1); gridPlano.setStyle("background-color: #f6f4e8; border: solid 1px #000000"); gridPlano.setColumnClasses("gridColCenter"); //plano //lblTop.setText("Plano de actuação da auditoria " + p.getData_visita_str()); System.out.println( "VIEWPLANO - : " + p.getConcluidoPorDesactivacao() ); 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 ); } gridLayout.getChildren().add(gridPlano); showAreas(p.getAreas()); showValidacoes(gridPlano, p); } 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%"); // st = new StaticText(); // st.setEscape(false); // st.setText("AAAAAAAAA"); // gridAreaContainer.getChildren().add(st); gridArea.getChildren().add(gridAreaContainer); showRiscos(area.getRiscos()); } } private void showRiscos(List riscos) { int rCount = 0; for(Risco risco : riscos) { 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("Risco: "); 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); if(r.getValor() == null) { st.setText("IND"); } else { st.setText(r.getValor().toString()); } 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 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.getValor() == null) { st.setText(" - "); } else { st.setText(valor.getValor().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%"); ////grd.setStyleClass("centerBlock"); gridMedida.getChildren().add(grd); gridPosto = new HtmlPanelGrid(); ////gridPosto.setStyleClass("centerBlock"); 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) { UtilizadoresDataProvider udp = new UtilizadoresDataProvider(); 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 { Utilizador user = udp.getUtilizador(p.getUser_dir_loja()); nome = user.getNome(); } catch(Exception ex) { ex.printStackTrace(); } 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 { Utilizador user = udp.getUtilizador(p.getUser_dns()); nome = user.getNome(); } catch(Exception ex) { ex.printStackTrace(); } 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 { Utilizador user = udp.getUtilizador(p.getUser_hs()); nome = user.getNome(); } catch(Exception ex) { ex.printStackTrace(); } 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() { // TODO: Process the action. Return value is a navigation // case name where null will return to the same page. return "lista_planos"; } }