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.
		
		
		
		
		
			
		
			
				
					
					
						
							334 lines
						
					
					
						
							8.6 KiB
						
					
					
				
			
		
		
	
	
							334 lines
						
					
					
						
							8.6 KiB
						
					
					
				| /*
 | |
|  * ProcessoPanel.java
 | |
|  *
 | |
|  * Created on March 21, 2007, 9:11 AM
 | |
|  *
 | |
|  * To change this template, choose Tools | Template Manager
 | |
|  * and open the template in the editor.
 | |
|  */
 | |
| 
 | |
| package siprp.medicina.processo;
 | |
| 
 | |
| import com.evolute.utils.dataui.ControllableComponent;
 | |
| import com.evolute.utils.images.ImageIconLoader;
 | |
| import com.evolute.utils.ui.DialogException;
 | |
| import info.clearthought.layout.TableLayout;
 | |
| import info.clearthought.layout.TableLayoutConstraints;
 | |
| import java.awt.*;
 | |
| import java.awt.event.ActionEvent;
 | |
| import java.awt.event.ActionListener;
 | |
| import java.text.DateFormat;
 | |
| import java.util.Date;
 | |
| import java.util.Locale;
 | |
| import java.util.Vector;
 | |
| import javax.swing.*;
 | |
| import siprp.medicina.MedicinaConstants;
 | |
| import siprp.medicina.processo.data.TrabalhadoresProcessoData;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author fpalma
 | |
|  */
 | |
| public class ProcessoPanel extends JPanel
 | |
| 		implements ActionListener, ControllableComponent, 
 | |
| 					MedicinaConstants, ProcessoConstants
 | |
| {
 | |
| 	private static final String ECDS_ICON_PATH = "siprp/medicina/processo/icons/ecds.png";
 | |
| 	private static final String CONSULTA_ICON_PATH = "siprp/medicina/processo/icons/consulta.png";
 | |
| 	private static final String FICHA_APTIDAO_ICON_PATH = "siprp/medicina/processo/icons/fichaaptidao.png";
 | |
| 	private static final String FECHAR_ICON_PATH = "siprp/medicina/processo/icons/lock.png";
 | |
| 	
 | |
| 	private static final DateFormat D_F = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) );
 | |
| 	
 | |
| 	private JTextField estadoText;
 | |
| 	private JTextField inicioText;
 | |
| 	private JTextField fimText;
 | |
| 	private JButton motivoButton;
 | |
| 	private JButton novoECDButton;
 | |
| 	private JButton novaConsultaButton;
 | |
| 	private JButton emitirFAButton;
 | |
| 	private JButton fecharButton;
 | |
| 		
 | |
| 	protected JFrame owner;
 | |
| 	
 | |
| 	private final Vector<ProcessoListener> PROCESSO_LISTENERS = new Vector<ProcessoListener>();
 | |
| 	
 | |
| 	private ProcessoDataProvider provider;
 | |
| 	
 | |
| 	private Integer trabalhadorID = null;
 | |
| 	private TrabalhadoresProcessoData processo;
 | |
| 	
 | |
| 	/** Creates a new instance of ProcessoPanel */
 | |
| 	public ProcessoPanel( JFrame owner )
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		this.owner = owner;
 | |
| 		provider = ProcessoDataProvider.getProvider();
 | |
| 		setupComponents();
 | |
| 		enableButtons( false );
 | |
| 	}
 | |
| 	
 | |
| 	
 | |
| 	private void setupComponents()
 | |
