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.
		
		
		
		
		
			
		
			
				
					
					
						
							613 lines
						
					
					
						
							20 KiB
						
					
					
				
			
		
		
	
	
							613 lines
						
					
					
						
							20 KiB
						
					
					
				/*
 | 
						|
 * TrabalhadorPanel.java
 | 
						|
 *
 | 
						|
 * Created on 14 de Maio de 2004, 12:29
 | 
						|
 */
 | 
						|
 | 
						|
package siprp.clientes;
 | 
						|
 | 
						|
import javax.swing.*;
 | 
						|
 | 
						|
import java.awt.*;
 | 
						|
import java.awt.event.*;
 | 
						|
import javax.swing.*;
 | 
						|
import javax.swing.event.*;
 | 
						|
import java.util.*;
 | 
						|
 | 
						|
import com.evolute.utils.data.*;
 | 
						|
import com.evolute.utils.dataui.*;
 | 
						|
import com.evolute.utils.date.*;
 | 
						|
import com.evolute.utils.metadb.*;
 | 
						|
import com.evolute.utils.tables.*;
 | 
						|
import com.evolute.utils.ui.*;
 | 
						|
import com.evolute.utils.ui.calendar.*;
 | 
						|
import com.evolute.utils.ui.panel.*;
 | 
						|
import com.evolute.utils.ui.text.*;
 | 
						|
 | 
						|
import siprp.*;
 | 
						|
import siprp.data.*;
 | 
						|
import siprp.importer.*;
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @author  fpalma
 | 
						|
 */
 | 
						|
