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.
159 lines
3.8 KiB
159 lines
3.8 KiB
package siprp.higiene.gestao;
|
|
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.Component;
|
|
import java.awt.event.ItemEvent;
|
|
import java.awt.event.ItemListener;
|
|
import java.util.List;
|
|
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JTabbedPane;
|
|
|
|
import leaf.ui.LeafDialog;
|
|
import shst.data.outer.EmpresasData;
|
|
import shst.data.provider.MedicinaDataProvider;
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
|
|
public class EmpresaPanel extends SIPRPLazyLoadedPanel
|
|
{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final String NULL_EMPRESA = "Nenhuma";
|
|
|
|
private final JComboBox comboEmpresa = new JComboBox();
|
|
|
|
private final JCheckBox checkImpressao = new JCheckBox("Imprimir tabela alargada");
|
|
|
|
private final GerirEmpresaPanel panelEmpresa = new GerirEmpresaPanel();
|
|
|
|
private final GerirEstabelecimentosPanel panelEstabelecimentos = new GerirEstabelecimentosPanel();
|
|
|
|
private final JTabbedPane tabs = new JTabbedPane();
|
|
|
|
private EmpresasData empresa = null;
|
|
|
|
public EmpresaPanel()
|
|
{
|
|
startupListeners();
|
|
startupComponents();
|
|
setupLayout();
|
|
placeComponents();
|
|
}
|
|
|
|
private void startupComponents()
|
|
{
|
|
List<EmpresasData> empresas = null;
|
|
try
|
|
{
|
|
MedicinaDataProvider medicinaProvider = MedicinaDataProvider.getProvider();
|
|
empresas = medicinaProvider.getAllEmpresas();
|
|
}
|
|
catch ( Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
|
|
if( empresas != null )
|
|
{
|
|
comboEmpresa.addItem( NULL_EMPRESA );
|
|
for( EmpresasData empresa : empresas )
|
|
{
|
|
comboEmpresa.addItem( empresa );
|
|
}
|
|
}
|
|
tabs.addTab( "Empresa", panelEmpresa );
|
|
tabs.addTab( "Estabelecimentos", panelEstabelecimentos );
|
|
}
|
|
|
|
private void setupLayout()
|
|
{
|
|
double[] cols = new double[]{
|
|
TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM
|
|
};
|
|
double[] rows = new double[]{
|
|
TableLayout.MINIMUM, TableLayout.FILL,
|
|
};
|
|
TableLayout layout = new TableLayout(cols,rows);
|
|
layout.setHGap( 10 );
|
|
layout.setVGap( 10 );
|
|
this.setLayout( layout );
|
|
}
|
|
|
|
private void placeComponents()
|
|
{
|
|
this.add( new JLabel( "Empresa" ), new TableLayoutConstraints( 0, 0 ) );
|
|
this.add( comboEmpresa, new TableLayoutConstraints( 1, 0 ) );
|
|
this.add( checkImpressao, new TableLayoutConstraints( 2, 0 ) );
|
|
this.add( tabs, new TableLayoutConstraints( 0, 1, 2, 1 ) );
|
|
}
|
|
|
|
private void setEmpresa( EmpresasData empresa )
|
|
{
|
|
this.empresa = empresa;
|
|
checkImpressao.setSelected( empresa != null && empresa.getImprimir_tabela_alargada() != null && empresa.getImprimir_tabela_alargada() );
|
|
}
|
|
|
|
private void startupListeners()
|
|
{
|
|
checkImpressao.addItemListener( new ItemListener()
|
|
{
|
|
@Override
|
|
public void itemStateChanged( ItemEvent e )
|
|
{
|
|
try
|
|
{
|
|
if( empresa != null )
|
|
{
|
|
empresa.setImprimir_tabela_alargada( checkImpressao.isSelected() );
|
|
empresa.save();
|
|
}
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
LeafDialog.error( ex );
|
|
}
|
|
}
|
|
} );
|
|
comboEmpresa.addItemListener( new ItemListener()
|
|
{
|
|
@Override
|
|
public void itemStateChanged( ItemEvent e )
|
|
{
|
|
Object item = e.getItem();
|
|
if( item != null && ItemEvent.SELECTED == e.getStateChange() )
|
|
{
|
|
if( item instanceof EmpresasData )
|
|
{
|
|
panelEmpresa.setEmpresa( (EmpresasData) item );
|
|
panelEstabelecimentos.setEmpresa( (EmpresasData) item );
|
|
EmpresaPanel.this.setEmpresa( (EmpresasData) item );
|
|
}
|
|
else
|
|
{
|
|
panelEmpresa.setEmpresa( null );
|
|
panelEstabelecimentos.setEmpresa( null );
|
|
EmpresaPanel.this.setEmpresa( null );
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
}
|
|
|
|
@Override
|
|
protected void refresh()
|
|
{
|
|
Component c = tabs.getSelectedComponent();
|
|
if( c instanceof SIPRPLazyLoadedPanel )
|
|
{
|
|
((SIPRPLazyLoadedPanel)c).init();
|
|
}
|
|
}
|
|
|
|
}
|