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.
		
		
		
		
		
			
		
			
				
					
					
						
							577 lines
						
					
					
						
							21 KiB
						
					
					
				
			
		
		
	
	
							577 lines
						
					
					
						
							21 KiB
						
					
					
				| /*
 | |
|  * AvisosPanel.java
 | |
|  *
 | |
|  * Created on 21 de Maio de 2004, 13:06
 | |
|  */
 | |
| 
 | |
| package siprp.clientes;
 | |
| 
 | |
| import java.awt.*;
 | |
| import java.awt.event.*;
 | |
| import java.text.*;
 | |
| import java.util.*;
 | |
| import javax.swing.*;
 | |
| import java.util.*;
 | |
| 
 | |
| import com.evolute.utils.*;
 | |
| import com.evolute.utils.dataui.*;
 | |
| import com.evolute.utils.jdo.*;
 | |
| import com.evolute.utils.ui.*;
 | |
| 
 | |
| import siprp.*;
 | |
| import siprp.data.*;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author  fpalma
 | |
|  */
 | |
| public class AvisosPanel extends JPanel
 | |
| 	implements ActionListener, ControllableComponent
 | |
| {
 | |
| 	private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( DateFormat.SHORT );
 | |
| 	private JDOProvider JDO;
 | |
| 	private FichaDataProvider provider;
 | |
| 	private SIPRPTracker tracker;
 | |
| 	
 | |
| 	private JPanel empresaPanel;
 | |
| 	private JPanel estabelecimentosPanel;
 | |
| 	private JPanel trabalhadoresPanel;
 | |
| 	
 | |
| //	private AvisoData avisos[];
 | |
| //	private AvisoData avisosEmpresa[];
 | |
| //	private AvisoData avisosEstabelecimento[];
 | |
| //	private AvisoData avisosTrabalhador[];
 | |
| 	
 | |
| 	private Object avisosEmpresa[][];
 | |
| 	private Object avisosEstabelecimento[][];
 | |
| 	private Object avisosTrabalhador[][];
 | |
| 	
 | |
| 	private boolean refreshed = false;
 | |
| 	
 | |
| 	private Hashtable buttonHash;
 | |
| 	private Hashtable buttonTypeHash;
 | |
| 	
 | |
| 	/** Creates a new instance of AvisosPanel */
 | |
| 	public AvisosPanel(/* AvisoData avisosEmpresa[], AvisoData avisosEstabelecimento[], AvisoData avisosTrabalhador[]*/ )
 | |
| 		throws Exception
 | |
| 	{
 | |
| //		this.avisosEmpresa = new AvisoData[ 0 ];
 | |
| //		this.avisosEstabelecimento = new AvisoData[ 0 ];
 | |
| //		this.avisosTrabalhador = new AvisoData[ 0 ];
 | |
| //		setupComponents();
 | |
| 		buttonHash = new Hashtable();
 | |
| 		buttonTypeHash = new Hashtable();
 | |
| 		JDO = (JDOProvider) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER );
 | |
| //		System.out.println( "public AvisosPanel() JDO: " + JDO );
 | |
| 	}
 | |
| 	
 | |
| 	private void setupComponents()
 | |
| 	{
 | |
| 		empresaPanel = new JPanel();
 | |
| 		empresaPanel.setBorder( 
 | |
| 			BorderFactory.createTitledBorder( 
 | |
| 				BorderFactory.createLineBorder( new Color( 0.0f, 0.0f, 0.0f, 0.0f ), 1 ), "Empresas" ) );
 | |
| 		empresaPanel.setLayout( new GridLayout( avisosEmpresa.length, 1 ) );
 | |
| 		GridBagConstraints constraints = new GridBagConstraints();
 | |
| 		constraints.insets = new Insets( 1, 1, 1, 1 );
 | |
| 		constraints.fill = GridBagConstraints.HORIZONTAL;
 | |
| 		constraints.weighty = 0;
 | |
| 		for( int n = 0; n < avisosEmpresa.length; n++ )
 | |
| 		{
 | |
| 			JPanel pan = new JPanel();
 | |
| 			GridBagLayout gridbag = new GridBagLayout();
 | |
| 			pan.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) );
 | |
| //			EmpresaData empresa = (EmpresaData)avisosEmpresa[ n ].get( AvisoData.EMPRESA );
 | |
