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.
323 lines
8.7 KiB
323 lines
8.7 KiB
package siprp.higiene.relatorio;
|
|
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.aacute;
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.CardLayout;
|
|
import java.awt.Dimension;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JPanel;
|
|
|
|
import leaf.ui.LeafButton;
|
|
import leaf.ui.LeafIconButton;
|
|
import siprp.database.cayenne.objects.Estabelecimentos;
|
|
import siprp.database.cayenne.objects.HsArea;
|
|
import siprp.database.cayenne.objects.HsPosto;
|
|
import siprp.database.cayenne.objects.HsPostoEstabelecimento;
|
|
import siprp.database.cayenne.objects.HsRelatorio;
|
|
import siprp.database.cayenne.objects.HsRelatorioArea;
|
|
import siprp.database.cayenne.objects.HsRelatorioPosto;
|
|
import siprp.database.cayenne.objects.HsRelatorioPostoMedida;
|
|
import siprp.database.cayenne.objects.HsRelatorioPostoRisco;
|
|
import siprp.database.cayenne.objects.MarcacoesEstabelecimento;
|
|
import siprp.logic.HigieneSegurancaLogic;
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
|
|
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 LeafButton refreshAreasButton = LeafIconButton.createButton( "Actualizar nomes de " + aacute + "reas/postos", PanelRelatorio.ICON_NAME_UNDO );
|
|
|
|
private final JPanel emptyPanel = new JPanel();
|
|
|
|
private final JPanel valoresPanel = new JPanel();
|
|
|
|
private final CardLayout cards = new CardLayout();
|
|
|
|
private HsRelatorio 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 HsRelatorioPosto )
|
|
{
|
|
riscos.setPosto( (HsRelatorioPosto) evt.getNewValue() );
|
|
}
|
|
else
|
|
{
|
|
riscos.setPosto( null );
|
|
}
|
|
}
|
|
} );
|
|
riscos.addPropertyChangeListener( GerirMedidasRelatorioPanel.SELECTION_CHANGED, new PropertyChangeListener()
|
|
{
|
|
@Override
|
|
public void propertyChange( PropertyChangeEvent evt )
|
|
{
|
|
if( evt.getNewValue() instanceof HsRelatorioPostoRisco )
|
|
{
|
|
cards.show( valoresPanel, RISCO_PANEL );
|
|
valoresRisco.setRelatorioPostoRisco( (HsRelatorioPostoRisco) evt.getNewValue() );
|
|
}
|
|
else if( evt.getNewValue() instanceof HsRelatorioPostoMedida )
|
|
{
|
|
cards.show( valoresPanel, MEDIDA_PANEL );
|
|
valoresMedida.setMedida( (HsRelatorioPostoMedida) 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();
|
|
}
|
|
} );
|
|
refreshAreasButton.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
try
|
|
{
|
|
refreshAreas();
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
|
|
private void refreshAreas()
|
|
{
|
|
if( relatorio != null )
|
|
{
|
|
MarcacoesEstabelecimento marcacao = relatorio.getToHsMarcacoesEstabelecimento();
|
|
if( marcacao != null )
|
|
{
|
|
Estabelecimentos estabelecimento = marcacao.getToEstabelecimentos();
|
|
if( estabelecimento != null )
|
|
{
|
|
for( HsPostoEstabelecimento postoEstabelecimento : estabelecimento.getHsPostoEstabelecimentoArray() )
|
|
{
|
|
refreshPostoEstabelecimento( postoEstabelecimento );
|
|
}
|
|
areas.refresh();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void refreshPostoEstabelecimento( HsPostoEstabelecimento postoEstabelecimento )
|
|
{
|
|
if( postoEstabelecimento != null )
|
|
{
|
|
HsPosto posto = postoEstabelecimento.getToHsPosto();
|
|
if( posto != null )
|
|
{
|
|
HsArea area = posto.getToHsArea();
|
|
if( area != null )
|
|
{
|
|
refreshArea( area );
|
|
}
|
|
refreshPosto( posto );
|
|
}
|
|
}
|
|
}
|
|
|
|
private void refreshArea( HsArea area )
|
|
{
|
|
HsRelatorioArea relatorioArea = getAreaInRelatorio( relatorio, area.getId() );
|
|
if( relatorioArea != null )
|
|
{
|
|
relatorioArea.setDescription( area.getDescription() );
|
|
}
|
|
}
|
|
|
|
private HsRelatorioArea getAreaInRelatorio( HsRelatorio relatorio, Integer softRefId )
|
|
{
|
|
HsRelatorioArea result = null;
|
|
if( relatorio != null && softRefId != null )
|
|
{
|
|
for( HsRelatorioArea relatArea : relatorio.getHsRelatorioArea() )
|
|
{
|
|
if( softRefId.equals( relatArea.getHsAreaId() ) )
|
|
{
|
|
result = relatArea;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private void refreshPosto( HsPosto posto )
|
|
{
|
|
HsRelatorioPosto relatorioPosto = getPostoInRelatorio( relatorio, posto.getId() );
|
|
if( relatorioPosto != null )
|
|
{
|
|
relatorioPosto.setDescription( posto.getDescription() );
|
|
relatorioPosto.setIsPrincipal( posto.getIsPrincipal() );
|
|
}
|
|
}
|
|
|
|
private HsRelatorioPosto getPostoInRelatorio( HsRelatorio relatorio, Integer softRefId )
|
|
{
|
|
HsRelatorioPosto result = null;
|
|
if( relatorio != null && softRefId != null )
|
|
{
|
|
for( HsRelatorioArea relatArea : relatorio.getHsRelatorioArea() )
|
|
{
|
|
for( HsRelatorioPosto relatPosto : relatArea.getHsRelatorioPostoArray() )
|
|
{
|
|
if( softRefId.equals( relatPosto.getHsPostoId() ) )
|
|
{
|
|
result = relatPosto;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
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( refreshAreasButton, new TableLayoutConstraints( 0, 0, 1, 0 ) );
|
|
add( areas, new TableLayoutConstraints( 0, 1, 1, 1 ) );
|
|
add( riscos, new TableLayoutConstraints( 2, 1 ) );
|
|
add( valoresPanel, new TableLayoutConstraints( 3, 1 ) );
|
|
}
|
|
|
|
private void setEnabled()
|
|
{
|
|
refreshAreasButton.setEnabled(relatorio != null && relatorio.getIsSubmetido() == null );
|
|
}
|
|
|
|
public void setRelatorio( HsRelatorio relatorio )
|
|
{
|
|
this.relatorio = relatorio;
|
|
areas.setRelatorio( relatorio );
|
|
riscos.setPosto( null );
|
|
valoresRisco.setRelatorioPostoRisco( null );
|
|
valoresRisco.setEnabled( relatorio != null && relatorio.getIsSubmetido() == null );
|
|
valoresMedida.setMedida( null );
|
|
valoresMedida.setEnabled( relatorio != null && relatorio.getIsSubmetido() == null );
|
|
setEnabled( );
|
|
}
|
|
|
|
public boolean isValidPlano()
|
|
{
|
|
boolean result = true;
|
|
if( relatorio != null )
|
|
{
|
|
for( HsRelatorioArea area : relatorio.getHsRelatorioArea() )
|
|
{
|
|
for( HsRelatorioPosto posto : area.getHsRelatorioPostoArray() )
|
|
{
|
|
for( HsRelatorioPostoRisco relRisco : posto.getHsRelatorioPostoRiscoArray() )
|
|
{
|
|
boolean preenchido = relRisco.getToHsRelatorioRiscoValorQualitativo() != 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;
|
|
}
|
|
|
|
}
|
|
|