/* * ConsultaPanel.java * * Created on March 22, 2007, 10:58 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package siprp.medicina.processo.detalhes; import com.evolute.utils.Singleton; import com.evolute.utils.data.IDObject; import com.evolute.utils.jdo.JDOProvider; import com.evolute.utils.ui.DialogException; import com.evolute.utils.ui.calendar.JCalendarPanel; import info.clearthought.layout.TableLayout; import info.clearthought.layout.TableLayoutConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Date; import java.util.Vector; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import siprp.medicina.MedicinaConstants; import siprp.medicina.processo.ProcessoDataProvider; import siprp.medicina.processo.ProcessoListener; import siprp.medicina.processo.data.TrabalhadoresConsultasData; /** * * @author fpalma */ public class ConsultaPanel extends JPanel implements ActionListener, MedicinaConstants, ChangeListener { protected JFrame owner; protected JCalendarPanel dataConsultaPanel; protected JButton estadoButton; protected JButton emailButton; protected JButton observacoesButton; protected ObservacoesDialog observacoesDialog; protected final Vector PROCESSO_LISTENERS = new Vector(); protected JDOProvider JDO; protected ProcessoDataProvider provider; protected TrabalhadoresConsultasData consulta; protected Integer trabalhadorID; /** Creates a new instance of ConsultaPanel */ public ConsultaPanel( JFrame owner ) throws Exception { this.owner = owner; JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); provider = ProcessoDataProvider.getProvider(); setupComponents(); } private void setupComponents() { JLabel dataLabel = new JLabel( "Data" ); dataConsultaPanel = new JCalendarPanel( null ); dataConsultaPanel.addChangeListener( this ); estadoButton = new JButton( " " ); estadoButton.addActionListener( this ); emailButton = new JButton( "Email" ); emailButton.addActionListener( this ); observacoesButton = new JButton( "Coment\u00e1rio" ); observacoesButton.addActionListener( this ); double cols[] = new double[]{ TableLayout.MINIMUM, TableLayout.FILL }; double rows[] = new double[]{ TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM }; TableLayout tableLayout = new TableLayout( cols, rows ); tableLayout.setVGap( 5 ); setLayout( tableLayout ); add( dataLabel, new TableLayoutConstraints( 0, 0 ) ); add( dataConsultaPanel, new TableLayoutConstraints( 1, 0 ) ); add( estadoButton, new TableLayoutConstraints( 0, 1, 1, 1 ) ); add( emailButton, new TableLayoutConstraints( 0, 2, 1, 2 ) ); add( observacoesButton, new TableLayoutConstraints( 0, 3, 1, 3 ) ); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if( source.equals( observacoesButton ) ) { editarObservacoes(); } else if( source.equals( emailButton ) ) { enviarEmail(); } else if( source.equals( estadoButton ) ) { mudarEstado(); } } public void stateChanged(ChangeEvent e) { Object source = e.getSource(); if( source.equals( dataConsultaPanel ) ) { } } protected void editarObservacoes() { if( observacoesDialog == null ) { observacoesDialog = new ObservacoesDialog( owner ); } String texto = ""; try { Integer dataID = provider.getLastConsultaDataIDForConsulta( ( Integer ) consulta.get( TrabalhadoresConsultasData.ID ) ); IDObject observacoes = provider.getObservacoesConsultaData( dataID ); if( observacoes != null ) { texto = observacoes.toString(); } texto = observacoesDialog.editarObservacao( texto ); if( texto != null ) { provider.saveObservacoesConsultaData( dataID, texto ); } } catch( Exception ex ) { DialogException.showExceptionMessage( ex, "Erro a carregar dados", true ); return; } } protected void enviarEmail() { } protected void mudarEstado() { } public void addProcessoListener( ProcessoListener listener ) { PROCESSO_LISTENERS.add( listener ); } public void removeProcessoListener( ProcessoListener listener ) { PROCESSO_LISTENERS.remove( listener ); } public void clear() { dataConsultaPanel.setDate( null ); estadoButton.setText( " " ); } public void fill( Object value ) { clear(); if( value != null ) { try { consulta = ( TrabalhadoresConsultasData ) JDO.load( TrabalhadoresConsultasData.class, ( Integer ) value ); Date data = ( Date ) consulta.get( TrabalhadoresConsultasData.DATA ); Integer estado = ( Integer ) consulta.get( TrabalhadoresConsultasData.ESTADO ); dataConsultaPanel.setDate( data ); if( estado != null ) { estadoButton.setText( ESTADOS_CONSULTA_STR[ estado.intValue() ] ); } else { estadoButton.setText( " " ); } } catch( Exception ex ) { DialogException.showExceptionMessage( ex, "Erro a carregar dados da consulta", true ); } } enableButtons(); } protected void enableButtons() { if( consulta != null ) { Integer estado = ( Integer ) consulta.get( TrabalhadoresConsultasData.ESTADO ); dataConsultaPanel.setEnabled( estado == null || estado.intValue() == ESTADO_POR_REALIZAR ); estadoButton.setEnabled( consulta.get( TrabalhadoresConsultasData.DATA ) != null ); emailButton.setEnabled( consulta.get( TrabalhadoresConsultasData.DATA ) != null ); observacoesButton.setEnabled( consulta.get( TrabalhadoresConsultasData.DATA ) != null ); } else { dataConsultaPanel.setEnabled( true ); estadoButton.setEnabled( false ); emailButton.setEnabled( false ); observacoesButton.setEnabled( false ); } } public void setTrabalhadorID( Integer trabalhadorID ) { this.trabalhadorID = trabalhadorID; } }