| 			pan.setLayout( gridbag );
 | |
| 			constraints.gridheight = GridBagConstraints.REMAINDER;
 | |
| 			constraints.gridx = 0;
 | |
| 			constraints.weightx = 0;
 | |
| 			constraints.gridwidth = 1;
 | |
| 			JButton tratarButton = new JButton( "Tratar" );
 | |
| 			gridbag.setConstraints( tratarButton, constraints );
 | |
| 			pan.add( tratarButton );
 | |
| 			//buttonHash.put( tratarButton, avisosEmpresa[ n ] );
 | |
| //			buttonHash.put( tratarButton, new Integer( n ) );
 | |
| //			buttonHash.put( tratarButton, avisosEmpresa[ n ].get( AvisoData.ID ) );
 | |
| 			buttonHash.put( tratarButton, avisosEmpresa[ n ][ 0 ] );
 | |
| 			buttonTypeHash.put( tratarButton, new Integer( AvisoConstants.TIPO_EMPRESA ) );
 | |
| 			tratarButton.addActionListener( this );
 | |
| 			
 | |
| 			constraints.gridx = 1;
 | |
| 			constraints.weightx = 1;
 | |
| 			constraints.gridheight = 1;
 | |
| 			constraints.gridwidth = GridBagConstraints.REMAINDER;
 | |
| //			JLabel empresaLabel = new JLabel( "" + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) );
 | |
| 			JLabel empresaLabel = new JLabel( "" + avisosEmpresa[ n ][ 3 ]  );
 | |
| 			gridbag.setConstraints( empresaLabel, constraints );
 | |
| 			pan.add( empresaLabel );
 | |
| 			
 | |
| 			
 | |
| 			constraints.weightx = 1;
 | |
| 			constraints.gridwidth = GridBagConstraints.REMAINDER;
 | |
| 			//JLabel descricaoLabel = new JLabel( (String)avisosEmpresa[ n ].get( AvisoData.DESCRICAO ) );
 | |
| 			JLabel descricaoLabel = criarDescricao( avisosEmpresa[ n ] );
 | |
| 			gridbag.setConstraints( descricaoLabel, constraints );
 | |
| 			pan.add( descricaoLabel );
 | |
| 			
 | |
| 			empresaPanel.add( pan );
 | |
| 		}
 | |
| 
 | |
| 		estabelecimentosPanel = new JPanel();
 | |
| 		estabelecimentosPanel.setBorder( 
 | |
| 			BorderFactory.createTitledBorder( 
 | |
| 				BorderFactory.createLineBorder( new Color( 0.0f, 0.0f, 0.0f, 0.0f ), 1 ), "Estabelecimentos" ) );
 | |
| 		estabelecimentosPanel.setLayout( new GridLayout( avisosEstabelecimento.length, 1 ) );
 | |
| 
 | |
| 		for( int n = 0; n < avisosEstabelecimento.length; n++ )
 | |
| 		{
 | |
| 			Date dataAviso = ( Date ) avisosEstabelecimento[ n ][ 5 ];
 | |
| 			Date dataEvento = ( Date ) avisosEstabelecimento[ n ][ 1 ];
 | |
| 			Calendar calAviso = Calendar.getInstance();
 | |
| 			calAviso.setTime( dataAviso );
 | |
| 			Calendar calEvento = Calendar.getInstance();
 | |
| 			calEvento.setTime( dataEvento );
 | |
| 			boolean mesmoDia = 
 | |
| 					( calAviso.get( Calendar.YEAR ) == calEvento.get( Calendar.YEAR ) ) &&
 | |
| 					( calAviso.get( Calendar.MONTH ) == calEvento.get( Calendar.MONTH ) ) &&
 | |
| 					( calAviso.get( Calendar.DAY_OF_MONTH ) == calEvento.get( Calendar.DAY_OF_MONTH ) );
 | |
| 			JPanel pan = new JPanel();
 | |
| 			GridBagLayout gridbag = new GridBagLayout();
 | |
| 			pan.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) );
 | |
| //			EstabelecimentoData estabelecimento = (EstabelecimentoData)avisosEstabelecimento[ n ].get( AvisoData.ESTABELECIMENTO );
 | |
| //			EmpresaData empresa = (EmpresaData)estabelecimento.get( EstabelecimentoData.EMPRESA );
 | |
