();
HtmlPanelGrid gridPlano = new HtmlPanelGrid();
HtmlPanelGrid gridRisco;
int risco_id = 0;
int medida_id = 0;
int posto_id = 0;
//page components
TextField txtResponsavelExecucao;
TextArea txtRecursos;
Calendar dtInicio;
Calendar dtFim;
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;
}
/**
* 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) {
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
}
/**
* 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("PRERENDER");
FacesContext fc = getFacesContext();
//boolean isPostback = JSFUtils.isPostBack12(fc);
//boolean isPostback = JSFUtils.isPostBack(fc);
boolean isPostback = JSFUtils.isPostback();
System.out.println("POSTBACK : " + isPostback);
if(!isPostback)
{
initializePlano();
initialize();
fillPlano();
}
else
{
riscos = getSessionBean1().getRiscos();
medidas = getSessionBean1().getMedidas();
postos = getSessionBean1().getPostos();
}
}
/**
* 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 fillPlano()
{
String indent = " ";
Risco r = getNextRisco(plano.getId());
fillRisco(r);
}
private void fillRisco(Risco r)
{
String indent = " ";
if(gridLayout.getChildren().size() > 0)
{
gridLayout.getChildren().clear();
}
gridRisco = new HtmlPanelGrid();
gridRisco.setWidth("100%");
gridRisco.setStyle("border: solid 1px #000000");
gridRisco.setColumns(1);
gridRisco.setColumnClasses("gridColLeft");
pg = new PanelGroup();
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setStyle("color: #2c4d7a");
st.setText("RISCO 1" + ": ");
pg.getChildren().add(st);
st = new StaticText();
st.setEscape(false);
st.setText(r.getDescricao());
pg.getChildren().add(st);
gridRisco.getChildren().add(pg);
st = new StaticText();
st.setEscape(false);
st.setText(" ");
gridRisco.getChildren().add(st);
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(r.getValor().toString());
pg.getChildren().add(st);
gridRisco.getChildren().add(pg);
st = new StaticText();
st.setEscape(false);
st.setText(" ");
gridRisco.getChildren().add(st);
//medidas
Vector meds = getMedidas(r.getId());
for(int i = 0; i < meds.size(); i++)
{
Medida m = medidas.get(i);
if(m.getRisco_id().intValue() == r.getId().intValue())
{
pg = new PanelGroup();
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setText(indent + "Medida" + ": ");
pg.getChildren().add(st);
st = new StaticText();
st.setEscape(false);
st.setText(m.getDescricao());
pg.getChildren().add(st);
gridRisco.getChildren().add(pg);
//postos trabalho
Vector posts = getPostosTrabalho(m.getId());
pg = new PanelGroup();
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setText(indent + indent + "Postos de trabalho afectados" + ": ");
pg.getChildren().add(st);
st = new StaticText();
st.setEscape(false);
String spostos = "";
for(int j = 0; j < posts.size(); j++)
{
PostoTrabalho p = posts.get(j);
spostos += p.getDescricao(); // + " ";
if(j < (posts.size() -1) )
{
spostos += "; ";
}
}
st.setText(spostos);
pg.getChildren().add(st);
gridRisco.getChildren().add(pg);
}
}
st = new StaticText();
st.setEscape(false);
st.setText(" ");
gridRisco.getChildren().add(st);
pg = new PanelGroup();
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setText("Responsável de execução:");
pg.getChildren().add(st);
txtResponsavelExecucao = new TextField();
txtResponsavelExecucao.setColumns(100);
pg.getChildren().add(txtResponsavelExecucao);
gridRisco.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);
gridRisco.getChildren().add(pg);
txtRecursos = new TextArea();
txtRecursos.setColumns(200);
gridRisco.getChildren().add(txtRecursos);
HtmlPanelGrid grd = new HtmlPanelGrid();
grd.setColumns(2);
grd.setColumnClasses("gridCol15, gridCol85");
grd.setId("pgDtInicio");
grd.setStyle("width: 100%");
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setText("Data prevista de início:");
grd.getChildren().add(st);
dtInicio = new Calendar();
grd.getChildren().add(dtInicio);
gridRisco.getChildren().add(grd);
grd = new HtmlPanelGrid();
grd.setColumns(2);
grd.setColumnClasses("gridCol15, gridCol85");
grd.setId("pgDtFim");
grd.setStyle("width: 100%");
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setText("Data prevista de conclusão:");
grd.getChildren().add(st);
dtFim = new Calendar();
grd.getChildren().add(dtFim);
gridRisco.getChildren().add(grd);
gridLayout.getChildren().add(gridRisco);
}
private void initializePlano()
{
getSessionBean1().setRiscosIdx(0);
//plano
plano = new PlanoActuacao();
plano.setId(new Integer(1));
plano.setEstabelecimento_id(new Integer(1));
plano.setEstado(new Integer(1));
getSessionBean1().setPlanoId(new Integer(1));
plano.setDescricao("Plano 1");
//riscos
Risco r = new Risco();
r.setId(new Integer(1));
r.setPlano_id(new Integer(1));
r.setDescricao("Risco A");
r.setValor(new Integer(4));
riscos.add(r);
r = new Risco();
r.setId(new Integer(2));
r.setPlano_id(new Integer(1));
r.setDescricao("Risco B");
r.setValor(new Integer(6));
riscos.add(r);
r = new Risco();
r.setId(new Integer(3));
r.setPlano_id(new Integer(1));
r.setDescricao("Risco C");
r.setValor(new Integer(12));
riscos.add(r);
//medidas
Medida m = new Medida();
m.setId(new Integer(1));
m.setRisco_id(new Integer(1));
m.setDescricao("Medida a");
medidas.add(m);
m = new Medida();
m.setId(new Integer(2));
m.setRisco_id(new Integer(1));
m.setDescricao("Medida b");
medidas.add(m);
m = new Medida();
m.setId(new Integer(3));
m.setRisco_id(new Integer(2));
m.setDescricao("Medida c");
medidas.add(m);
m = new Medida();
m.setId(new Integer(4));
m.setRisco_id(new Integer(2));
m.setDescricao("Medida d");
medidas.add(m);
m = new Medida();
m.setId(new Integer(5));
m.setRisco_id(new Integer(2));
m.setDescricao("Medida e");
medidas.add(m);
m = new Medida();
m.setId(new Integer(6));
m.setRisco_id(new Integer(3));
m.setDescricao("Medida f");
medidas.add(m);
m = new Medida();
m.setId(new Integer(7));
m.setRisco_id(new Integer(3));
m.setDescricao("Medida g");
medidas.add(m);
//postos trabalho
PostoTrabalho p = new PostoTrabalho();
p.setId(new Integer(1));
p.setMedida_id(new Integer(1));
p.setDescricao("posto 1");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(2));
p.setMedida_id(new Integer(1));
p.setDescricao("posto 2");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(3));
p.setMedida_id(new Integer(1));
p.setDescricao("posto 3");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(4));
p.setMedida_id(new Integer(2));
p.setDescricao("posto 4");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(5));
p.setMedida_id(new Integer(2));
p.setDescricao("posto 5");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(6));
p.setMedida_id(new Integer(3));
p.setDescricao("posto 6");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(7));
p.setMedida_id(new Integer(3));
p.setDescricao("posto 7");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(8));
p.setMedida_id(new Integer(4));
p.setDescricao("posto 8");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(9));
p.setMedida_id(new Integer(4));
p.setDescricao("posto 9");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(10));
p.setMedida_id(new Integer(5));
p.setDescricao("posto 10");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(11));
p.setMedida_id(new Integer(5));
p.setDescricao("posto 11");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(12));
p.setMedida_id(new Integer(6));
p.setDescricao("posto 12");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(13));
p.setMedida_id(new Integer(6));
p.setDescricao("posto 13");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(14));
p.setMedida_id(new Integer(7));
p.setDescricao("posto 14");
postos.add(p);
p = new PostoTrabalho();
p.setId(new Integer(15));
p.setMedida_id(new Integer(7));
p.setDescricao("posto 15");
postos.add(p);
getSessionBean1().setRiscos(riscos);
getSessionBean1().setMedidas(medidas);
getSessionBean1().setPostos(postos);
}
private Risco getNextRisco(Integer planoId)
{
System.out.println("GET NEXT RISCO");
System.out.println("RISCOS SIZE : " + riscos.size());
riscos = getSessionBean1().getRiscos();
risco_id = getSessionBean1().getRiscosIdx();
Risco r = riscos.get(risco_id);
if(r != null)
{
if(r.getPlano_id().intValue() != planoId.intValue())
{
r = null;
risco_id = 0;
}
}
risco_id++;
getSessionBean1().setRiscosIdx(risco_id);
return r;
}
private Vector getMedidas(Integer riscoId)
{
Vector meds = new Vector();
medidas = getSessionBean1().getMedidas();
for(int i = 0; i < medidas.size(); i++)
{
Medida m = medidas.get(i);
if(m.getRisco_id().intValue() == riscoId.intValue())
{
meds.add(m);
}
}
return meds;
}
private Vector getPostosTrabalho(Integer medidaId)
{
Vector posts = new Vector();
postos = getSessionBean1().getPostos();
for(int i = 0; i < postos.size(); i++)
{
PostoTrabalho p = postos.get(i);
if(p.getMedida_id().intValue() == medidaId.intValue())
{
posts.add(p);
}
}
return posts;
}
private void initialize()
{
gridPlano.setWidth("100%");
gridPlano.setColumns(1);
gridPlano.setColumnClasses("gridColCenter");
//plano
st = new StaticText();
st.setEscape(false);
st.setStyleClass("label");
st.setStyle("font-size: 16px");
st.setText(plano.getDescricao());
gridPlano.getChildren().add(st);
gridLayout.getChildren().add(gridPlano);
}
public String butGravarPlano_action() {
// TODO: Process the action. Return value is a navigation
// case name where null will return to the same page.
return null;
}
public String butGravarRisco_action() {
// TODO: Process the action. Return value is a navigation
// case name where null will return to the same page.
System.out.println("BUT NEXT RISCO");
Risco r = getNextRisco(getSessionBean1().getPlanoId());
fillRisco(r);
return null;
}
public String butEnviar_action() {
// TODO: Process the action. Return value is a navigation
// case name where null will return to the same page.
processEnviar();
return null;
}
private void processEnviar()
{
}
}