forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
5.3 KiB
194 lines
5.3 KiB
package siprp.higiene.relatorio;
|
|
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.CardLayout;
|
|
import java.awt.Dimension;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JPanel;
|
|
|
|
import shst.data.outer.HsRelatorioAreaData;
|
|
import shst.data.outer.HsRelatorioData;
|
|
import shst.data.outer.HsRelatorioPostoData;
|
|
import shst.data.outer.HsRelatorioPostoMedidaData;
|
|
import shst.data.outer.HsRelatorioPostoRiscoData;
|
|
import shst.logic.HigieneSegurancaLogic;
|
|
|
|
public class PlanoActuacaoPanel extends JPanel
|
|
{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final String RISCO_PANEL = "RISCO_PANEL";
|
|
|
|
private static final String MEDIDA_PANEL = "MEDIDA_PANEL";
|
|
|
|
private static final String EMPTY_PANEL = "EMPTY_PANEL";
|
|
|
|
private final VerAreasRelatorioPanel areas = new VerAreasRelatorioPanel();
|
|
|
|
private final GerirMedidasRelatorioPanel riscos = new GerirMedidasRelatorioPanel();
|
|
|
|
private final GerirValoresRiscoPanel valoresRisco = new GerirValoresRiscoPanel();
|
|
|
|
private final GerirMedidaRelatorioPanel valoresMedida = new GerirMedidaRelatorioPanel();
|
|
|
|
private final JPanel emptyPanel = new JPanel();
|
|
|
|
private final JPanel valoresPanel = new JPanel();
|
|
|
|
private final CardLayout cards = new CardLayout();
|
|
|
|
private HsRelatorioData relatorio = null;
|
|
|
|
public PlanoActuacaoPanel()
|
|
{
|
|
startupListeners();
|
|
startupComponents();
|
|
startupLayout();
|
|
placeComponents();
|
|
cards.show( valoresPanel, EMPTY_PANEL );
|
|
}
|
|
|
|
private void startupListeners()
|
|
{
|
|
areas.addPropertyChangeListener( VerAreasRelatorioPanel.SELECTION_CHANGED, new PropertyChangeListener()
|
|
{
|
|
@Override
|
|
public void propertyChange( PropertyChangeEvent evt )
|
|
{
|
|
if( evt.getNewValue() instanceof HsRelatorioPostoData )
|
|
{
|
|
riscos.setPosto( (HsRelatorioPostoData) evt.getNewValue() );
|
|
}
|
|
else
|
|
{
|
|
riscos.setPosto( null );
|
|
}
|
|
}
|
|
} );
|
|
riscos.addPropertyChangeListener( GerirMedidasRelatorioPanel.SELECTION_CHANGED, new PropertyChangeListener()
|
|
{
|
|
@Override
|
|
public void propertyChange( PropertyChangeEvent evt )
|
|
{
|
|
if( evt.getNewValue() instanceof HsRelatorioPostoRiscoData )
|
|
{
|
|
cards.show( valoresPanel, RISCO_PANEL );
|
|
valoresRisco.setRelatorioPostoRisco( (HsRelatorioPostoRiscoData) evt.getNewValue() );
|
|
}
|
|
else if( evt.getNewValue() instanceof HsRelatorioPostoMedidaData )
|
|
{
|
|
cards.show( valoresPanel, MEDIDA_PANEL );
|
|
valoresMedida.setMedida( (HsRelatorioPostoMedidaData) evt.getNewValue() );
|
|
}
|
|
else
|
|
{
|
|
cards.show( valoresPanel, EMPTY_PANEL );
|
|
valoresRisco.setRelatorioPostoRisco( null );
|
|
valoresMedida.setMedida( null );
|
|
}
|
|
}
|
|
} );
|
|
valoresRisco.addPropertyChangeListener( GerirValoresRiscoPanel.VALUE_CHANGED, new PropertyChangeListener()
|
|
{
|
|
@Override
|
|
public void propertyChange( PropertyChangeEvent evt )
|
|
{
|
|
riscos.repaint();
|
|
areas.repaint();
|
|
}
|
|
} );
|
|
valoresMedida.addPropertyChangeListener( GerirMedidaRelatorioPanel.MEDIDA_CHANGED, new PropertyChangeListener()
|
|
{
|
|
@Override
|
|
public void propertyChange( PropertyChangeEvent evt )
|
|
{
|
|
riscos.refresh();
|
|
}
|
|
} );
|
|
}
|
|
|
|
private void startupComponents()
|
|
{
|
|
riscos.setBorder( BorderFactory.createTitledBorder( "Riscos" ) );
|
|
areas.setBorder( BorderFactory.createTitledBorder( "Postos de trabalho" ) );
|
|
areas.setPreferredSize( new Dimension(250,0) );
|
|
}
|
|
|
|
private void startupLayout()
|
|
{
|
|
TableLayout layout = new TableLayout(
|
|
new double[]{ TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.FILL },
|
|
new double[]{ TableLayout.MINIMUM, TableLayout.FILL }
|
|
);
|
|
layout.setHGap( 5 );
|
|
layout.setVGap( 5 );
|
|
setLayout( layout );
|
|
valoresPanel.setLayout(cards);
|
|
}
|
|
|
|
private void placeComponents()
|
|
{
|
|
valoresPanel.add( valoresRisco, RISCO_PANEL );
|
|
valoresPanel.add( valoresMedida, MEDIDA_PANEL );
|
|
valoresPanel.add( emptyPanel, EMPTY_PANEL );
|
|
add( areas, new TableLayoutConstraints( 0, 1, 1, 1 ) );
|
|
add( riscos, new TableLayoutConstraints( 2, 1 ) );
|
|
add( valoresPanel, new TableLayoutConstraints( 3, 1 ) );
|
|
}
|
|
|
|
public void setRelatorio( HsRelatorioData relatorio )
|
|
{
|
|
this.relatorio = relatorio;
|
|
areas.setRelatorio( relatorio );
|
|
riscos.setPosto( null );
|
|
valoresRisco.setRelatorioPostoRisco( null );
|
|
valoresRisco.setEnabled( relatorio != null && relatorio.getIs_submetido() == null );
|
|
valoresMedida.setMedida( null );
|
|
valoresMedida.setEnabled( relatorio != null && relatorio.getIs_submetido() == null );
|
|
}
|
|
|
|
public boolean isValidPlano()
|
|
{
|
|
boolean result = true;
|
|
if( relatorio != null )
|
|
{
|
|
for( HsRelatorioAreaData area : relatorio.fromHsRelatorioArea_relatorio_id() )
|
|
{
|
|
for( HsRelatorioPostoData posto : area.fromHsRelatorioPosto_area_id() )
|
|
{
|
|
for( HsRelatorioPostoRiscoData relRisco : posto.fromHsRelatorioPostoRisco_posto_id() )
|
|
{
|
|
boolean preenchido = relRisco.toValor_qualitativo_id() != null;
|
|
if( !preenchido )
|
|
{
|
|
preenchido = HigieneSegurancaLogic.isProbabilidadeValida( relRisco.getProbabilidade() ) && HigieneSegurancaLogic.isSeveridadeValida( relRisco.getSeveridade() );
|
|
}
|
|
if( !preenchido )
|
|
{
|
|
result = false;
|
|
break;
|
|
}
|
|
}
|
|
if( !result )
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if( !result )
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|