| 			pan.setLayout( gridbag );
 | |
| 			constraints.gridheight = GridBagConstraints.REMAINDER;
 | |
| 			constraints.gridx = 0;
 | |
| 			constraints.weightx = 0;
 | |
| 			constraints.gridwidth = 1;
 | |
| 			JButton tratarButton = new JButton( mesmoDia ? "Confirmar" : "Marcar" );
 | |
| 			gridbag.setConstraints( tratarButton, constraints );
 | |
| 			pan.add( tratarButton );
 | |
| 			//buttonHash.put( tratarButton, avisosEstabelecimento[ n ] );
 | |
| //			buttonHash.put( tratarButton, new Integer( n + avisosEmpresa.length ) );
 | |
| //			buttonHash.put( tratarButton, avisosEstabelecimento[ n ].get( AvisoData.ID ) );
 | |
| 			buttonHash.put( tratarButton, avisosEstabelecimento[ n ][ 0 ] );
 | |
| 			buttonTypeHash.put( tratarButton, new Integer( AvisoConstants.TIPO_ESTABELECIMENTO ) );
 | |
| 			tratarButton.addActionListener( this );
 | |
| 			
 | |
| 			constraints.gridx = 1;
 | |
| 			constraints.weightx = 1;
 | |
| 			constraints.gridheight = 1;
 | |
| 			constraints.gridwidth = GridBagConstraints.REMAINDER;
 | |
| //			JLabel empresaLabel = new JLabel( "" + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) );
 | |
| 			JLabel empresaLabel = new JLabel( "" + avisosEstabelecimento[ n ][ 3 ] );
 | |
| 			gridbag.setConstraints( empresaLabel, constraints );
 | |
| 			pan.add( empresaLabel );
 | |
| 			
 | |
| //			JLabel estabelecimentoLabel = new JLabel( "" + estabelecimento.get( EstabelecimentoData.NOME ) );
 | |
| 			JLabel estabelecimentoLabel = new JLabel( "" + avisosEstabelecimento[ n ][ 4 ] );
 | |
| 			gridbag.setConstraints( estabelecimentoLabel, constraints );
 | |
| 			pan.add( estabelecimentoLabel );
 | |
| 			
 | |
| 			constraints.gridwidth = GridBagConstraints.REMAINDER;
 | |
| 			//JLabel descricaoLabel = new JLabel( (String)avisosEstabelecimento[ n ].get( AvisoData.DESCRICAO ) );
 | |
| 			JLabel descricaoLabel = criarDescricao( avisosEstabelecimento[ n ] );
 | |
| 			gridbag.setConstraints( descricaoLabel, constraints );
 | |
| 			pan.add( descricaoLabel );
 | |
| 			
 | |
| 			estabelecimentosPanel.add( pan );
 | |
| 		}
 | |
| 
 | |
| 		trabalhadoresPanel = new JPanel();
 | |
| 		trabalhadoresPanel.setBorder( 
 | |
| 			BorderFactory.createTitledBorder( 
 | |
| 				BorderFactory.createLineBorder( new Color( 0.0f, 0.0f, 0.0f, 0.0f ), 1 ), "Trabalhadores" ) );
 | |
| 		trabalhadoresPanel.setLayout( new GridLayout( avisosTrabalhador.length, 1 ) );
 | |
| 
 | |
| 		for( int n = 0; n < avisosTrabalhador.length; n++ )
 | |
| 		{
 | |
| 			Date dataAviso = ( Date ) avisosTrabalhador[ n ][ 6 ];
 | |
| 			Date dataEvento = ( Date ) avisosTrabalhador[ n ][ 1 ];
 | |
| 			Calendar calAviso = Calendar.getInstance();
 | |
| 			calAviso.setTime( dataAviso );
 | |
| 			Calendar calEvento = Calendar.getInstance();
 | |
| 			calEvento.setTime( dataEvento );
 | |
| 			boolean mesmoDia = 
 | |
| 					( calAviso.get( Calendar.YEAR ) == calEvento.get( Calendar.YEAR ) ) &&
 | |
| 					( calAviso.get( Calendar.MONTH ) == calEvento.get( Calendar.MONTH ) ) &&
 | |
| 					( calAviso.get( Calendar.DAY_OF_MONTH ) == calEvento.get( Calendar.DAY_OF_MONTH ) );
 | |
| 			JPanel pan = new JPanel();
 | |
| 			GridBagLayout gridbag = new GridBagLayout();
 | |
| 			pan.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) );
 | |
