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.
		
		
		
		
		
			
		
			
				
					
					
						
							387 lines
						
					
					
						
							13 KiB
						
					
					
				
			
		
		
	
	
							387 lines
						
					
					
						
							13 KiB
						
					
					
				/*
 | 
						|
 * EmpresaPanel.java
 | 
						|
 *
 | 
						|
 * Created on 29 de Março de 2004, 11:53
 | 
						|
 */
 | 
						|
 | 
						|
package siprp.ficha;
 | 
						|
 | 
						|
import java.awt.*;
 | 
						|
import java.awt.event.*;
 | 
						|
import javax.swing.*;
 | 
						|
import java.util.*;
 | 
						|
 | 
						|
import com.evolute.utils.data.*;
 | 
						|
import com.evolute.utils.dataui.*;
 | 
						|
import com.evolute.utils.metadb.*;
 | 
						|
import com.evolute.utils.ui.*;
 | 
						|
import com.evolute.utils.ui.button.*;
 | 
						|
import com.evolute.utils.ui.panel.*;
 | 
						|
 | 
						|
import siprp.*;
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @author  fpalma
 | 
						|
 */
 | 
						|
public class EmpresaPanel extends JPanel
 | 
						|
	implements ControllableComponent
 | 
						|
{
 | 
						|
	private JTextField designacaoSocialText;
 | 
						|
	private JTextField estabelecimentoText;
 | 
						|
	private JTextField localidadeText;
 | 
						|
	private RadioButtonFixedPanel servicoSaudeTipoPanel;
 | 
						|
	private JTextField designacaoServicoSaudeText;
 | 
						|
	private JButton defaultServicoSaudeButton;
 | 
						|
	private RadioButtonFixedPanel servicoHigieneTipoPanel;
 | 
						|
	private JTextField designacaoText;
 | 
						|
	private JButton defaultServicoHigieneButton;
 | 
						|
	
 | 
						|
	private FichaDataProvider provider;
 | 
						|
	private ComponentsHashtable components;
 | 
						|
	
 | 
						|
	private MetaObject estabelecimento;
 | 
						|
	private MetaObject empresa;
 | 
						|
	
 | 
						|
	/** Creates a new instance of EmpresaPanel */
 | 
						|
	public EmpresaPanel()
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		provider = (FichaDataProvider)FichaDataProvider.getProvider();
 | 
						|
		setupComponents();
 | 
						|
		setupComponentsHashtable();
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void setupComponents()
 | 
						|
	{
 | 
						|
		setBorder( BorderFactory.createTitledBorder(
 | 
						|
					BorderFactory.createEtchedBorder(),
 | 
						|
					"Empresa/Entidade" ) );
 | 
						|
		
 | 
						|
		JLabel designacaoSocialLabel = new JLabel( "Designa\u00e7\u00e3o Social" );
 | 
						|
		designacaoSocialText = new JTextField();
 | 
						|
//		JPanel servicoSaudePanel = new JPanel();
 | 
						|
		JLabel estabelecimentoLabel = new JLabel( "Estabelecimento" );
 | 
						|
		estabelecimentoText = new JTextField();
 | 
						|
		JLabel localidadeLabel = new JLabel( "Localidade" );
 | 
						|
		localidadeText = new JTextField();
 | 
						|
		JLabel servicoSaudeLabel = new JLabel( "Servi\u00e7o de Sa\u00fade: Tipo" );
 | 
						|
		servicoSaudeTipoPanel = 
 | 
						|
			new RadioButtonFixedPanel( new IDObject[]{ new MappableObject( new Integer(1), "Interno" ), 
 | 
						|
													new MappableObject( new Integer(2), "Interempresas" ),
 | 
						|
													new MappableObject( new Integer(3), "Externo" ), 
 | 
						|
													new MappableObject( new Integer(4), "Servi\u00e7o Nacional de Sa\u00fade" ) }, 
 | 
						|
									1, 4, RadioButtonPanel.ORIENTATION_HORIZONTAL, false );
 | 
						|
		JLabel designacaoServicoSaudeLabel = new JLabel( "Designa\u00e7\u00e3o" );
 | 
						|
		designacaoServicoSaudeText = new JTextField();
 | 
						|
		defaultServicoSaudeButton = new JButton("-");
 | 
						|
		defaultServicoSaudeButton.addActionListener( new ActionListener(){
 | 
						|
			public void actionPerformed( ActionEvent e )
 | 
						|
			{
 | 
						|
				designacaoServicoSaudeText.setText( provider.SIPRP );
 | 
						|
			}
 | 
						|
		} );
 | 
						|
		
 | 
						|
		JLabel servicoHigieneLabel = new JLabel( "Servi\u00e7o de Higiene e Seguran\u00e7a: Tipo" );
 | 
						|
		servicoHigieneTipoPanel = 
 | 
						|
			new RadioButtonFixedPanel( new IDObject[]{ new MappableObject( new Integer(1), "Interno" ), 
 | 
						|
													new MappableObject( new Integer(2), "Interempresas" ),
 | 
						|
													new MappableObject( new Integer(3), "Externo" ), 
 | 
						|
													new MappableObject( new Integer(4), "Outro" ) }, 
 | 
						|
									1, 4, RadioButtonPanel.ORIENTATION_HORIZONTAL, false );
 | 
						|
		JLabel designacaoLabel = new JLabel( "Designa\u00e7\u00e3o" );
 | 
						|
		designacaoText = new JTextField();
 | 
						|
		defaultServicoHigieneButton = new JButton("-");
 | 
						|
		defaultServicoHigieneButton.addActionListener( new ActionListener(){
 | 
						|
			public void actionPerformed( ActionEvent e )
 | 
						|
			{
 | 
						|
				designacaoText.setText( provider.SIPRP );
 | 
						|
			}
 | 
						|
		} );
 | 
						|
		
 | 
						|
		GridBagLayout gridbag = new GridBagLayout();
 | 
						|
		setLayout( gridbag );
 | 
						|
		GridBagConstraints constraints = new GridBagConstraints();
 | 
						|
		constraints.insets = new Insets( 0, 1, 0, 1 );
 | 
						|
		constraints.fill = GridBagConstraints.HORIZONTAL;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridheight = 1;
 | 
						|
		constraints.weighty = 0;
 | 
						|
		
 | 
						|
		gridbag.setConstraints( designacaoSocialLabel, constraints );
 | 
						|
		add( designacaoSocialLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( designacaoSocialText, constraints );
 | 
						|
		add( designacaoSocialText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( estabelecimentoLabel, constraints );
 | 
						|
		add( estabelecimentoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.6;
 | 
						|
		constraints.gridwidth = 3;
 | 
						|
		gridbag.setConstraints( estabelecimentoText, constraints );
 | 
						|
		add( estabelecimentoText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( localidadeLabel, constraints );
 | 
						|
		add( localidadeLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.4;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( localidadeText, constraints );
 | 
						|
		add( localidadeText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 2;
 | 
						|
		gridbag.setConstraints( servicoSaudeLabel, constraints );
 | 
						|
		add( servicoSaudeLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( servicoSaudeTipoPanel, constraints );
 | 
						|
		add( servicoSaudeTipoPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( designacaoServicoSaudeLabel, constraints );
 | 
						|
		add( designacaoServicoSaudeLabel );
 | 
						|
		
 | 
						|
		JPanel designacaoServicoSaudePanel = new JPanel();
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( designacaoServicoSaudePanel, constraints );
 | 
						|
		add( designacaoServicoSaudePanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 3;
 | 
						|
		gridbag.setConstraints( servicoHigieneLabel, constraints );
 | 
						|
		add( servicoHigieneLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( servicoHigieneTipoPanel, constraints );
 | 
						|
		add( servicoHigieneTipoPanel );
 | 
						|
		
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.weighty = 1;
 | 
						|
		constraints.gridheight = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( designacaoLabel, constraints );
 | 
						|
		add( designacaoLabel );
 | 
						|
		
 | 
						|
		JPanel designacaoServicoHigienePanel = new JPanel();
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( designacaoServicoHigienePanel, constraints );
 | 
						|
		add( designacaoServicoHigienePanel );
 | 
						|
		
 | 
						|
		gridbag = new GridBagLayout();
 | 
						|
		designacaoServicoSaudePanel.setLayout( gridbag );
 | 
						|
		constraints.insets = new Insets( 0, 0, 0, 0 );
 | 
						|
		constraints.fill = GridBagConstraints.HORIZONTAL;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.weighty = 1;
 | 
						|
		constraints.gridheight = GridBagConstraints.REMAINDER;
 | 
						|
		
 | 
						|
		gridbag.setConstraints( designacaoServicoSaudeText, constraints );
 | 
						|
		designacaoServicoSaudePanel.add( designacaoServicoSaudeText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( defaultServicoSaudeButton, constraints );
 | 
						|
		designacaoServicoSaudePanel.add( defaultServicoSaudeButton );
 | 
						|
		
 | 
						|
		
 | 
						|
		gridbag = new GridBagLayout();
 | 
						|
		designacaoServicoHigienePanel.setLayout( gridbag );
 | 
						|
		constraints.insets = new Insets( 0, 0, 0, 0 );
 | 
						|
		constraints.fill = GridBagConstraints.HORIZONTAL;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.weighty = 1;
 | 
						|
		constraints.gridheight = GridBagConstraints.REMAINDER;
 | 
						|
		
 | 
						|
		gridbag.setConstraints( designacaoText, constraints );
 | 
						|
		designacaoServicoHigienePanel.add( designacaoText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( defaultServicoHigieneButton, constraints );
 | 
						|
		designacaoServicoHigienePanel.add( defaultServicoHigieneButton );
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void setupComponentsHashtable()
 | 
						|
	{
 | 
						|
		components = new ComponentsHashtable();
 | 
						|
		components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.DESIGNACAO_SOCIAL, designacaoSocialText );
 | 
						|
		components.put( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_SAUDE_TIPO, servicoSaudeTipoPanel );
 | 
						|
		components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_SAUDE_DESIGNACAO, designacaoServicoSaudeText );
 | 
						|
		components.put( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_HIGIENE_TIPO, servicoHigieneTipoPanel );
 | 
						|
		components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_HIGIENE_DESIGNACAO, designacaoText );
 | 
						|
		
 | 
						|
		components.putComponent( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.NOME, estabelecimentoText );
 | 
						|
		components.putComponent( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.LOCALIDADE, localidadeText );
 | 
						|
		
 | 
						|
		components.putDummy( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.INACTIVO );
 | 
						|
		components.putDummy( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.EMPRESA_ID );
 | 
						|
		components.putDummy( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.INACTIVO );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void fill(Object value)
 | 
						|
	{
 | 
						|
		clear();
 | 
						|
		empresa = null;
 | 
						|
		estabelecimento = null;
 | 
						|
		if( value != null )
 | 
						|
		{
 | 
						|
			Integer empresaID = (Integer)((Object[])value)[0];
 | 
						|
			Integer estabelecimentoID = (Integer)((Object[])value)[1];
 | 
						|
			if( empresaID != null )
 | 
						|
			{
 | 
						|
				try
 | 
						|
				{
 | 
						|
					empresa = provider.load( provider.EMPRESAS, new DBKey( empresaID ) );
 | 
						|
					DBField fields[] = provider.EMPRESAS.getInsertFields();
 | 
						|
					String empresaFields[] = new String[ fields.length ];
 | 
						|
					Hashtable data = new Hashtable();
 | 
						|
					for( int i = 0; i < empresaFields.length; ++i )
 | 
						|
					{
 | 
						|
						empresaFields[ i ] = fields[ i ].FULL_NAME;
 | 
						|
						Object fieldValue = empresa.getProperty( empresaFields[ i ] );
 | 
						|
						if( fieldValue != null )
 | 
						|
						{
 | 
						|
							data.put( empresaFields[ i ], fieldValue );
 | 
						|
						}
 | 
						|
					}
 | 
						|
					ComponentController.fill( empresaFields, data, components );
 | 
						|
					if( estabelecimentoID != null )
 | 
						|
					{
 | 
						|
						estabelecimento = provider.load( provider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) );
 | 
						|
						fields = provider.ESTABELECIMENTOS.getInsertFields();
 | 
						|
						String estabelecimentoFields[] = new String[ fields.length ];
 | 
						|
						for( int i = 0; i < estabelecimentoFields.length; ++i )
 | 
						|
						{
 | 
						|
							estabelecimentoFields[ i ] = fields[ i ].FULL_NAME;
 | 
						|
							Object fieldValue = estabelecimento.getProperty( estabelecimentoFields[ i ] );
 | 
						|
							if( fieldValue != null )
 | 
						|
							{
 | 
						|
								data.put( estabelecimentoFields[ i ], fieldValue );
 | 
						|
							}
 | 
						|
						}
 | 
						|
						ComponentController.fill( estabelecimentoFields, data, components );
 | 
						|
					}
 | 
						|
				}
 | 
						|
				catch( Exception ex )
 | 
						|
				{
 | 
						|
					DialogException.showExceptionMessage( ex, "Erro a carregar os dados da Empresa", true );
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			estabelecimentoText.setText( "Sede" );
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public Object save()
 | 
						|
	{
 | 
						|
		StringBuffer msg = new StringBuffer();
 | 
						|
		boolean hasMsg = false;
 | 
						|
		try
 | 
						|
		{
 | 
						|
			if( estabelecimento == null )
 | 
						|
			{
 | 
						|
				estabelecimento = provider.createObject( provider.ESTABELECIMENTOS );
 | 
						|
			}
 | 
						|
			if( empresa == null )
 | 
						|
			{
 | 
						|
				empresa = provider.createObject( provider.EMPRESAS );
 | 
						|
			}
 | 
						|
			DBField fields[] = provider.EMPRESAS.getInsertFields();
 | 
						|
			String empresaFields[] = new String[ fields.length ];
 | 
						|
			for( int i = 0; i < empresaFields.length; ++i )
 | 
						|
			{
 | 
						|
				empresaFields[ i ] = fields[ i ].FULL_NAME;
 | 
						|
			}
 | 
						|
			Hashtable hash = new Hashtable();
 | 
						|
			ComponentController.save( empresaFields, hash, components );
 | 
						|
			Enumeration enum = hash.keys();
 | 
						|
			while( enum.hasMoreElements() )
 | 
						|
			{
 | 
						|
				String name = ( String )enum.nextElement();
 | 
						|
				empresa.setProperty( name, hash.get( name ) );
 | 
						|
			}
 | 
						|
			fields = provider.ESTABELECIMENTOS.getInsertFields();
 | 
						|
			String estabelecimentoFields[] = new String[ fields.length ];
 | 
						|
			for( int i = 0; i < estabelecimentoFields.length; ++i )
 | 
						|
			{
 | 
						|
				estabelecimentoFields[ i ] = fields[ i ].FULL_NAME;
 | 
						|
			}
 | 
						|
			hash = new Hashtable();
 | 
						|
			ComponentController.save( estabelecimentoFields, hash, components );
 | 
						|
			enum = hash.keys();
 | 
						|
			while( enum.hasMoreElements() )
 | 
						|
			{
 | 
						|
				String name = ( String )enum.nextElement();
 | 
						|
				estabelecimento.setProperty( name, hash.get( name ) );
 | 
						|
			}
 | 
						|
			estabelecimento.setProperty( provider.R_ESTABELECIMENTO_EMPRESA, empresa );
 | 
						|
			
 | 
						|
			if( ((String)empresa.getProperty( provider.DESIGNACAO_SOCIAL )).trim().length() == 0 )
 | 
						|
			{
 | 
						|
				msg.append( "A empresa tem de ter uma design\u00e7\u00e3o social\n" );
 | 
						|
				hasMsg = true;
 | 
						|
			}
 | 
						|
			if( empresa.getProperty( provider.SERVICO_SAUDE_TIPO ) == null )
 | 
						|
			{
 | 
						|
				msg.append( "A empresa tem de ter um tipo de seri\00e7o de sa\u00fade\n" );
 | 
						|
				hasMsg = true;
 | 
						|
			}
 | 
						|
			if( empresa.getProperty( provider.SERVICO_HIGIENE_TIPO ) == null )
 | 
						|
			{
 | 
						|
				msg.append( "A empresa tem de ter um tipo de seri\00e7o de higiene\n" );
 | 
						|
				hasMsg = true;
 | 
						|
			}
 | 
						|
			if( ((String)estabelecimento.getProperty( provider.NOME )).trim().length() == 0 )
 | 
						|
			{
 | 
						|
				msg.append( "O estabelecimento tem de ter nome\n" );
 | 
						|
				hasMsg = true;
 | 
						|
			}
 | 
						|
			
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			ex.printStackTrace();
 | 
						|
			return null;
 | 
						|
		}
 | 
						|
		if( hasMsg )
 | 
						|
		{
 | 
						|
			throw new ValuesException( msg.toString() );
 | 
						|
		}
 | 
						|
		return estabelecimento;
 | 
						|
		
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void clear()
 | 
						|
	{
 | 
						|
		String names[] = (String[])components.keySet().toArray( new String[0] );
 | 
						|
		ComponentController.clear( names, components );
 | 
						|
		estabelecimentoText.setText( "Sede" );
 | 
						|
		empresa = null;
 | 
						|
		estabelecimento = null;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void setEnabled( boolean enable )
 | 
						|
	{
 | 
						|
		String names[] = (String[])components.keySet().toArray( new String[0] );
 | 
						|
		ComponentController.setEnabled( names, enable, components );
 | 
						|
	}
 | 
						|
}
 |