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.
467 lines
15 KiB
467 lines
15 KiB
/*
|
|
* TrabalhadorPanel.java
|
|
*
|
|
* Created on 29 de Março de 2004, 11:55
|
|
*/
|
|
|
|
package siprp.ficha;
|
|
|
|
import java.awt.*;
|
|
import javax.swing.*;
|
|
import java.util.*;
|
|
|
|
import com.evolute.utils.*;
|
|
import com.evolute.utils.data.*;
|
|
import com.evolute.utils.dataui.*;
|
|
import com.evolute.utils.date.*;
|
|
import com.evolute.utils.jdo.*;
|
|
import com.evolute.utils.metadb.*;
|
|
import com.evolute.utils.ui.*;
|
|
import com.evolute.utils.ui.panel.*;
|
|
|
|
import siprp.*;
|
|
import siprp.data.*;
|
|
import siprp.importer.*;
|
|
/**
|
|
*
|
|
* @author fpalma
|
|
*/
|
|
public class TrabalhadorPanel extends JPanel
|
|
implements ControllableComponent
|
|
{
|
|
private JDOProvider JDO;
|
|
private JTextField nomeText;
|
|
private RadioButtonFixedPanel sexoPanel;
|
|
private JCalendarPanel dataNascimentoPanel;
|
|
private JTextField nacionalidadeText;
|
|
private JTextField numeroMecanograficoText;
|
|
private JCalendarPanel dataAdmissaoPanel;
|
|
private JTextField categoriaText;
|
|
private JTextField localText;
|
|
private JTextField funcaoText;
|
|
private JCalendarPanel dataAdmissaoFuncaoPanel;
|
|
|
|
private ComponentsHashtable components;
|
|
private FichaDataProvider provider;
|
|
private TrabalhadorData trabalhador;
|
|
|
|
/** Creates a new instance of TrabalhadorPanel */
|
|
|
|
public TrabalhadorPanel()
|
|
throws Exception
|
|
{
|
|
provider = (FichaDataProvider)FichaDataProvider.getProvider();
|
|
JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER );
|
|
setupComponents();
|
|
setupComponentsHashtable();
|
|
}
|
|
|
|
|
|
private void setupComponents()
|
|
{
|
|
setBorder( BorderFactory.createTitledBorder(
|
|
BorderFactory.createEtchedBorder(),
|
|
"Trabalhador" ) );
|
|
JLabel nomeLabel = new JLabel( "Nome" );
|
|
nomeText = new JTextField();
|
|
JLabel sexoLabel = new JLabel( "Sexo" );
|
|
sexoPanel =
|
|
new RadioButtonFixedPanel(
|
|
new IDObject[]{ new MappableObject( new Integer( 1 ), "M" ),
|
|
new MappableObject( new Integer( 2 ), "F" ) },
|
|
1, 2, RadioButtonPanel.ORIENTATION_HORIZONTAL, false );
|
|
JLabel dataNascimentoLabel = new JLabel( "Data de Nascimento" );
|
|
dataNascimentoPanel = new JCalendarPanel( null );
|
|
JLabel nacionalidadeLabel = new JLabel( "Nacionalidade" );
|
|
nacionalidadeText = new JTextField();
|
|
JLabel numeroMecanograficoLabel = new JLabel( "N\u00famero Mecanogr\u00e1fico/outro" );
|
|
numeroMecanograficoText = new JTextField();
|
|
JLabel dataAdmissaoLabel = new JLabel( "Data de Admiss\u00e3o" );
|
|
dataAdmissaoPanel = new JCalendarPanel( null );
|
|
JLabel categoriaLabel = new JLabel( "Categoria Profissional" );
|
|
categoriaText = new JTextField();
|
|
JLabel localLabel = new JLabel( "Local de Trabalho" );
|
|
localText = new JTextField();
|
|
JLabel funcaoLabel = new JLabel( "Fun\u00e7\u00e3o proposta" );
|
|
funcaoText = new JTextField();
|
|
JLabel dataAdmissaoFuncaoLabel = new JLabel( "Data de Admiss\u00e3o na Fun\u00e7\u00e3o" );
|
|
dataAdmissaoFuncaoPanel = new JCalendarPanel( null );
|
|
|
|
GridBagLayout gridbag = new GridBagLayout();
|
|
setLayout( gridbag );
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
constraints.insets = new Insets( 0, 1, 0, 1 );
|
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
constraints.weighty = 0;
|
|
constraints.gridheight = 1;
|
|
constraints.gridwidth = 1;
|
|
constraints.weightx = 0;
|
|
|
|
gridbag.setConstraints( nomeLabel, constraints );
|
|
add( nomeLabel );
|
|
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = 3;
|
|
gridbag.setConstraints( nomeText, constraints );
|
|
add( nomeText );
|
|
|
|
constraints.gridwidth = 1;
|
|
constraints.weightx = 0;
|
|
gridbag.setConstraints( sexoLabel, constraints );
|
|
add( sexoLabel );
|
|
|
|
constraints.weightx = 0;
|
|
//constraints.gridwidth = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( sexoPanel, constraints );
|
|
add( sexoPanel );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 2;
|
|
gridbag.setConstraints( nacionalidadeLabel, constraints );
|
|
add( nacionalidadeLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( nacionalidadeText, constraints );
|
|
add( nacionalidadeText );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( dataNascimentoLabel, constraints );
|
|
add( dataNascimentoLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( dataNascimentoPanel, constraints );
|
|
add( dataNascimentoPanel );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 2;
|
|
gridbag.setConstraints( numeroMecanograficoLabel, constraints );
|
|
add( numeroMecanograficoLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( numeroMecanograficoText, constraints );
|
|
add( numeroMecanograficoText );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( dataAdmissaoLabel, constraints );
|
|
add( dataAdmissaoLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( dataAdmissaoPanel, constraints );
|
|
add( dataAdmissaoPanel );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 2;
|
|
gridbag.setConstraints( categoriaLabel, constraints );
|
|
add( categoriaLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( categoriaText, constraints );
|
|
add( categoriaText );
|
|
|
|
constraints.weightx = 0;
|
|
gridbag.setConstraints( localLabel, constraints );
|
|
add( localLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( localText, constraints );
|
|
add( localText );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 2;
|
|
gridbag.setConstraints( funcaoLabel, constraints );
|
|
add( funcaoLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( funcaoText, constraints );
|
|
add( funcaoText );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( dataAdmissaoFuncaoLabel, constraints );
|
|
add( dataAdmissaoFuncaoLabel );
|
|
|
|
constraints.weightx = 0.5;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( dataAdmissaoFuncaoPanel, constraints );
|
|
add( dataAdmissaoFuncaoPanel );
|
|
}
|
|
|
|
private void setupComponentsHashtable()
|
|
{
|
|
components = new ComponentsHashtable();
|
|
components.putComponent( TrabalhadorData.NOME, nomeText );
|
|
components.putComponent( TrabalhadorData.SEXO, new ControllableComponent()
|
|
{
|
|
public void fill( Object value )
|
|
{
|
|
if( value != null && value.equals( "f" ) )
|
|
{
|
|
sexoPanel.fill( new Integer(2) );
|
|
}
|
|
else
|
|
{
|
|
sexoPanel.fill( new Integer(1) );
|
|
}
|
|
}
|
|
|
|
public Object save()
|
|
{
|
|
Integer id = (Integer)sexoPanel.save();
|
|
if( id != null && id.intValue() == 1 )
|
|
{
|
|
return "m";
|
|
}
|
|
return "f";
|
|
}
|
|
|
|
public void clear()
|
|
{
|
|
sexoPanel.clear();
|
|
}
|
|
|
|
public void setEnabled( boolean enable )
|
|
{
|
|
sexoPanel.setEnabled( enable );
|
|
}
|
|
} );
|
|
components.putComponent( TrabalhadorData.DATA_NASCIMENTO, dataNascimentoPanel );
|
|
components.putComponent( TrabalhadorData.NACIONALIDADE, nacionalidadeText );
|
|
components.putComponent( TrabalhadorData.NUMERO_MECANOGRAFICO, numeroMecanograficoText );
|
|
components.putComponent( TrabalhadorData.DATA_ADMISSAO, dataAdmissaoPanel );
|
|
components.putComponent( TrabalhadorData.CATEGORIA, categoriaText );
|
|
components.putComponent( TrabalhadorData.LOCAL_TRABALHO, localText );
|
|
components.putComponent( TrabalhadorData.FUNCAO_PROPOSTA, funcaoText );
|
|
components.putComponent( TrabalhadorData.DATA_ADMISSAO_FUNCAO, dataAdmissaoFuncaoPanel );
|
|
components.putDummy( TrabalhadorData.DATA_DEMISSAO );
|
|
components.putDummy( TrabalhadorData.OBSERVACOES );
|
|
components.putDummy( TrabalhadorData.OBSERVACOES_GESTAO );
|
|
components.putDummy( TrabalhadorData.PERFIL );
|
|
components.putDummy( TrabalhadorData.ESTABELECIMENTO );
|
|
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NOME, nomeText );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_NASCIMENTO, dataNascimentoPanel );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NACIONALIDADE, nacionalidadeText );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NUMERO_MECANOGRAFICO, numeroMecanograficoText );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_ADMISSAO, dataAdmissaoPanel );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.CATEGORIA, categoriaText );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.LOCAL_TRABALHO, localText );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.FUNCAO_PROPOSTA, funcaoText );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_ADMISSAO_FUNCAO, dataAdmissaoFuncaoPanel );
|
|
// components.putDummy( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.ESTABELECIMENTO_ID );
|
|
// components.putDummy( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.OBSERVACOES );
|
|
// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.SEXO,
|
|
// new ControllableComponent()
|
|
// {
|
|
// public void fill( Object value )
|
|
// {
|
|
// if( value != null && value.equals( "f" ) )
|
|
// {
|
|
// sexoPanel.fill( new Integer(2) );
|
|
// }
|
|
// else
|
|
// {
|
|
// sexoPanel.fill( new Integer(1) );
|
|
// }
|
|
// }
|
|
//
|
|
// public Object save()
|
|
// {
|
|
// Integer id = (Integer)sexoPanel.save();
|
|
// if( id != null && id.intValue() == 1 )
|
|
// {
|
|
// return "m";
|
|
// }
|
|
// return "f";
|
|
// }
|
|
//
|
|
// public void clear()
|
|
// {
|
|
// sexoPanel.clear();
|
|
// }
|
|
//
|
|
// public void setEnabled( boolean enable )
|
|
// {
|
|
// sexoPanel.setEnabled( enable );
|
|
// }
|
|
// } );
|
|
}
|
|
|
|
public void fill(Object value)
|
|
{
|
|
clear();
|
|
trabalhador = null;
|
|
if( value != null )
|
|
{
|
|
Integer trabalhadorID = (Integer)value;
|
|
if( trabalhadorID != null )
|
|
{
|
|
try
|
|
{
|
|
trabalhador = ( TrabalhadorData ) JDO.load( TrabalhadorData.class, trabalhadorID );
|
|
String names[] = trabalhador.getFieldNames();
|
|
ComponentController.fill( names, trabalhador.getHashData(), components );
|
|
// trabalhador = provider.load( FichaDataProvider.TRABALHADORES, new DBKey( trabalhadorID ) );
|
|
// DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields();
|
|
// String trabalhadorFields[] = new String[ fields.length ];
|
|
// Hashtable data = new Hashtable();
|
|
// for( int i = 0; i < trabalhadorFields.length; ++i )
|
|
// {
|
|
// trabalhadorFields[ i ] = fields[ i ].FULL_NAME;
|
|
// Object fieldValue = trabalhador.getProperty( trabalhadorFields[ i ] );
|
|
// if( fieldValue != null )
|
|
// {
|
|
// data.put( trabalhadorFields[ i ], fieldValue );
|
|
// }
|
|
// }
|
|
// ComponentController.fill( trabalhadorFields, data, components );
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
DialogException.showExceptionMessage( ex, "Erro a carregar os dados do trabalhador", true );
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public Object save()
|
|
{
|
|
StringBuffer msg = new StringBuffer();
|
|
boolean hasMsg = false;
|
|
try
|
|
{
|
|
if( trabalhador == null )
|
|
{
|
|
// trabalhador = provider.createObject( FichaDataProvider.TRABALHADORES );
|
|
trabalhador = new TrabalhadorData();
|
|
}
|
|
// DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields();
|
|
// String trabalhadorFields[] = new String[ fields.length ];
|
|
// for( int i = 0; i < trabalhadorFields.length; ++i )
|
|
// {
|
|
// trabalhadorFields[ i ] = fields[ i ].FULL_NAME;
|
|
// }
|
|
// Hashtable hash = new Hashtable();
|
|
// ComponentController.save( trabalhadorFields, hash, components );
|
|
// Enumeration enum = hash.keys();
|
|
// while( enum.hasMoreElements() )
|
|
// {
|
|
// String name = ( String )enum.nextElement();
|
|
// trabalhador.setProperty( name, hash.get( name ) );
|
|
// }
|
|
String names[] = trabalhador.getFieldNames();
|
|
Hashtable hash = trabalhador.getHashData();
|
|
ComponentController.save( names, hash, components );
|
|
trabalhador.setHashData( hash );
|
|
// if( ((String)trabalhador.getProperty( FichaDataProvider.NOME )).trim().length() == 0 )
|
|
if( ((String)trabalhador.get( TrabalhadorData.NOME )).trim().length() == 0 )
|
|
{
|
|
msg.append( "O trabalhador tem de ter nome\n" );
|
|
hasMsg = true;
|
|
}
|
|
// if( trabalhador.getProperty( FichaDataProvider.SEXO ) == null )
|
|
if( trabalhador.get( TrabalhadorData.SEXO ) == null )
|
|
{
|
|
msg.append( "O trabalhador tem de ter um sexo definido\n" );
|
|
hasMsg = true;
|
|
}
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
ex.printStackTrace();
|
|
return null;
|
|
}
|
|
if( hasMsg )
|
|
{
|
|
throw new ValuesException( msg.toString() );
|
|
}
|
|
return trabalhador;
|
|
}
|
|
|
|
public void clear()
|
|
{
|
|
String names[] = (String[])components.keySet().toArray( new String[0] );
|
|
ComponentController.clear( names, components );
|
|
trabalhador = null;
|
|
}
|
|
|
|
public void setEnabled( boolean enable )
|
|
{
|
|
String names[] = (String[])components.keySet().toArray( new String[0] );
|
|
ComponentController.setEnabled( names, enable, components );
|
|
}
|
|
|
|
public void setData( Hashtable data )
|
|
{
|
|
String nome = (String)data.get( Importer.NOME );
|
|
if( nome != null && nome.trim().length() > 0 )
|
|
{
|
|
nomeText.setText( nome );
|
|
}
|
|
String sexo = (String)data.get( Importer.SEXO );
|
|
if( sexo != null && sexo.trim().length() > 0 )
|
|
{
|
|
Integer sexoInt;
|
|
if( sexo.trim().toLowerCase().charAt(0) == 'f' )
|
|
{
|
|
sexoInt = new Integer( 2 );
|
|
}
|
|
else
|
|
{
|
|
sexoInt = new Integer( 1 );
|
|
}
|
|
sexoPanel.fill( sexoInt );
|
|
}
|
|
String nacionalidade = (String)data.get( Importer.NACIONALIDADE );
|
|
if( nacionalidade != null && nacionalidade.trim().length() > 0 )
|
|
{
|
|
nacionalidadeText.setText( nacionalidade );
|
|
}
|
|
String dataNascimento = (String)data.get( Importer.DATA_NASCIMENTO );
|
|
if( dataNascimento != null )
|
|
{
|
|
dataNascimentoPanel.setDate( DateUtils.guessDate( dataNascimento ) );
|
|
}
|
|
String numeroMecanografico = (String)data.get( Importer.NUMERO_MECANOGRAFICO );
|
|
if( numeroMecanografico != null && numeroMecanografico.trim().length() > 0 )
|
|
{
|
|
numeroMecanograficoText.setText( numeroMecanografico );
|
|
}
|
|
String dataAdmissao = (String)data.get( Importer.DATA_ADMISSAO );
|
|
if( dataAdmissao != null )
|
|
{
|
|
dataAdmissaoPanel.setDate( DateUtils.guessDate( dataAdmissao ) );
|
|
}
|
|
String categoria = (String)data.get( Importer.CATEGORIA );
|
|
if( categoria != null && categoria.trim().length() > 0 )
|
|
{
|
|
categoriaText.setText( categoria );
|
|
}
|
|
String localTrabalho = (String)data.get( Importer.LOCAL_TRABALHO );
|
|
if( localTrabalho != null && localTrabalho.trim().length() > 0 )
|
|
{
|
|
localText.setText( localTrabalho );
|
|
}
|
|
String funcao = (String)data.get( Importer.FUNCAO );
|
|
if( funcao != null && funcao.trim().length() > 0 )
|
|
{
|
|
funcaoText.setText( funcao );
|
|
}
|
|
String dataAdmissaoFuncao = (String)data.get( Importer.DATA_ADMISSAO_FUNCAO );
|
|
if( dataAdmissaoFuncao != null )
|
|
{
|
|
dataAdmissaoFuncaoPanel.setDate( DateUtils.guessDate( dataAdmissaoFuncao ) );
|
|
}
|
|
}
|
|
}
|