| //			TrabalhadorData trabalhador = (TrabalhadorData)avisosTrabalhador[ n ].get( AvisoData.TRABALHADOR );
 | |
| //			EstabelecimentoData estabelecimento = (EstabelecimentoData)trabalhador.get( TrabalhadorData.ESTABELECIMENTO );
 | |
| //			EmpresaData empresa = (EmpresaData)estabelecimento.get( EstabelecimentoData.EMPRESA );
 | |
| 			pan.setLayout( gridbag );
 | |
| 			constraints.gridheight = GridBagConstraints.REMAINDER;
 | |
| 			constraints.gridx = 0;
 | |
| 			constraints.weightx = 0;
 | |
| 			constraints.gridwidth = 1;
 | |
| 			JButton tratarButton = new JButton( mesmoDia ? "Confirmar" : "Marcar" );
 | |
| 			gridbag.setConstraints( tratarButton, constraints );
 | |
| 			pan.add( tratarButton );
 | |
| 			//buttonHash.put( tratarButton, avisosTrabalhador[ n ] );
 | |
| //			buttonHash.put( tratarButton, new Integer( n + avisosEmpresa.length + avisosEstabelecimento.length ) );
 | |
| //			buttonHash.put( tratarButton, avisosTrabalhador[ n ].get( AvisoData.ID ) );
 | |
| 			buttonHash.put( tratarButton, avisosTrabalhador[ n ][ 0 ] );
 | |
| 			buttonTypeHash.put( tratarButton, new Integer( AvisoConstants.TIPO_TRABALHADOR ) );
 | |
| 			tratarButton.addActionListener( this );
 | |
| 
 | |
| 			constraints.gridx = 1;
 | |
| 			constraints.weightx = 1;
 | |
| 			constraints.gridheight = 1;
 | |
| 			constraints.gridwidth = GridBagConstraints.REMAINDER;
 | |
| //			JLabel empresaLabel = new JLabel( "" + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) );
 | |
| 			JLabel empresaLabel = new JLabel( "" + avisosTrabalhador[ n ][ 3 ] );
 | |
| 			gridbag.setConstraints( empresaLabel, constraints );
 | |
| 			pan.add( empresaLabel );
 | |
| 
 | |
| //			JLabel estabelecimentoLabel = new JLabel( "" + estabelecimento.get( EstabelecimentoData.NOME ) );
 | |
| 			JLabel estabelecimentoLabel = new JLabel( "" + avisosTrabalhador[ n ][ 4 ] );
 | |
| 			gridbag.setConstraints( estabelecimentoLabel, constraints );
 | |
| 			pan.add( estabelecimentoLabel );
 | |
| 
 | |
| //			JLabel trabalhadorLabel = new JLabel( "" + trabalhador.get( TrabalhadorData.NOME ) );
 | |
| 			JLabel trabalhadorLabel = new JLabel( "" + avisosTrabalhador[ n ][ 5 ] );
 | |
| 			gridbag.setConstraints( trabalhadorLabel, constraints );
 | |
| 			pan.add( trabalhadorLabel );
 | |
| 			constraints.gridwidth = GridBagConstraints.REMAINDER;
 | |
| 			//JLabel descricaoLabel = new JLabel( (String)avisosTrabalhador[ n ].get( AvisoData.DESCRICAO ) );
 | |
| 			JLabel descricaoLabel = criarDescricao( avisosTrabalhador[ n ] );
 | |
| 			gridbag.setConstraints( descricaoLabel, constraints );
 | |
| 			pan.add( descricaoLabel );
 | |
| 
 | |
| 			trabalhadoresPanel.add( pan );
 | |
| 		}
 | |
| 
 | |
| //		Vector v = new Vector( Arrays.asList( avisosEmpresa ) );
 | |
| //		v.addAll( Arrays.asList( avisosTrabalhador ) );
 | |
| //		v.addAll( Arrays.asList( avisosEstabelecimento ) );
 | |
| //		avisos = (AvisoData []) v.toArray( new AvisoData[0] );
 | |
| 		
 | |
