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.
149 lines
4.9 KiB
149 lines
4.9 KiB
package siprp.higiene.gestao;
|
|
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.Dimension;
|
|
import java.awt.GridLayout;
|
|
import java.awt.event.ItemEvent;
|
|
import java.awt.event.ItemListener;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JPanel;
|
|
|
|
import shst.data.outer.EmpresasData;
|
|
import shst.data.outer.EstabelecimentosData;
|
|
import shst.data.outer.HsPostoData;
|
|
import siprp.higiene.gestao.email.AdicionarEmailsPanel;
|
|
import siprp.higiene.gestao.legislacao.AdicionarLegislacaoPanel;
|
|
import siprp.higiene.gestao.normalizacao.AdicionarNormalizacaoPanel;
|
|
import siprp.higiene.gestao.postos.AdicionarAreasPanel;
|
|
import siprp.higiene.gestao.riscos.AdicionarRiscosPanel;
|
|
|
|
public class GerirEstabelecimentosPanel extends JPanel
|
|
{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final String NULL_ESTABELECIMENTO = "Nenhum";
|
|
|
|
private final JComboBox comboEstabelecimentos = new JComboBox();
|
|
private final JPanel panelAreasRiscos = new JPanel();
|
|
private final AdicionarAreasPanel panelAreas = new AdicionarAreasPanel();
|
|
private final AdicionarRiscosPanel panelRiscos = new AdicionarRiscosPanel();
|
|
private final AdicionarEmailsPanel panelEmails = new AdicionarEmailsPanel();
|
|
private final AdicionarLegislacaoPanel panelLegislacao = new AdicionarLegislacaoPanel();
|
|
private final AdicionarNormalizacaoPanel panelNormalizacao = new AdicionarNormalizacaoPanel();
|
|
|
|
public GerirEstabelecimentosPanel()
|
|
{
|
|
startupComponents();
|
|
setupLayout();
|
|
placeComponents();
|
|
startupListeners();
|
|
}
|
|
|
|
private void startupComponents()
|
|
{
|
|
panelAreasRiscos.setBorder( BorderFactory.createTitledBorder( "Riscos por posto de trabalho" ) );
|
|
panelRiscos.setBorder( BorderFactory.createTitledBorder( "Riscos" ) );
|
|
panelEmails.setBorder( BorderFactory.createTitledBorder( "Emails" ) );
|
|
panelLegislacao.setBorder( BorderFactory.createTitledBorder( "Legisla" + ccedil + atilde + "o" ) );
|
|
panelEmails.setPreferredSize( new Dimension(0,150) );
|
|
}
|
|
|
|
private void setupLayout()
|
|
{
|
|
double [] cols = new double[]{ TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, };
|
|
double [] rows = new double[]{ TableLayout.MINIMUM, TableLayout.FILL,TableLayout.FILL, TableLayout.PREFERRED };
|
|
TableLayout layout = new TableLayout( cols, rows );
|
|
layout.setHGap( 5 );
|
|
layout.setVGap( 5 );
|
|
this.setLayout( layout );
|
|
|
|
panelAreasRiscos.setLayout( new GridLayout( 1, 2 ) );
|
|
}
|
|
|
|
private void placeComponents()
|
|
{
|
|
panelAreasRiscos.add( panelAreas );
|
|
panelAreasRiscos.add( panelRiscos );
|
|
|
|
this.add( comboEstabelecimentos, new TableLayoutConstraints( 0, 0, 2, 0 ) );
|
|
this.add( panelAreasRiscos, new TableLayoutConstraints( 0, 1, 1, 3 ) );
|
|
this.add( panelLegislacao, new TableLayoutConstraints( 2, 1 ) );
|
|
this.add( panelNormalizacao, new TableLayoutConstraints( 2, 2 ) );
|
|
this.add( panelEmails, new TableLayoutConstraints( 2, 3 ) );
|
|
}
|
|
|
|
private void startupListeners()
|
|
{
|
|
comboEstabelecimentos.addItemListener( new ItemListener()
|
|
{
|
|
@Override
|
|
public void itemStateChanged( ItemEvent e )
|
|
{
|
|
if( e.getItem() != null && ItemEvent.SELECTED == e.getStateChange() )
|
|
{
|
|
if( e.getItem() instanceof EstabelecimentosData )
|
|
{
|
|
EstabelecimentosData estabelecimento = (EstabelecimentosData) e.getItem();
|
|
panelAreas.setEstabelecimento( estabelecimento );
|
|
panelEmails.setEstabelecimento( estabelecimento );
|
|
panelLegislacao.setEstabelecimento( estabelecimento );
|
|
panelNormalizacao.setEstabelecimento( estabelecimento );
|
|
}
|
|
else
|
|
{
|
|
EstabelecimentosData estabelecimento = null;
|
|
panelAreas.setEstabelecimento( estabelecimento );
|
|
panelEmails.setEstabelecimento( estabelecimento );
|
|
panelLegislacao.setEstabelecimento( estabelecimento );
|
|
panelNormalizacao.setEstabelecimento( estabelecimento );
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
panelAreas.addPropertyChangeListener( AdicionarAreasPanel.SELECTION_CHANGED, new PropertyChangeListener()
|
|
{
|
|
@Override
|
|
public void propertyChange( PropertyChangeEvent evt )
|
|
{
|
|
Object obj = evt.getNewValue();
|
|
if( obj != null && (obj instanceof HsPostoData) )
|
|
{
|
|
panelRiscos.setPosto( (HsPostoData) obj );
|
|
}
|
|
else
|
|
{
|
|
panelRiscos.setPosto( null );
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
|
|
public void setEmpresa( EmpresasData empresa )
|
|
{
|
|
comboEstabelecimentos.removeAllItems();
|
|
System.out.println("setEmpresa!");
|
|
if( empresa != null )
|
|
{
|
|
comboEstabelecimentos.addItem( NULL_ESTABELECIMENTO );
|
|
for( EstabelecimentosData estabelecimento : empresa.fromEstabelecimentos_empresa_id() )
|
|
{
|
|
comboEstabelecimentos.addItem( estabelecimento );
|
|
}
|
|
if( comboEstabelecimentos.getItemCount() > 0 )
|
|
{
|
|
comboEstabelecimentos.setSelectedIndex( 0 );
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|