diff --git a/trunk/siprp/medicina/MedicinaConstants.java b/trunk/siprp/medicina/MedicinaConstants.java index 3ec19d87..f06d4005 100644 --- a/trunk/siprp/medicina/MedicinaConstants.java +++ b/trunk/siprp/medicina/MedicinaConstants.java @@ -15,18 +15,40 @@ package siprp.medicina; */ public interface MedicinaConstants { - public static final int TIPO_ECDS = 0; - public static final int TIPO_CONSULTA = 1; - public static final int TIPO_FICHA_APTIDAO = 2; - public static final int MOTIVO_ADMISSAO = 1; public static final Integer MOTIVO_ADMISSAO_INTEGER = new Integer( MOTIVO_ADMISSAO ); + public static final String MOTIVO_ADMISSAO_STR = "Admiss\u00e3o"; public static final int MOTIVO_PERIODICO = 2; public static final Integer MOTIVO_PERIODICO_INTEGER = new Integer( MOTIVO_PERIODICO ); + public static final String MOTIVO_PERIODICO_STR = "Peri\u00f3dico"; public static final int MOTIVO_OCASIONAL = 3; public static final Integer MOTIVO_OCASIONAL_INTEGER = new Integer( MOTIVO_OCASIONAL ); + public static final String MOTIVO_OCASIONAL_STR = "Ocasional"; public static final int MOTIVO_PERIODICO_INICIAL = 5; public static final Integer MOTIVO_PERIODICO_INICIAL_INTEGER = new Integer( MOTIVO_PERIODICO_INICIAL ); + public static final String MOTIVO_PERIODICO_INICIAL_STR = "Peri\u00f3dico inicial"; + + public static final int SUB_MOTIVO_APOS_DOENCA = 1; + public static final Integer SUB_MOTIVO_APOS_DOENCA_INTEGER = new Integer( SUB_MOTIVO_APOS_DOENCA ); + public static final String SUB_MOTIVO_APOS_DOENCA_STR = "Ap\u00f3s doen\u00e7a"; + public static final int SUB_MOTIVO_APOS_ACIDENTE = 2; + public static final Integer SUB_MOTIVO_APOS_ACIDENTE_INTEGER = new Integer( SUB_MOTIVO_APOS_ACIDENTE ); + public static final String SUB_MOTIVO_APOS_ACIDENTE_STR = "Ap\u00f3s acidente"; + public static final int SUB_MOTIVO_PEDIDO_TRABALHADOR = 3; + public static final Integer SUB_MOTIVO_PEDIDO_TRABALHADOR_INTEGER = new Integer( SUB_MOTIVO_PEDIDO_TRABALHADOR ); + public static final String SUB_MOTIVO_PEDIDO_TRABALHADOR_STR = "A pedido do trabalhador"; + public static final int SUB_MOTIVO_PEDIDO_SERVICO = 4; + public static final Integer SUB_MOTIVO_PEDIDO_SERVICO_INTEGER = new Integer( SUB_MOTIVO_PEDIDO_SERVICO ); + public static final String SUB_MOTIVO_PEDIDO_SERVICO_STR = "A pedido do servi\u00e7o"; + public static final int SUB_MOTIVO_MUDANCA_FUNCAO = 5; + public static final Integer SUB_MOTIVO_MUDANCA_FUNCAO_INTEGER = new Integer( SUB_MOTIVO_MUDANCA_FUNCAO ); + public static final String SUB_MOTIVO_MUDANCA_FUNCAO_STR = "Por mudan\u00e7a de fun\u00e7\u00e3o"; + public static final int SUB_MOTIVO_ALTERACAO_CONDICOES = 6; + public static final Integer SUB_MOTIVO_ALTERACAO_CONDICOES_INTEGER = new Integer( SUB_MOTIVO_ALTERACAO_CONDICOES ); + public static final String SUB_MOTIVO_ALTERACAO_CONDICOES_STR = "Por altera\u00e7\u00e3o das condi\u00e7\u00f5es de trabalho"; + public static final int SUB_MOTIVO_OUTRO = 10; + public static final Integer SUB_MOTIVO_OUTRO_INTEGER = new Integer( SUB_MOTIVO_OUTRO ); + public static final String SUB_MOTIVO_OUTRO_STR = "Outro"; public static final int ESTADO_POR_REALIZAR = 0; public static final int ESTADO_PARCIALMENTE_REALIZADO = 1; diff --git a/trunk/siprp/medicina/processo/EscolherMotivoDialog.java b/trunk/siprp/medicina/processo/EscolherMotivoDialog.java index 7e5a92f6..1f9f83c5 100644 --- a/trunk/siprp/medicina/processo/EscolherMotivoDialog.java +++ b/trunk/siprp/medicina/processo/EscolherMotivoDialog.java @@ -18,24 +18,27 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; +import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.JToggleButton; import javax.swing.SwingUtilities; +import siprp.medicina.MedicinaConstants; /** * * @author Frederico */ public class EscolherMotivoDialog extends CustomJDialog - implements ActionListener + implements ActionListener, MedicinaConstants { protected IDObject MOTIVOS[] = new IDObject[]{ - new MappableObject( new Integer( 1 ), "Admiss\u00e3o" ), - new MappableObject( new Integer( 2 ), "Peri\u00f3dico" ), - new MappableObject( new Integer( 5 ), "Peri\u00f3dico inicial" ), - new MappableObject( new Integer( 3 ), "Ocasional" ) + new MappableObject( MOTIVO_ADMISSAO_INTEGER, MOTIVO_ADMISSAO_STR ), + new MappableObject( MOTIVO_PERIODICO_INTEGER, MOTIVO_PERIODICO_STR ), + new MappableObject( MOTIVO_PERIODICO_INICIAL_INTEGER, MOTIVO_PERIODICO_INICIAL_STR ), + new MappableObject( MOTIVO_OCASIONAL_INTEGER, MOTIVO_OCASIONAL_STR ) }; protected IDObject SUB_MOTIVOS[][] = @@ -43,23 +46,24 @@ public class EscolherMotivoDialog extends CustomJDialog {}, {}, {}, - { new MappableObject( new Integer( 1 ), "Ap\u00f3s doen\u00e7a" ), - new MappableObject( new Integer( 2 ), "Ap\u00f3s acidente" ), - new MappableObject( new Integer( 3 ), "A pedido do trabalhador" ), - new MappableObject( new Integer( 4 ), "A pedido do servi\u00e7o" ), - new MappableObject( new Integer( 5 ), "Por mudan\u00e7a de fun\u00e7\u00e3o" ), - new MappableObject( new Integer( 6 ), "Por altera\u00e7\u00e3o das condi\u00e7\u00f5es de trabalho" ), - new MappableObject( new Integer( 10 ), "Outro" ) + { new MappableObject( SUB_MOTIVO_APOS_DOENCA_INTEGER, SUB_MOTIVO_APOS_DOENCA_STR ), + new MappableObject( SUB_MOTIVO_APOS_ACIDENTE_INTEGER, SUB_MOTIVO_APOS_ACIDENTE_STR ), + new MappableObject( SUB_MOTIVO_PEDIDO_TRABALHADOR_INTEGER, SUB_MOTIVO_PEDIDO_TRABALHADOR_STR ), + new MappableObject( SUB_MOTIVO_PEDIDO_SERVICO_INTEGER, SUB_MOTIVO_PEDIDO_SERVICO_STR ), + new MappableObject( SUB_MOTIVO_MUDANCA_FUNCAO_INTEGER, SUB_MOTIVO_MUDANCA_FUNCAO_STR ), + new MappableObject( SUB_MOTIVO_ALTERACAO_CONDICOES_INTEGER, SUB_MOTIVO_ALTERACAO_CONDICOES_STR ), + new MappableObject( SUB_MOTIVO_OUTRO_INTEGER, SUB_MOTIVO_OUTRO_STR ) } }; - protected JButton motivoButtons[]; - protected HashMap subMotivoButtons; - protected HashMap motivoButtonIDs; + protected AbstractButton motivoButtons[]; + protected HashMap subMotivoButtons; + protected HashMap motivoButtonIDs; protected HashMap subMotivoButtonIDs; protected JPanel motivoPanel; protected JPanel subMotivoPanel; + protected Integer motivoTemp; protected Integer motivo; protected Integer subMotivo; @@ -83,13 +87,13 @@ public class EscolherMotivoDialog extends CustomJDialog { setTitle( "Escolher Motivo" ); setLayout( new FlowLayout( FlowLayout.LEFT ) ); - motivoButtons = new JButton[ MOTIVOS.length ]; - subMotivoButtons = new HashMap(); - motivoButtonIDs = new HashMap(); + motivoButtons = new JToggleButton[ MOTIVOS.length ]; + subMotivoButtons = new HashMap(); + motivoButtonIDs = new HashMap(); subMotivoButtonIDs = new HashMap(); for( int m = 0; m < MOTIVOS.length; m++ ) { - JButton motivoButton = new JButton( MOTIVOS[ m ].toString() ); + JToggleButton motivoButton = new JToggleButton( MOTIVOS[ m ].toString() ); motivoButton.addActionListener( this ); motivoButtonIDs.put( motivoButton, MOTIVOS[ m ].getID() ); motivoButton.setPreferredSize( new Dimension( 250, 20 ) ); @@ -129,13 +133,14 @@ public class EscolherMotivoDialog extends CustomJDialog public void actionPerformed(ActionEvent e) { - JButton source = ( JButton ) e.getSource(); + AbstractButton source = ( AbstractButton ) e.getSource(); if( motivoButtonIDs.containsKey( source ) ) { - motivo = motivoButtonIDs.get( source ); + motivoTemp = motivoButtonIDs.get( source ); } else if( subMotivoButtonIDs.containsKey( source ) ) { + motivo = motivoTemp; subMotivo = subMotivoButtonIDs.get( source ); close(); } @@ -144,6 +149,7 @@ public class EscolherMotivoDialog extends CustomJDialog JButton subButtons[] = subMotivoButtons.get( source ); if( subButtons == null || subButtons.length == 0 ) { + motivo = motivoTemp; close(); } else @@ -170,4 +176,8 @@ public class EscolherMotivoDialog extends CustomJDialog } ); } + public Integer[] getMotivo() + { + return new Integer[]{ motivo, subMotivo }; + } } diff --git a/trunk/siprp/medicina/processo/ProcessoConstants.java b/trunk/siprp/medicina/processo/ProcessoConstants.java new file mode 100644 index 00000000..a915de30 --- /dev/null +++ b/trunk/siprp/medicina/processo/ProcessoConstants.java @@ -0,0 +1,30 @@ +/* + * ProcessoConstants.java + * + * Created on May 14, 2007, 10:08 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.medicina.processo; + +/** + * + * @author fpalma + */ +public interface ProcessoConstants +{ + public static final int TIPO_ECDS = 0; + public static final int TIPO_CONSULTA = 1; + public static final int TIPO_FICHA_APTIDAO = 2; + + public static final String PROCESSO_ABERTO_CODE = "a"; + public static final String PROCESSO_FECHADO_CODE = "f"; + public static final String PROCESSO_CANCELADO_CODE = "c"; + + public static final String PROCESSO_ABERTO_DESCRIPTION = "Aberto"; + public static final String PROCESSO_FECHADO_DESCRIPTION = "Fechado"; + public static final String PROCESSO_CANCELADO_DESCRIPTION = "Cancelado"; + public static final String PROCESSO_POR_ABRIR_DESCRIPTION = "Por Abrir"; +} diff --git a/trunk/siprp/medicina/processo/ProcessoController.java b/trunk/siprp/medicina/processo/ProcessoController.java index 9ec8be00..3f31f854 100644 --- a/trunk/siprp/medicina/processo/ProcessoController.java +++ b/trunk/siprp/medicina/processo/ProcessoController.java @@ -337,6 +337,7 @@ public class ProcessoController { Integer ids[] = ( Integer [] ) processoUpperPanel.save(); Integer trabalhadorID = ids[ 2 ]; + processoPanel.setTrabalhadorID( trabalhadorID ); if( trabalhadorID != null ) { TrabalhadorData trabalhador = ( TrabalhadorData ) JDO.load( TrabalhadorData.class, trabalhadorID ); diff --git a/trunk/siprp/medicina/processo/ProcessoDataProvider.java b/trunk/siprp/medicina/processo/ProcessoDataProvider.java index e2fde2f9..1a7d0bf9 100644 --- a/trunk/siprp/medicina/processo/ProcessoDataProvider.java +++ b/trunk/siprp/medicina/processo/ProcessoDataProvider.java @@ -33,17 +33,8 @@ import siprp.medicina.processo.data.TrabalhadoresProcessoData; * @author fpalma */ public class ProcessoDataProvider - implements MedicinaConstants + implements MedicinaConstants, ProcessoConstants { - public static final String PROCESSO_ABERTO_CODE = "a"; - public static final String PROCESSO_FECHADO_CODE = "f"; - public static final String PROCESSO_CANCELADO_CODE = "c"; - - public static final String PROCESSO_ABERTO_DESCRIPTION = "Aberto"; - public static final String PROCESSO_FECHADO_DESCRIPTION = "Fechado"; - public static final String PROCESSO_CANCELADO_DESCRIPTION = "Cancelado"; - public static final String PROCESSO_POR_ABRIR_DESCRIPTION = "Por Abrir"; - public static final HashMap ESTADO_PROCESSO_BY_CODE = new HashMap(); diff --git a/trunk/siprp/medicina/processo/ProcessoPanel.java b/trunk/siprp/medicina/processo/ProcessoPanel.java index 6a69ec8e..543fca50 100644 --- a/trunk/siprp/medicina/processo/ProcessoPanel.java +++ b/trunk/siprp/medicina/processo/ProcessoPanel.java @@ -22,6 +22,7 @@ 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; /** @@ -29,7 +30,8 @@ import siprp.medicina.processo.data.TrabalhadoresProcessoData; * @author fpalma */ public class ProcessoPanel extends JPanel - implements ActionListener, ControllableComponent + 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"; @@ -53,6 +55,9 @@ public class ProcessoPanel extends JPanel private ProcessoDataProvider provider; + private Integer trabalhadorID = null; + private TrabalhadoresProcessoData processo; + /** Creates a new instance of ProcessoPanel */ public ProcessoPanel( JFrame owner ) throws Exception @@ -60,6 +65,7 @@ public class ProcessoPanel extends JPanel this.owner = owner; provider = ProcessoDataProvider.getProvider(); setupComponents(); + enableButtons( false ); } @@ -143,9 +149,39 @@ public class ProcessoPanel extends JPanel } } + 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() { - new EscolherMotivoDialog( owner ).setVisible( true ); + 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() @@ -166,6 +202,7 @@ public class ProcessoPanel extends JPanel public void clear() { + processo = null; estadoText.setText( "" ); inicioText.setText( "" ); fimText.setText( "" ); @@ -212,39 +249,19 @@ public class ProcessoPanel extends JPanel public void fill( Object value ) { clear(); - - if( value == null ) + if( trabalhadorID == null ) { - enableButtons( false ); + return; } - else + if( value != null ) { try { - TrabalhadoresProcessoData processo = provider.getProcessoByID( ( Integer ) value ); - enableButtons( true ); - String estado = null; - if( processo != 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 + processo = provider.getProcessoByID( ( Integer ) value ); + if( processo == null ) { - estadoText.setText( ProcessoDataProvider.ESTADO_PROCESSO_BY_CODE.get( estado ) ); + processo = new TrabalhadoresProcessoData(); + processo.set( TrabalhadoresProcessoData.TRABALHADOR_ID, trabalhadorID ); } } catch( Exception ex ) @@ -252,5 +269,65 @@ public class ProcessoPanel extends JPanel 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; } } diff --git a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java index 5a0baa08..255047b4 100644 --- a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java +++ b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java @@ -22,6 +22,7 @@ import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import siprp.medicina.processo.*; import siprp.medicina.processo.data.TrabalhadoresProcessoData; @@ -96,7 +97,6 @@ public class EstruturaProcessoPanel extends JPanel { mainTree.expandRow( n ); } - repaint(); } @@ -122,6 +122,7 @@ public class EstruturaProcessoPanel extends JPanel nodes[ n ] = new ProcessoMutableTreeNode( ids[ n ], desc ); PROCESSOS_POR_ID.put( ids[ n ], processo ); } +//System.out.println( "nl: " + nodes.length ); return nodes; } catch( Exception ex ) @@ -247,10 +248,13 @@ public class EstruturaProcessoPanel extends JPanel public void clear() { + mainTree.clearSelection(); + mainTree.setRootVisible( true ); this.trabalhador = null; rootNode.removeAllChildren(); PROCESSOS_POR_ID.clear(); rootNode.setID( null ); rootNode.setDescricao( "" ); + ( ( DefaultTreeModel ) mainTree.getModel() ).nodeStructureChanged( rootNode ) ; } }