| 		JScrollPane scp = new JScrollPane();
 | |
| 		setLayout( new GridLayout( 1, 1 ) );
 | |
| 		add( scp );
 | |
| 		JPanel contentPanel = new JPanel();
 | |
| 		scp.setViewportView( contentPanel );
 | |
| 		contentPanel.setLayout( new BoxLayout( contentPanel, BoxLayout.Y_AXIS ) );
 | |
| 		if( avisosEmpresa.length > 0 )
 | |
| 		{
 | |
| 			contentPanel.add( empresaPanel );
 | |
| 		}
 | |
| 		if( avisosTrabalhador.length > 0 )
 | |
| 		{
 | |
| 			contentPanel.add( new JLabel( " " ) );
 | |
| 			contentPanel.add( trabalhadoresPanel );
 | |
| 		}
 | |
| 		if( avisosEstabelecimento.length > 0 )
 | |
| 		{
 | |
| 			contentPanel.add( new JLabel( " " ) );
 | |
| 			contentPanel.add( estabelecimentosPanel );
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public void refresh()
 | |
| 	{
 | |
| 		if( refreshed )
 | |
| 		{
 | |
| 			return;
 | |
| 		}
 | |
| 		refreshed = true;
 | |
| 		try
 | |
| 		{
 | |
| 			provider = ( FichaDataProvider ) FichaDataProvider.getProvider();
 | |
| //		Collection c = AvisoData.load( AvisoData.class, " estabelecimento_id == \"null\" ",
 | |
| //				AvisoData.DATA_EVENTO + " ascending" );
 | |
| 			
 | |
| //		Collection c = AvisoData.load( AvisoData.class, "(tipo == " + AvisoData.TIPO_EMPRESA+")",// + ") && ( data_aviso <= CURRENT_DATE )",
 | |
| //				AvisoData.DATA_EVENTO + " ascending" );
 | |
| //		Collection c = AvisoData.load( AvisoData.class, new Object[]{ /*new Integer( AvisoData.TIPO_EMPRESA ), */new Date() },
 | |
| //												new String[]{ /*"tipo", */"data_aviso" },
 | |
| //												new String[]{ "=="/*, "==" */},
 | |
| //												new String[]{ AvisoData.DATA_EVENTO + " ascending" } );
 | |
| 			
 | |
| //		if( c == null )
 | |
| //		{
 | |
| //			avisosEmpresa = new AvisoData[ 0 ];
 | |
| //		}
 | |
| //		else
 | |
| //		{
 | |
| //
 | |
| //			avisosEmpresa = ( AvisoData[] )c.toArray( new AvisoData[ c.size() ] );
 | |
| //		}
 | |
| 			
 | |
| //		Integer ids[] = provider.getAvisosIDByTipoAndDate( new Integer( AvisoConstants.TIPO_EMPRESA ), new Date() );
 | |
| //		avisosEmpresa = new AvisoData[ ids.length ];
 | |
| //		if( JDO == null )
 | |
| //		{
 | |
| //			JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER );
 | |
| //		}
 | |
| ////		System.out.println( "JDO: " + JDO );
 | |
| //		for( int n = 0; n < avisosEmpresa.length; n++ )
 | |
| //		{
 | |
| //			avisosEmpresa[ n ] = (AvisoData) JDO.load( AvisoData.class, ids[ n ] );
 | |
| //		}
 | |
| //		
 | |
| ////System.out.println( "EmpresaData " + avisosEmpresa.length );
 | |
| ////		c = AvisoData.load( AvisoData.class, " tipo == " + AvisoData.TIPO_ESTABELECIMENTO,// + ") && ( data_aviso <= new Date() )",
 | |
| ////				AvisoData.DATA_EVENTO + " ascending" );
 | |
| ////		c = AvisoData.load( AvisoData.class, "estabelecimento_id != \"null\" "
 | |
| ////			+ " && trabalhador_id == \"null\"", AvisoData.DATA_EVENTO + " ascending" );
 | |
| ////		if( c == null )
 | |
| ////		{
 | |
| ////			avisosEstabelecimento = new AvisoData[ 0 ];
 | |
| ////		}
 | |
| ////		else
 | |
| ////		{
 | |
| ////			avisosEstabelecimento = ( AvisoData[] )c.toArray( new AvisoData[ c.size() ] );
 | |
| ////		}
 | |
| //
 | |
| //		ids = provider.getAvisosIDByTipoAndDate( new Integer( AvisoConstants.TIPO_ESTABELECIMENTO ), new Date() );
 | |
| //		avisosEstabelecimento = new AvisoData[ ids.length ];
 | |
| //		for( int n = 0; n < avisosEstabelecimento.length; n++ )
 | |
| //		{
 | |
| //			avisosEstabelecimento[ n ] = (AvisoData) JDO.load( AvisoData.class, new Object[]{ids[ n ]}, new String[]{ "id" } );
 | |
| //		}
 | |
| ////System.out.println( "EstabelecimentoData " + avisosEstabelecimento.length );
 | |
| ////		c = AvisoData.load( AvisoData.class, " tipo == " + AvisoData.TIPO_TRABALHADOR,// + ") && ( data_aviso <= new Date() )",
 | |
| ////				AvisoData.DATA_EVENTO + " ascending" );
 | |
| ////		c = AvisoData.load( AvisoData.class, "trabalhador_id != \"null\"", AvisoData.DATA_EVENTO + " ascending" );
 | |
| ////		if( c == null )
 | |
| ////		{
 | |
| ////			avisosTrabalhador = new AvisoData[ 0 ];
 | |
| ////		}
 | |
| ////		else
 | |
| ////		{
 | |
| ////			avisosTrabalhador = ( AvisoData[] )c.toArray( new AvisoData[ c.size() ] );
 | |
| ////		}
 | |
| //		ids = provider.getAvisosIDByTipoAndDate( new Integer( AvisoConstants.TIPO_TRABALHADOR ), new Date() );
 | |
| //
 | |
| //		avisosTrabalhador = new AvisoData[ ids.length ];
 | |
| //		for( int n = 0; n < avisosTrabalhador.length; n++ )
 | |
| //		{
 | |
| //			avisosTrabalhador[ n ] = (AvisoData) JDO.load( AvisoData.class, ids[ n ] );
 | |
| //		}
 | |
| //System.out.println( "trabalhador " + avisosTrabalhador.length );
 | |
| 			avisosEmpresa = provider.getAvisosEmpresaByDate( new Date() );
 | |
| 			avisosEstabelecimento = provider.getAvisosEstabelecimentoByDate( new Date() );
 | |
| 			avisosTrabalhador = provider.getAvisosTrabalhadorByDate( new Date() );
 | |
| 		}
 | |
| 		catch( Exception ex )
 | |
| 		{
 | |
| 			ex.printStackTrace();
 | |
| 		}
 | |
| 		setupComponents();
 | |
| 		setVisible( true );
 | |
| 		repaint();
 | |
| 	}
 | |
| 	
 | |
| 	private JLabel criarDescricao( Object aviso[] )
 | |
| 	{
 | |
| 		Date dataEvento = ( Date )aviso[ 1 ];
 | |
| 		
 | |
| 		String descricao = (String)aviso[ 2 ];
 | |
| 		Calendar cal = Calendar.getInstance();
 | |
| 		cal.setTime( dataEvento );
 | |
| 		cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 );
 | |
| 		cal.set( Calendar.MILLISECOND, 0 );
 | |
| 		dataEvento = cal.getTime();
 | |
| 		
 | |
| 		cal = Calendar.getInstance();
 | |
| 		cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 );
 | |