| 	{
 | |
| 		motivoButton = new JButton( "Motivo" );
 | |
| 		motivoButton.addActionListener( this );
 | |
| 		JLabel estadoLabel = new JLabel( "Estado" );
 | |
| 		estadoText = new JTextField();
 | |
| 		estadoText.setPreferredSize( new Dimension( 120, 20 ) );
 | |
| 		estadoText.setEditable( false );
 | |
| 		JLabel inicioLabel = new JLabel( "In\u00edcio" );
 | |
| 		inicioText = new JTextField();
 | |
| 		inicioText.setPreferredSize( new Dimension( 120, 20 ) );
 | |
| 		inicioText.setEditable( false );
 | |
| 		JLabel fimLabel = new JLabel( "Fim" );
 | |
| 		fimText = new JTextField();
 | |
| 		fimText.setPreferredSize( new Dimension( 120, 20 ) );
 | |
| 		fimText.setEditable( false );
 | |
| 		novoECDButton = new JButton( "Marcar ECDs" );
 | |
| 		novoECDButton.setIcon( getIcon( ECDS_ICON_PATH ) );
 | |
| 		novoECDButton.addActionListener( this );
 | |
| 		novaConsultaButton = new JButton( "Marcar Consulta" );
 | |
| 		novaConsultaButton.setIcon( getIcon( CONSULTA_ICON_PATH ) );
 | |
| 		novaConsultaButton.addActionListener( this );
 | |
| 		emitirFAButton = new JButton( "Ficha de Aptid\u00e3o" );
 | |
| 		emitirFAButton.setIcon( getIcon( FICHA_APTIDAO_ICON_PATH ) );
 | |
| 		emitirFAButton.addActionListener( this );
 | |
| 		fecharButton = new JButton( "Fechar Processo" );
 | |
| 		fecharButton.setIcon( getIcon( FECHAR_ICON_PATH ) );
 | |
| 		fecharButton.addActionListener( this );
 | |
| 		JPanel buttonPanel = new JPanel();
 | |
| 		
 | |
| 		double cols[] =
 | |
| 				new double[]{ TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL };
 | |
| 		double rows[] =
 | |
| 				new double[]{ TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
 | |
| 				TableLayout.PREFERRED, TableLayout.FILL };
 | |
| 		
 | |
| 		TableLayout tableLayout = new TableLayout( cols, rows );
 | |
| 		setLayout( tableLayout );
 | |
| 		
 | |
| 		add( motivoButton, new TableLayoutConstraints( 0, 0, 2, 0 ) );
 | |
| 		add( estadoLabel, new TableLayoutConstraints( 0, 1 ) );
 | |
| 		add( estadoText, new TableLayoutConstraints( 1, 1 ) );
 | |
| 		add( inicioLabel, new TableLayoutConstraints( 0, 2 ) );
 | |
| 		add( inicioText, new TableLayoutConstraints( 1, 2 ) );
 | |
| 		add( fimLabel, new TableLayoutConstraints( 0, 3 ) );
 | |
| 		add( fimText, new TableLayoutConstraints( 1, 3 ) );
 | |
| 		add( buttonPanel, new TableLayoutConstraints( 2, 1, 2, 3 ) );
 | |
| 		
 | |
| 		buttonPanel.setLayout( new GridLayout( 2, 2 ) );
 | |
| 		buttonPanel.add( novoECDButton );
 | |
| 		buttonPanel.add( novaConsultaButton );
 | |
| 		buttonPanel.add( emitirFAButton );
 | |
| 		buttonPanel.add( fecharButton );
 | |
| 	}
 | |
| 	
 | |
| 	public void actionPerformed(ActionEvent e)
 | |