public class TrabalhadorPanel extends JPanel
 | 
						|
	implements ControllableComponent, ListSelectionListener, ActionListener
 | 
						|
{
 | 
						|
	private FichaDataProvider provider;
 | 
						|
	private TrabalhadorData trabalhador;
 | 
						|
	private ComponentsHashtable components;
 | 
						|
	
 | 
						|
	private EstabelecimentoData estabelecimento;
 | 
						|
	private JTable estabelecimentosTable;
 | 
						|
	
 | 
						|
	private JPanel toolbarPanel;
 | 
						|
	
 | 
						|
	private JPanel dadosTrabalhadorPanel;
 | 
						|
	
 | 
						|
	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 JCalendarPanel dataDemissaoPanel;
 | 
						|
	private JTextField observacoesText;
 | 
						|
	//private JComboBox perfilCombo;
 | 
						|
	private RadioButtonFixedPanel perfilPanel;
 | 
						|
 | 
						|
	private SIPRPTracker tracker;
 | 
						|
	
 | 
						|
	private BaseTable trabalhadoresTable;
 | 
						|
	private VectorTableModel trabalhadoresModel;
 | 
						|
 | 
						|
	private JButton marcacoesButton;
 | 
						|
//	private MarcacaoPanel examesPanel;
 | 
						|
//	private MarcacaoPanel consultaPanel;
 | 
						|
	
 | 
						|
	private Vector listeners;
 | 
						|
	
 | 
						|
	private boolean lastEnable = false;
 | 
						|
	
 | 
						|
	/** Creates a new instance of TrabalhadorPanel */
 | 
						|
	public TrabalhadorPanel( JPanel toolbarPanel, JTable estabelecimentosTable )
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		this.toolbarPanel = toolbarPanel;
 | 
						|
		this.estabelecimentosTable = estabelecimentosTable;
 | 
						|
		provider = ( FichaDataProvider )FichaDataProvider.getProvider();
 | 
						|
		listeners = new Vector();
 | 
						|
		setupComponents();
 | 
						|
		setupComponentsHashtable();
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void setupComponents()
 | 
						|
	{
 | 
						|
		dadosTrabalhadorPanel = new JPanel();
 | 
						|
//		JPanel marcacoesPanel = new JPanel();
 | 
						|
		
 | 
						|
		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 );
 | 
						|
		JLabel perfilLabel = new JLabel( "Perfil" );
 | 
						|
//		perfilCombo = new JComboBox();
 | 
						|
//		perfilCombo.addItem( new MappableObject( new Integer( 1 ), "A" ) );
 | 
						|
//		perfilCombo.addItem( new MappableObject( new Integer( 2 ), "B" ) );
 | 
						|
		perfilPanel = new RadioButtonFixedPanel( 
 | 
						|
				new IDObject[]{ new MappableObject( new Integer( 1 ), "A" ),
 | 
						|
								new MappableObject( new Integer( 2 ), "B" ) },
 | 
						|
					1, 2, RadioButtonPanel.ORIENTATION_HORIZONTAL, false );
 | 
						|
		JLabel dataDemissaoLabel = new JLabel( "Data de Demiss\u00e3o" );
 | 
						|
		dataDemissaoPanel = new JCalendarPanel( null );
 | 
						|
		JLabel observacoesLabel = new JLabel( "Observa\u00e7\u00f5es" );
 | 
						|
		observacoesText = new JTextField();
 | 
						|
		marcacoesButton = new JButton( "Marca\u00e7\u00f5es" );
 | 
						|
		marcacoesButton.addActionListener( this );
 | 
						|
		
 | 
						|
		JScrollPane trabalhadoresScroll = new JScrollPane();
 | 
						|
		trabalhadoresScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
 | 
						|
		trabalhadoresScroll.setPreferredSize( new Dimension( 250, 300 ) );
 | 
						|
		trabalhadoresModel = new VectorTableModel( new String[]{ "Trabalhadores" } );
 | 
						|
		trabalhadoresTable = new BaseTable( trabalhadoresModel );
 | 
						|
		trabalhadoresTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
 | 
						|
		trabalhadoresTable.setNonResizableNorReordable();
 | 
						|
		trabalhadoresScroll.setViewportView( trabalhadoresTable );
 | 
						|
		
 | 
						|
		JPanel pad;
 | 
						|
		
 | 
						|
		GridBagLayout gridbag = new GridBagLayout();
 | 
						|
		dadosTrabalhadorPanel.setLayout( gridbag );
 | 
						|
		GridBagConstraints constraints = new GridBagConstraints();
 | 
						|
		constraints.insets = new Insets( 1, 1, 1, 1 );
 | 
						|
		constraints.fill = GridBagConstraints.HORIZONTAL;
 | 
						|
		constraints.weighty = 0;
 | 
						|
		constraints.gridheight = 1;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		constraints.weightx = 0;
 | 
						|
		
 | 
						|
		gridbag.setConstraints( nomeLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( nomeLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = 3;
 | 
						|
		gridbag.setConstraints( nomeText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( nomeText );
 | 
						|
		
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		constraints.weightx = 0;
 | 
						|
		gridbag.setConstraints( sexoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( sexoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		//constraints.gridwidth = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		JPanel sexoOuterPanel = new JPanel();
 | 
						|
		sexoOuterPanel.setLayout( new GridLayout( 1, 2 ) );
 | 
						|
		sexoOuterPanel.add( sexoPanel );
 | 
						|
		sexoOuterPanel.add( new JPanel() );
 | 
						|
		gridbag.setConstraints( sexoOuterPanel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( sexoOuterPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 2;
 | 
						|
		gridbag.setConstraints( nacionalidadeLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( nacionalidadeLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( nacionalidadeText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( nacionalidadeText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( dataNascimentoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataNascimentoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( dataNascimentoPanel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataNascimentoPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 2;
 | 
						|
		gridbag.setConstraints( numeroMecanograficoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( numeroMecanograficoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( numeroMecanograficoText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( numeroMecanograficoText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( dataAdmissaoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataAdmissaoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( dataAdmissaoPanel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataAdmissaoPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 2;
 | 
						|
		gridbag.setConstraints( categoriaLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( categoriaLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( categoriaText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( categoriaText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		gridbag.setConstraints( localLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( localLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( localText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( localText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 2;
 | 
						|
		gridbag.setConstraints( funcaoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( funcaoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( funcaoText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( funcaoText );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( dataAdmissaoFuncaoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataAdmissaoFuncaoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( dataAdmissaoFuncaoPanel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataAdmissaoFuncaoPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 2;
 | 
						|
		gridbag.setConstraints( perfilLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( perfilLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
//		gridbag.setConstraints( perfilCombo, constraints );
 | 
						|
//		dadosTrabalhadorPanel.add( perfilCombo );
 | 
						|
		gridbag.setConstraints( perfilPanel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( perfilPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( dataDemissaoLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataDemissaoLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0.5;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( dataDemissaoPanel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( dataDemissaoPanel );
 | 
						|
		
 | 
						|
		constraints.weightx = 0;
 | 
						|
		constraints.gridwidth = 1;
 | 
						|
		gridbag.setConstraints( observacoesLabel, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( observacoesLabel );
 | 
						|
		
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( observacoesText, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( observacoesText );
 | 
						|
		
 | 
						|
		constraints.weightx = 1;
 | 
						|
		constraints.gridwidth = GridBagConstraints.REMAINDER;
 | 
						|
		gridbag.setConstraints( marcacoesButton, constraints );
 | 
						|
		dadosTrabalhadorPanel.add( marcacoesButton );
 | 
						|
		
 | 
						|
//		examesPanel = new MarcacaoPanel( false, "Realizados", "", Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES );
 | 
						|
//		examesPanel.setCalendarDialogOrientation( JCalendarDialog.ABOVE, JCalendarDialog.RIGHT );
 | 
						|
//		examesPanel.setBorder( BorderFactory.createTitledBorder( 
 | 
						|
//									BorderFactory.createEtchedBorder(),
 | 
						|
//									"Exames" ) );
 | 
						|
//		consultaPanel = new MarcacaoPanel( true, "Realizada", "Ficha de Aptid\u00e3o", Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA );
 | 
						|
//		consultaPanel.setCalendarDialogOrientation( JCalendarDialog.ABOVE, JCalendarDialog.LEFT );
 | 
						|
//		consultaPanel.setBorder( BorderFactory.createTitledBorder( 
 | 
						|
//									BorderFactory.createEtchedBorder(),
 | 
						|
//									"Consulta" ) );
 | 
						|
//		//marcacoesPanel.setLayout( new BoxLayout( marcacoesPanel, BoxLayout.X_AXIS ) );
 | 
						|
//		marcacoesPanel.setLayout( new GridLayout( 1, 2 ) );
 | 
						|
//		marcacoesPanel.add( examesPanel );
 | 
						|
//		marcacoesPanel.add( consultaPanel );
 | 
						|
		
 | 
						|
		JPanel leftPanel = new JPanel();
 | 
						|
		leftPanel.setLayout( new BorderLayout() );
 | 
						|
		leftPanel.add( toolbarPanel, BorderLayout.NORTH );
 | 
						|
		leftPanel.add( trabalhadoresScroll, BorderLayout.CENTER );
 | 
						|
		
 | 
						|
		setLayout( new BorderLayout() );
 | 
						|
		add( leftPanel, BorderLayout.WEST );
 | 
						|
		add( dadosTrabalhadorPanel, BorderLayout.CENTER );
 | 
						|
//		add( marcacoesPanel, BorderLayout.SOUTH );
 | 
						|
		
 | 
						|
		trabalhadoresTable.getSelectionModel().addListSelectionListener( this );
 | 
						|
		
 | 
						|
		new CopyPasteHandler( nomeText );
 | 
						|
		new CopyPasteHandler( nacionalidadeText );
 | 
						|
		new CopyPasteHandler( numeroMecanograficoText );
 | 
						|
		new CopyPasteHandler( categoriaText );
 | 
						|
		new CopyPasteHandler( localText );
 | 
						|
		new CopyPasteHandler( funcaoText );
 | 
						|
		new CopyPasteHandler( observacoesText );
 | 
						|
	}
 | 
						|
	
 | 
						|
	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.putComponent( TrabalhadorData.DATA_DEMISSAO, dataDemissaoPanel );
 | 
						|
		components.putDummy( TrabalhadorData.OBSERVACOES );
 | 
						|
		components.putComponent( TrabalhadorData.OBSERVACOES_GESTAO, observacoesText );
 | 
						|
		components.putComponent( TrabalhadorData.PERFIL, perfilPanel );
 | 
						|
//		components.putDummy( TrabalhadorData.INACTIVO );
 | 
						|
		components.putDummy( TrabalhadorData.ESTABELECIMENTO );
 | 
						|
		components.putDummy( TrabalhadorData.NOME_PLAIN );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void clear()
 | 
						|
	{
 | 
						|
		String names[] = (String[])components.keySet().toArray( new String[0] );
 | 
						|
		ComponentController.clear( names, components );
 | 
						|
		trabalhador = null;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void fill(Object value)
 | 
						|
	{
 | 
						|
		clear();
 | 
						|
		trabalhador = ( TrabalhadorData ) value;
 | 
						|
//		examesPanel.setEnabled( trabalhador != null );
 | 
						|
//		examesPanel.fill( trabalhador );
 | 
						|
//		consultaPanel.setEnabled( trabalhador != null );
 | 
						|
//		consultaPanel.fill( trabalhador );
 | 
						|
		if( trabalhador == null )
 | 
						|
		{
 | 
						|
			trabalhadoresTable.clearSelection();
 | 
						|
			return;
 | 
						|
		}
 | 
						|
		String names[] = trabalhador.getFieldNames();
 | 
						|
		ComponentController.fill( names, trabalhador.getHashData(), components );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public Object save()
 | 
						|
	{
 | 
						|
		
 | 
						|
		if( trabalhador == null )
 | 
						|
		{
 | 
						|
			trabalhador = new TrabalhadorData();
 | 
						|
		}
 | 
						|
			
 | 
						|
		String names[] = trabalhador.getFieldNames();
 | 
						|
		Hashtable hash = new Hashtable();
 | 
						|
		ComponentController.save( names, hash, components );
 | 
						|
		trabalhador.setHashData( hash );
 | 
						|
		trabalhador.set( TrabalhadorData.ESTABELECIMENTO, estabelecimento );
 | 
						|
		return trabalhador;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void setEnabled( boolean enable )
 | 
						|
	{
 | 
						|
		super.setEnabled( enable );
 | 
						|
		String names[] = (String[])components.keySet().toArray( new String[0] );
 | 
						|
		ComponentController.setEnabled( names, enable, components );
 | 
						|
		trabalhadoresTable.setEnabled( !enable );
 | 
						|
		if( lastEnable != enable )
 | 
						|
		{
 | 
						|
			if( enable )
 | 
						|
			{
 | 
						|
				EstabelecimentoPanel.disables++;
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				EstabelecimentoPanel.disables--; 
 | 
						|
			}
 | 
						|
			lastEnable = enable;
 | 
						|
		}
 | 
						|
		estabelecimentosTable.setEnabled( EstabelecimentoPanel.disables == 0 );
 | 
						|
//		if( trabalhador == null )
 | 
						|
//		{
 | 
						|
//			examesPanel.setEnabled( false );
 | 
						|
//			consultaPanel.setEnabled( false );
 | 
						|
//		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void reloaList()
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		if( estabelecimento == null )
 | 
						|
		{
 | 
						|
			trabalhadoresModel.clearAll();
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			Integer id = ( Integer )estabelecimento.get( EstabelecimentoData.ID );
 | 
						|
			IDObject []trabalhadores = provider.getAllTrabalhadoresForEstabelecimento( id );
 | 
						|
			trabalhadoresModel.setValues( new Vector( Arrays.asList( trabalhadores ) ) );
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void valueChanged( ListSelectionEvent e )
 | 
						|
	{
 | 
						|
		Object source = e.getSource();
 | 
						|
		if( source instanceof EmpresaPanel )
 | 
						|
		{
 | 
						|
			Integer id = ( ( EmpresaPanel ) source ).getSelectedEstabelecimento();
 | 
						|
			if( id != null )
 | 
						|
			{
 | 
						|
				try
 | 
						|
				{
 | 
						|
					IDObject []trabalhadores = provider.getAllTrabalhadoresForEstabelecimento( id );
 | 
						|
					trabalhadoresModel.setValues( new Vector( Arrays.asList( trabalhadores ) ) );
 | 
						|
				}
 | 
						|
				catch( Exception ex )
 | 
						|
				{
 | 
						|
					DialogException.showExceptionMessage( ex, "Erro a carregar os trabalhadores", true );
 | 
						|
					clear();
 | 
						|
				}
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				trabalhadoresModel.clearAll();
 | 
						|
				clear();
 | 
						|
			}
 | 
						|
		}
 | 
						|
		else if( source.equals( trabalhadoresTable.getSelectionModel() ) )
 | 
						|
		{
 | 
						|
//			int selected = trabalhadoresTable.getSelectedRow();
 | 
						|
//			if( selected == -1 )
 | 
						|
//			{
 | 
						|
//				clear();
 | 
						|
//				
 | 
						|
//			}
 | 
						|
//			else
 | 
						|
//			{
 | 
						|
//				Integer id = ( ( IDObject ) trabalhadoresModel.getRowAt( selected ) ).getID();;
 | 
						|
//				try
 | 
						|
//				{
 | 
						|
//					TrabalhadorData trabalhador = (TrabalhadorData) TrabalhadorData.load( TrabalhadorData.class, id );
 | 
						|
//					fill( trabalhador );
 | 
						|
//				}
 | 
						|
//				catch( Exception ex )
 | 
						|
//				{
 | 
						|
//					DialogException.showExceptionMessage( ex, "Erro a carregar o trabalhador", true );
 | 
						|
//					clear();
 | 
						|
//				}
 | 
						|
				for( int n = 0; n < listeners.size(); n++ )
 | 
						|
				{
 | 
						|
					ListSelectionEvent newEvent = 
 | 
						|
						new ListSelectionEvent( this, e.getFirstIndex(), e.getLastIndex(), e.getValueIsAdjusting() );
 | 
						|
					( (ListSelectionListener) listeners.elementAt( n ) ).valueChanged( newEvent );
 | 
						|
				}
 | 
						|
//			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void postSave()
 | 
						|
	{
 | 
						|
		int selected = trabalhadoresTable.getSelectedRow();
 | 
						|
//System.out.println( "postSave TRABALHADOR PANEL " + selected + " : " + ( trabalhador == null ) );
 | 
						|
		if( trabalhador != null )
 | 
						|
		{
 | 
						|
			IDObject obj = new MappableObject( (Integer) trabalhador.get( TrabalhadorData.ID ), trabalhador.get( TrabalhadorData.NOME ) );
 | 
						|
			if( selected == -1 )
 | 
						|
			{
 | 
						|
				trabalhadoresModel.insertRowAt( obj, trabalhadoresTable.getRowCount() );
 | 
						|
				trabalhadoresTable.setRowSelectionInterval( trabalhadoresTable.getRowCount() - 1, trabalhadoresTable.getRowCount() - 1 );
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				trabalhadoresModel.removeRowAt( selected );
 | 
						|
				trabalhadoresModel.insertRowAt( obj, selected );
 | 
						|
				trabalhadoresTable.setRowSelectionInterval( selected, selected );
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void reload()
 | 
						|
	{
 | 
						|
		fill( trabalhador );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void addListSelectionListener( ListSelectionListener listener )
 | 
						|
	{
 | 
						|
		listeners.add( listener );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void removeListSelectionListener( ListSelectionListener listener )
 | 
						|
	{
 | 
						|
		listeners.remove( listener );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public Integer getSelectedTrabalhador()
 | 
						|
	{
 | 
						|
		int selected = trabalhadoresTable.getSelectedRow();
 | 
						|
		if( selected == -1 )
 | 
						|
		{
 | 
						|
			return null;
 | 
						|
		}
 | 
						|
		return ( (IDObject) trabalhadoresModel.getRowAt( selected ) ).getID();
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void setEstabelecimento( EstabelecimentoData estabelecimento )
 | 
						|
	{
 | 
						|
		this.estabelecimento = estabelecimento;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void setSelectedTrabalhador( TrabalhadorData trab )
 | 
						|
	{
 | 
						|
		IDObject lista[] = (IDObject [])trabalhadoresModel.getValues().toArray( new IDObject[ 0 ] );
 | 
						|
		Integer id = (Integer)trab.get( TrabalhadorData.ID );
 | 
						|
		for( int n = 0; n < lista.length; n++ )
 | 
						|
		{
 | 
						|
			if( lista[ n ].getID().equals( id ) )
 | 
						|
			{
 | 
						|
				trabalhadoresTable.setRowSelectionInterval( n, n );
 | 
						|
				return;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		trabalhadoresTable.clearSelection();
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void actionPerformed( ActionEvent e )
 | 
						|
	{
 | 
						|
		Object source = e.getSource();
 | 
						|
		if( source.equals( marcacoesButton ) )
 | 
						|
		{
 | 
						|
			if( trabalhador == null )
 | 
						|
			{
 | 
						|
				return;
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				EstabelecimentoData estabelecimento = ( EstabelecimentoData ) trabalhador.get( TrabalhadorData.ESTABELECIMENTO );
 | 
						|
				EmpresaData empresa = ( EmpresaData ) estabelecimento.get( EstabelecimentoData.EMPRESA );
 | 
						|
				tracker.getMedicinaWindow().setVisible( true );
 | 
						|
				tracker.getMedicinaWindow().setEmpresaAndEstabelecimentoAndTrabalhador( (Integer) empresa.get( EmpresaData.ID ),
 | 
						|
																( Integer ) estabelecimento.get( EstabelecimentoData.ID ),
 | 
						|
																( Integer ) trabalhador.get( TrabalhadorData.ID ) );
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void setTracker( SIPRPTracker tracker )
 | 
						|
	{
 | 
						|
		this.tracker = tracker;
 | 
						|
	}
 | 
						|
}
 |