| 		cal.set( Calendar.MILLISECOND, 0 );
 | |
| 		Date hoje = cal.getTime();
 | |
| 		
 | |
| 		if( !hoje.after( dataEvento ) && !hoje.before( dataEvento ) )
 | |
| 		{
 | |
| 			descricao += " hoje";
 | |
| 		}
 | |
| 		else
 | |
| 		{
 | |
| 			descricao += " no dia " + DATE_FORMAT.format( dataEvento );
 | |
| 		}
 | |
| 		JLabel descricaoLabel = new JLabel( descricao );
 | |
| 		if( hoje.after( dataEvento ) )
 | |
| 		{
 | |
| 			descricaoLabel.setForeground( Color.red );
 | |
| 		}
 | |
| 		else if( hoje.equals( dataEvento ) )
 | |
| 		{
 | |
| 			descricaoLabel.setForeground( Color.green.darker() );
 | |
| 		}
 | |
| 		return descricaoLabel;
 | |
| 	}
 | |
| 	
 | |
| //	private JLabel criarDescricao( AvisoData aviso )
 | |
| //	{
 | |
| //		Date dataEvento = ( Date )aviso.get( AvisoData.DATA_EVENTO );
 | |
| //		
 | |
| //		String descricao = (String)aviso.get( AvisoData.DESCRICAO );
 | |