| 	{
 | |
| 		Object source = e.getSource();
 | |
| 		if( source.equals( motivoButton ) )
 | |
| 		{
 | |
| 			escolherMotivo();
 | |
| 		}
 | |
| 		else if( source.equals( novoECDButton ) )
 | |
| 		{
 | |
| 			novoECD();
 | |
| 		}
 | |
| 		else if( source.equals( novaConsultaButton ) )
 | |
| 		{
 | |
| 			novaConsulta();
 | |
| 		}
 | |
| 		else if( source.equals( emitirFAButton ) )
 | |
| 		{
 | |
| 			emitirFA();
 | |
| 		}
 | |
| 		else if( source.equals( fecharButton ) )
 | |
| 		{
 | |
| 			fecharProcesso();
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	protected boolean gravarProcesso()
 | |
| 	{
 | |
| 		if( processo.get( TrabalhadoresProcessoData.ESTADO ) == null )
 | |
| 		{
 | |
| 			processo.set( TrabalhadoresProcessoData.ESTADO, PROCESSO_ABERTO_CODE );
 | |
| 			processo.set( TrabalhadoresProcessoData.DATA_INICIO, new Date() );
 | |
| 		}
 | |
| 		try
 | |
| 		{
 | |
| 			provider.saveProcesso( processo );
 | |
| 			return true;
 | |
| 		}
 | |
| 		catch( Exception ex )
 | |
| 		{
 | |
| 			DialogException.showExceptionMessage( ex, "Erro a gravar processo", true );
 | |
| 			return false;
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	protected void escolherMotivo()
 | |
| 	{
 | |
| 		EscolherMotivoDialog dialog = new EscolherMotivoDialog( owner );
 | |
| 		dialog.setVisible( true );
 | |
| 		Integer motivo[] = dialog.getMotivo();
 | |
| 		if( motivo != null && motivo[ 0 ] != null )
 | |
| 		{
 | |
| 			processo.set( TrabalhadoresProcessoData.MOTIVO, motivo[ 0 ] );
 | |
| 			processo.set( TrabalhadoresProcessoData.SUB_MOTIVO, motivo[ 1 ] );
 | |
| 			if( gravarProcesso() )
 | |
| 			{
 | |
| 				reload();
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	protected void novoECD()
 | |
| 	{
 | |
| 	}
 | |
| 	
 | |
| 	protected void novaConsulta()
 | |
| 	{
 | |
| 	}
 | |
| 	
 | |
| 	protected void emitirFA()
 | |
| 	{
 | |
| 	}
 | |
| 	
 | |
| 	protected void fecharProcesso()
 | |
| 	{
 | |
| 	}
 | |
| 
 | |
| 	public void clear()
 | |
| 	{
 | |
| 		processo = null;
 | |
| 		estadoText.setText( "" );
 | |
| 		inicioText.setText( "" );
 | |
| 		fimText.setText( "" );
 | |
| 		motivoButton.setText( "Motivo" );
 | |
| 	}
 | |
| 	
 | |
| 	protected void enableButtons( boolean enable )
 | |
| 	{
 | |
| 		novoECDButton.setEnabled( enable );
 | |
| 		novaConsultaButton.setEnabled( enable );
 | |
| 		emitirFAButton.setEnabled( enable );
 | |
| 		fecharButton.setEnabled( enable );
 | |
| 		motivoButton.setEnabled( enable );
 | |
| 	}
 | |
| 		
 | |
| 	public void addProcessoListener( ProcessoListener listener )
 | |
| 	{
 | |
| 		PROCESSO_LISTENERS.add( listener );
 | |
| 	}
 | |
| 	
 | |
| 	public Icon getIcon( String path )
 | |
| 	{
 | |
| 		try
 | |
| 		{
 | |
| 			return ImageIconLoader.loadImageIcon( getClass(), path );
 | |
| 		}
 | |
| 		catch( Exception ex )
 | |
| 		{
 | |
| 			ex.printStackTrace();
 | |
| 			return null;
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	public Object save()
 | |
| 	{
 | |
| 		return null;
 | |
| 	}
 | |
| 	
 | |
| 	public void enableComponents( boolean enable )
 | |
| 	{
 | |
| 		
 | |
| 	}
 | |
| 	
 | |
| 	public void fill( Object value )
 | |
| 	{
 | |
| 		clear();
 | |
| 		if( trabalhadorID == null )
 | |
| 		{
 | |
| 			return;
 | |
| 		}
 | |
| 		if( value != null )
 | |
| 		{
 | |
| 			try
 | |
| 			{
 | |
| 				processo = provider.getProcessoByID( ( Integer ) value );
 | |
| 				if( processo == null )
 | |
| 				{
 | |
| 					processo = new TrabalhadoresProcessoData();
 | |
| 					processo.set( TrabalhadoresProcessoData.TRABALHADOR_ID, trabalhadorID );
 | |
| 				}
 | |
| 			}
 | |
| 			catch( Exception ex )
 | |
| 			{
 | |
| 				DialogException.showExceptionMessage( ex, "Erro a carregar dados do processo", true );
 | |
| 			}
 | |
| 		}
 | |
| 		reload();
 | |
| 	}
 | |
| 	
 | |
| 	public void reload()
 | |
| 	{
 | |
| 		enableButtons( processo != null );
 | |
| 		if( processo != null )
 | |
| 		{
 | |
| 			enableButtons( true );
 | |
| 			String estado = null;
 | |
| 			Date dataInicio = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_INICIO );
 | |
| 			if( dataInicio != null )
 | |
| 			{
 | |
| 				inicioText.setText( D_F.format( dataInicio ) );
 | |
| 			}
 | |
| 			Date dataFim = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_FIM );
 | |
| 			if( dataFim != null )
 | |
| 			{
 | |
| 				fimText.setText( D_F.format( dataFim ) );
 | |
| 			}
 | |
| 			estado = ( String ) processo.get( TrabalhadoresProcessoData.ESTADO );
 | |
| 			if( estado == null )
 | |
| 			{
 | |
| 				estadoText.setText( ProcessoDataProvider.PROCESSO_POR_ABRIR_DESCRIPTION );
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				estadoText.setText( ProcessoDataProvider.ESTADO_PROCESSO_BY_CODE.get( estado ) );
 | |
| 			}
 | |
| 			Integer motivo = ( Integer ) processo.get( TrabalhadoresProcessoData.MOTIVO );
 | |
| 			Integer subMotivo = ( Integer ) processo.get( TrabalhadoresProcessoData.SUB_MOTIVO );
 | |
| 			String motivoStr = "Motivo";
 | |
| 			if( motivo != null )
 | |
| 			{
 | |
| 				switch( motivo.intValue() )
 | |
| 				{
 | |
| 					case MOTIVO_ADMISSAO:
 | |
| 						motivoStr = MOTIVO_ADMISSAO_STR;
 | |
| 						break;
 | |
| 						
 | |
| 					case MOTIVO_PERIODICO:
 | |
| 						motivoStr = MOTIVO_PERIODICO_STR;
 | |
| 						break;
 | |
| 						
 | |
| 					case MOTIVO_PERIODICO_INICIAL:
 | |
| 						motivoStr = MOTIVO_PERIODICO_INICIAL_STR;
 | |
| 						break;
 | |
| 						
 | |
| 					case MOTIVO_OCASIONAL:
 | |
| 						motivoStr = MOTIVO_OCASIONAL_STR;
 | |
| 						break;
 | |
| 				}
 | |
| 			}
 | |
| 			motivoButton.setText( motivoStr );
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	public void setTrabalhadorID( Integer trabalhadorID )
 | |
| 	{
 | |
| 		this.trabalhadorID = trabalhadorID;
 | |
| 	}
 | |
| }
 |