diff --git a/trunk/siprp/medicina/processo/ProcessoPanel.java b/trunk/siprp/medicina/processo/ProcessoPanel.java index 1a70904b..03acecaa 100644 --- a/trunk/siprp/medicina/processo/ProcessoPanel.java +++ b/trunk/siprp/medicina/processo/ProcessoPanel.java @@ -9,7 +9,9 @@ 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.*; @@ -20,17 +22,14 @@ import java.util.Date; import java.util.Locale; import java.util.Vector; import javax.swing.*; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; import siprp.medicina.processo.data.MarcacoesProcessoData; -import siprp.medicina.processo.estrutura.EstruturaProcessoPanel; /** * * @author fpalma */ public class ProcessoPanel extends JPanel - implements ActionListener, TreeSelectionListener + implements ActionListener, ControllableComponent { 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"; @@ -48,15 +47,16 @@ public class ProcessoPanel extends JPanel private JButton novaConsultaButton; private JButton emitirFAButton; private JButton fecharButton; - - private final EstruturaProcessoPanel estruturaPanel; - + private final Vector PROCESSO_LISTENERS = new Vector(); + private ProcessoDataProvider provider; + /** Creates a new instance of ProcessoPanel */ - public ProcessoPanel( EstruturaProcessoPanel estruturaPanel ) + public ProcessoPanel() + throws Exception { - this.estruturaPanel = estruturaPanel; + provider = ProcessoDataProvider.getProvider(); setupComponents(); } @@ -153,13 +153,7 @@ public class ProcessoPanel extends JPanel protected void fecharProcesso() { } - - public void valueChanged(TreeSelectionEvent e) - { - clear(); - mudarProcesso(); - } - + public void clear() { estadoText.setText( "" ); @@ -169,73 +163,82 @@ public class ProcessoPanel extends JPanel ocasionalMotivoButton.setText( " " ); } - protected void disableButtons() + protected void enableButtons( boolean enable ) { - novoECDButton.setEnabled( false ); - novaConsultaButton.setEnabled( false ); - emitirFAButton.setEnabled( false ); - fecharButton.setEnabled( false ); - motivoButton.setEnabled( false ); - ocasionalMotivoButton.setEnabled( false ); + novoECDButton.setEnabled( enable ); + novaConsultaButton.setEnabled( enable ); + emitirFAButton.setEnabled( enable ); + fecharButton.setEnabled( enable ); + motivoButton.setEnabled( enable ); + ocasionalMotivoButton.setEnabled( enable ); } - - protected void enableButtons() + + public void addProcessoListener( ProcessoListener listener ) { - novoECDButton.setEnabled( true ); - novaConsultaButton.setEnabled( true ); - emitirFAButton.setEnabled( true ); - fecharButton.setEnabled( true ); - motivoButton.setEnabled( true ); - ocasionalMotivoButton.setEnabled( true ); + PROCESSO_LISTENERS.add( listener ); } - protected void mudarProcesso() + public Icon getIcon( String path ) { - MarcacoesProcessoData processo = estruturaPanel.getProcessoEscolhido(); - if( processo == null ) + try { - disableButtons(); + return ImageIconLoader.loadImageIcon( getClass(), path ); } - else + catch( Exception ex ) { - enableButtons(); - Date dataInicio = ( Date ) processo.get( MarcacoesProcessoData.DATA_INICIO ); - if( dataInicio != null ) - { - inicioText.setText( D_F.format( dataInicio ) ); - } - Date dataFim = ( Date ) processo.get( MarcacoesProcessoData.DATA_FIM ); - if( dataFim != null ) - { - fimText.setText( D_F.format( dataFim ) ); - } - String estado = ( String ) processo.get( MarcacoesProcessoData.ESTADO ); - if( estado == null ) - { - estadoText.setText( ProcessoDataProvider.PROCESSO_POR_ABRIR_DESCRIPTION ); - } - else - { - estadoText.setText( ProcessoDataProvider.ESTADO_PROCESSO_BY_CODE.get( estado ) ); - } + ex.printStackTrace(); + return null; } } - public void addProcessoListener( ProcessoListener listener ) + public Object save() { - PROCESSO_LISTENERS.add( listener ); + return null; } - public Icon getIcon( String path ) + public void enableComponents( boolean enable ) { - try + + } + + public void fill( Object value ) + { + clear(); + + if( value == null ) { - return ImageIconLoader.loadImageIcon( getClass(), path ); + enableButtons( false ); } - catch( Exception ex ) + else { - ex.printStackTrace(); - return null; + try + { + MarcacoesProcessoData processo = provider.getProcessoByID( ( Integer ) value ); + enableButtons( false ); + Date dataInicio = ( Date ) processo.get( MarcacoesProcessoData.DATA_INICIO ); + if( dataInicio != null ) + { + inicioText.setText( D_F.format( dataInicio ) ); + } + Date dataFim = ( Date ) processo.get( MarcacoesProcessoData.DATA_FIM ); + if( dataFim != null ) + { + fimText.setText( D_F.format( dataFim ) ); + } + String estado = ( String ) processo.get( MarcacoesProcessoData.ESTADO ); + if( estado == null ) + { + estadoText.setText( ProcessoDataProvider.PROCESSO_POR_ABRIR_DESCRIPTION ); + } + else + { + estadoText.setText( ProcessoDataProvider.ESTADO_PROCESSO_BY_CODE.get( estado ) ); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados do processo", true ); + } } } }