| //		String descricao2 = (String)aviso.get( AvisoData.DESCRICAO );
 | |
| //		Calendar cal = Calendar.getInstance();
 | |
| //		cal.setTime( dataEvento );
 | |
| //		cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 );
 | |
| //		cal.set( Calendar.MILLISECOND, 0 );
 | |
| //		dataEvento = cal.getTime();
 | |
| //		
 | |
| //		cal = Calendar.getInstance();
 | |
| //		cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 );
 | |
| //		cal.set( Calendar.MILLISECOND, 0 );
 | |
| //		Date hoje = cal.getTime();
 | |
| //		
 | |
| //		if( !hoje.after( dataEvento ) && !hoje.before( dataEvento ) )
 | |
| //		{
 | |
| //			descricao += " hoje";
 | |
| //		}
 | |
| //		else
 | |
| //		{
 | |
| //			descricao += " no dia " + DATE_FORMAT.format( dataEvento );
 | |
| //		}
 | |
| //		JLabel descricaoLabel = new JLabel( descricao );
 | |
| //		if( hoje.after( dataEvento ) )
 | |
| //		{
 | |
| //			descricaoLabel.setForeground( Color.red );
 | |
| //		}
 | |
| //		else if( hoje.equals( dataEvento ) )
 | |
| //		{
 | |
| //			descricaoLabel.setForeground( Color.green.darker() );
 | |
| //		}
 | |
| //		return descricaoLabel;
 | |
| //	}
 | |
| 	
 | |
| 	public void actionPerformed( ActionEvent e )
 | |
| 	{
 | |
| 		if( JDO == null )
 | |
| 		{
 | |
| 			JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER );
 | |
| 		}
 | |
| 		Object source = e.getSource();
 | |
| 		if( source instanceof JButton )
 | |
| 		{
 | |
| //			AvisoData aviso = (AvisoData) buttonHash.get( source );
 | |
| 			try
 | |
| 			{
 | |
| 				( (JButton) source ).setEnabled( false );
 | |
| 				Integer id = (Integer)buttonHash.get( source );
 | |
| 				if( id == null )
 | |
| 				{
 | |
| 					return;
 | |
| 				}
 | |
| 				buttonHash.remove( source );
 | |
| 				AvisoData aviso = (AvisoData) JDO.load( AvisoData.class, id );
 | |
| 				if( aviso == null )
 | |
| 				{
 | |
| 					JOptionPane.showMessageDialog( null, "Este aviso j\u00e1 foi tratado.", "J\u00e1 tratado",
 | |
| 						JOptionPane.WARNING_MESSAGE );
 | |
| 					return;
 | |
| 				}
 | |
| 				Hashtable dataHash = aviso.getHashData();
 | |
| 				Date dataEvento = (Date)dataHash.get( AvisoData.DATA_EVENTO );
 | |
| 				Calendar cal = Calendar.getInstance();
 | |
| 				cal.setTime( dataEvento );
 | |
| 				cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 );
 | |
| 				cal.set( Calendar.MILLISECOND, 0 );
 | |
| 				dataEvento = cal.getTime();
 | |
| 
 | |
| 				cal = Calendar.getInstance();
 | |
| 				cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 10, 0, 0 );
 | |
| 				cal.set( Calendar.MILLISECOND, 0 );
 | |
| 				Date hoje = cal.getTime();
 | |
| 				if( hoje.before( dataEvento ) )
 | |
| 				{
 | |
| 					AvisoData novoAviso = new AvisoData();
 | |
| 					novoAviso.setHashData( dataHash );
 | |
| 					novoAviso.set( AvisoData.DATA_AVISO, dataEvento );
 | |
| 					novoAviso.save();
 | |
| 				}
 | |
| 				
 | |
| 				Integer tipo = (Integer) aviso.get( AvisoData.TIPO );
 | |
| 				TrabalhadorData trabalhador;
 | |
| 				EstabelecimentoData estabelecimento;
 | |
| 				EmpresaData empresa;
 | |
| 				
 | |
| 				switch( tipo.intValue() )
 | |
| 				{
 | |
| 					case AvisoConstants.TIPO_TRABALHADOR:
 | |
| 						trabalhador = (TrabalhadorData) aviso.get( AvisoData.TRABALHADOR );
 | |
| 						estabelecimento = (EstabelecimentoData) trabalhador.get( TrabalhadorData.ESTABELECIMENTO );
 | |
| 						empresa = (EmpresaData) estabelecimento.get( EstabelecimentoData.EMPRESA );
 | |
| 						aviso.delete();
 | |
| 						tracker.getMedicinaWindow().setVisible( true );
 | |
| 						tracker.getMedicinaWindow().setEmpresaAndEstabelecimentoAndTrabalhador( (Integer) empresa.get( EmpresaData.ID ),
 | |
| 																( Integer ) estabelecimento.get( EstabelecimentoData.ID ),
 | |
| 																( Integer ) trabalhador.get( TrabalhadorData.ID ) );
 | |
| 						break;
 | |
| 						
 | |
| 					case AvisoConstants.TIPO_ESTABELECIMENTO:
 | |
| 						estabelecimento = (EstabelecimentoData) aviso.get( AvisoData.ESTABELECIMENTO );
 | |
| 						empresa = (EmpresaData) estabelecimento.get( EstabelecimentoData.EMPRESA );
 | |
| 						aviso.delete();
 | |
| 						tracker.getHigieneWindow().setVisible( true );
 | |
| 						tracker.getHigieneWindow().setEmpresaAndEstabelecimento( (Integer) empresa.get( EmpresaData.ID ),
 | |
| 																( Integer ) estabelecimento.get( EstabelecimentoData.ID ) );
 | |
| 						break;
 | |
| 						
 | |
| 					case AvisoConstants.TIPO_EMPRESA:
 | |
| 						empresa = (EmpresaData) aviso.get( AvisoData.EMPRESA );
 | |
| 						aviso.delete();
 | |
| 						ClientesWindow clientesWindow = tracker.getClientesWindow();
 | |
| 						clientesWindow.setVisible( true );
 | |
| 						clientesWindow.setJDOObject( empresa );
 | |
| 						break;
 | |
| 				}
 | |
| System.out.println( "delete aviso" );
 | |
| //				aviso.set( AvisoData.TRABALHADOR, null );
 | |
| //				aviso.set( AvisoData.ESTABELECIMENTO, null );
 | |
| //				aviso.set( AvisoData.EMPRESA, null );
 | |
| 			}
 | |
| 			catch( Exception ex )
 | |
| 			{
 | |
| 				DialogException.showExceptionMessage( ex, "Erro a limpar o aviso", true );
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	public void clear()
 | |
| 	{
 | |
| 	}
 | |
| 	
 | |
| 	public void fill(Object value)
 | |
| 	{
 | |
| 	}
 | |
| 	
 | |
| 	public Object save()
 | |
| 	{
 | |
| 		return null;
 | |
| 	}
 | |
| 	
 | |
| 	public void setEnabled( boolean enable )
 | |
| 	{
 | |
| 		Set buttonSet = buttonHash.keySet();
 | |
| 		JButton buttons[] = (JButton[]) buttonSet.toArray( new JButton[0] );
 | |
| 		for( int n = 0;n < buttons.length; n++ )
 | |
| 		{
 | |
| 			buttons[ n ].setEnabled( enable );
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	public void setEnabled( boolean enable, int type )
 | |
| 	{
 | |
| 		Set buttonSet = buttonHash.keySet();
 | |
| 		JButton buttons[] = (JButton[]) buttonSet.toArray( new JButton[0] );
 | |
| 		for( int n = 0;n < buttons.length; n++ )
 | |
| 		{
 | |
| 			Integer buttonType = ( Integer ) buttonTypeHash.get( buttons[ n ] );
 | |
| 			if( buttonType.intValue() == type )
 | |
| 			{
 | |
| 				buttons[ n ].setEnabled( enable );
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	public void setTracker( SIPRPTracker tracker )
 | |
| 	{
 | |
| 		this.tracker = tracker;
 | |
| 	}
 | |
| }
 |