From fc9ec96215f082df0fd213281bdc2fcd34204ad9 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Tue, 15 May 2007 14:56:47 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@381 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../medicina/processo/ProcessoController.java | 5 +- .../medicina/processo/ProcessoPanel.java | 57 ++++++---- .../estrutura/EstruturaProcessoPanel.java | 107 ++++++++++++------ 3 files changed, 106 insertions(+), 63 deletions(-) diff --git a/trunk/siprp/medicina/processo/ProcessoController.java b/trunk/siprp/medicina/processo/ProcessoController.java index 3f31f854..b37bb0d9 100644 --- a/trunk/siprp/medicina/processo/ProcessoController.java +++ b/trunk/siprp/medicina/processo/ProcessoController.java @@ -1,4 +1,4 @@ -/* + /* * ProcessoController.java * * Created on 25 de Abril de 2007, 15:10 @@ -49,6 +49,7 @@ public class ProcessoController this.detalhesProcessoPanel = detalhesProcessoPanel; processoUpperPanel.addListSelectionListener( this ); estruturaProcessoPanel.addProcessoListener( this ); + processoPanel.addProcessoListener( this ); provider = ProcessoDataProvider.getProvider(); JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); @@ -239,9 +240,11 @@ public class ProcessoController try { idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO ); + estruturaProcessoPanel.actualizarProcessoEscolhido( idProcesso ); } catch( Exception ex ) { + DialogException.showExceptionMessage( ex, "Erro a actualizar dados", true ); } } diff --git a/trunk/siprp/medicina/processo/ProcessoPanel.java b/trunk/siprp/medicina/processo/ProcessoPanel.java index 543fca50..2c012a3a 100644 --- a/trunk/siprp/medicina/processo/ProcessoPanel.java +++ b/trunk/siprp/medicina/processo/ProcessoPanel.java @@ -19,10 +19,12 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DateFormat; import java.util.Date; +import java.util.HashMap; import java.util.Locale; import java.util.Vector; import javax.swing.*; import siprp.medicina.MedicinaConstants; +import siprp.medicina.MedicinaDataProvider; import siprp.medicina.processo.data.TrabalhadoresProcessoData; /** @@ -65,7 +67,7 @@ public class ProcessoPanel extends JPanel this.owner = owner; provider = ProcessoDataProvider.getProvider(); setupComponents(); - enableButtons( false ); + enableButtons(); } @@ -180,6 +182,13 @@ public class ProcessoPanel extends JPanel if( gravarProcesso() ) { reload(); + HashMap ids = new HashMap(); + ids.put( ProcessoEvent.TIPO_PROCESSO, ( Integer ) processo.get( TrabalhadoresProcessoData.ID ) ); + ProcessoEvent event = new ProcessoEvent( this, ProcessoEvent.ACCAO_ESCOLHER_MOTIVO, ids ); + for( int n = 0; n < PROCESSO_LISTENERS.size(); n++ ) + { + PROCESSO_LISTENERS.get( n ).processoStateChanged( event ); + } } } } @@ -209,13 +218,20 @@ public class ProcessoPanel extends JPanel motivoButton.setText( "Motivo" ); } - protected void enableButtons( boolean enable ) + protected void enableButtons() { - novoECDButton.setEnabled( enable ); - novaConsultaButton.setEnabled( enable ); - emitirFAButton.setEnabled( enable ); - fecharButton.setEnabled( enable ); - motivoButton.setEnabled( enable ); + String estado = null; + Integer motivo = null; + if( processo != null ) + { + estado = ( String ) processo.get( TrabalhadoresProcessoData.ESTADO ); + motivo = ( Integer ) processo.get( TrabalhadoresProcessoData.MOTIVO ); + } + novoECDButton.setEnabled( processo != null && motivo != null ); + novaConsultaButton.setEnabled( processo != null && motivo != null ); + emitirFAButton.setEnabled( processo != null && motivo != null ); + fecharButton.setEnabled( processo != null && motivo != null && PROCESSO_ABERTO_CODE.equals( estado ) ); + motivoButton.setEnabled( processo != null ); } public void addProcessoListener( ProcessoListener listener ) @@ -223,6 +239,11 @@ public class ProcessoPanel extends JPanel PROCESSO_LISTENERS.add( listener ); } + public void removeProcessoListener( ProcessoListener listener ) + { + PROCESSO_LISTENERS.remove( listener ); + } + public Icon getIcon( String path ) { try @@ -274,10 +295,9 @@ public class ProcessoPanel extends JPanel public void reload() { - enableButtons( processo != null ); + enableButtons(); if( processo != null ) { - enableButtons( true ); String estado = null; Date dataInicio = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_INICIO ); if( dataInicio != null ) @@ -303,23 +323,10 @@ public class ProcessoPanel extends JPanel String motivoStr = "Motivo"; if( motivo != null ) { - switch( motivo.intValue() ) + motivoStr = MedicinaDataProvider.MOTIVOS_BY_ID.get( motivo ); + if( subMotivo != null ) { - 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; + motivoStr += " > " + MedicinaDataProvider.SUB_MOTIVOS_BY_ID.get( subMotivo ); } } motivoButton.setText( motivoStr ); diff --git a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java index 20bfbd9f..3df1945c 100644 --- a/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java +++ b/trunk/siprp/medicina/processo/estrutura/EstruturaProcessoPanel.java @@ -10,7 +10,6 @@ package siprp.medicina.processo.estrutura; import com.evolute.utils.data.IDObject; -import com.evolute.utils.data.MappableObject; import com.evolute.utils.ui.DialogException; import java.awt.*; import java.text.DateFormat; @@ -24,6 +23,7 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; +import siprp.medicina.MedicinaDataProvider; import siprp.medicina.processo.*; import siprp.medicina.processo.data.TrabalhadoresProcessoData; @@ -63,7 +63,7 @@ public class EstruturaProcessoPanel extends JPanel mainScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED ); mainScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); // rootNode = new DefaultMutableTreeNode( new MappableObject( new Integer( 12 ), "Frederico Palma" ) ); - rootNode = new TrabalhadorMutableTreeNode( new Integer( 12 ), "Frederico Palma" ); + rootNode = new TrabalhadorMutableTreeNode( new Integer( -1 ), "" ); mainTree = new JTree( rootNode ); mainTree.addTreeSelectionListener( this ); mainTree.setCellRenderer( new EstruturaProcessoRenderer() ); @@ -87,7 +87,7 @@ public class EstruturaProcessoPanel extends JPanel rootNode.setDescricao( trabalhador.toString() ); DefaultMutableTreeNode nodes[] = loadProcessos( trabalhador.getID() ); - rootNode.add( new ProcessoMutableTreeNode( new Integer( -1 ), "Novo Processo..." ) ); + rootNode.add( criarProcessoVazio() ); for( int n = 0; n < nodes.length; n++ ) { rootNode.add( nodes[ n ] ); @@ -107,19 +107,7 @@ public class EstruturaProcessoPanel extends JPanel DefaultMutableTreeNode nodes[] = new DefaultMutableTreeNode[ ids.length ]; for( int n = 0; n < ids.length; n++ ) { - TrabalhadoresProcessoData processo = provider.getProcessoByID( ids[ n ] ); - Date dataInicio = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_INICIO ); - Date dataFim = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_FIM ); - String codigoEstado = ( String ) processo.get( TrabalhadoresProcessoData.ESTADO ); - String estado = provider.getDescricaoEstadoProcessoByCodigo( codigoEstado ); - String desc = D_F.format( dataInicio ); - if( dataFim != null ) - { - desc += " - " + D_F.format( dataFim ); - } - desc += ": " + estado; - nodes[ n ] = new ProcessoMutableTreeNode( ids[ n ], desc ); - PROCESSOS_POR_ID.put( ids[ n ], processo ); + nodes[ n ] = loadProcesso( ids[ n ], null ); } //System.out.println( "nl: " + nodes.length ); return nodes; @@ -131,6 +119,30 @@ public class EstruturaProcessoPanel extends JPanel } } + protected ProcessoMutableTreeNode loadProcesso( Integer id, ProcessoMutableTreeNode node ) + throws Exception + { + TrabalhadoresProcessoData processo = provider.getProcessoByID( id ); + Date dataInicio = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_INICIO ); + Date dataFim = ( Date ) processo.get( TrabalhadoresProcessoData.DATA_FIM ); + String codigoEstado = ( String ) processo.get( TrabalhadoresProcessoData.ESTADO ); + String estado = provider.getDescricaoEstadoProcessoByCodigo( codigoEstado ); + String desc = D_F.format( dataInicio ); + Integer motivo = ( Integer ) processo.get( TrabalhadoresProcessoData.MOTIVO ); + desc += ": " + MedicinaDataProvider.MOTIVOS_BY_ID.get( motivo ) + " : " + estado; + PROCESSOS_POR_ID.put( id, processo ); + if( node == null ) + { + return new ProcessoMutableTreeNode( id, desc ); + } + else + { + node.setID( id ); + node.setDescricao( desc ); + return node; + } + } + public void valueChanged( TreeSelectionEvent e ) { Object components[] = e.getPath().getPath(); @@ -204,27 +216,27 @@ public class EstruturaProcessoPanel extends JPanel PROCESSO_LISTENERS.get( n ).processoStateChanged( event ); } } - - public TrabalhadoresProcessoData getProcessoEscolhido() - { - TreePath path = mainTree.getSelectionPath(); - TrabalhadoresProcessoData processo = null; - if( path != null ) - { - IDObject escolhido = ( IDObject )( ( DefaultMutableTreeNode ) path.getLastPathComponent() ).getUserObject(); - if( escolhido != null ) - { - processo = PROCESSOS_POR_ID.get( escolhido.getID() ); - if( processo == null ) - { - processo = new TrabalhadoresProcessoData(); - PROCESSOS_POR_ID.put( escolhido.getID(), processo ); - } - } - } - - return processo; - } +// +// public TrabalhadoresProcessoData getProcessoEscolhido() +// { +// TreePath path = mainTree.getSelectionPath(); +// TrabalhadoresProcessoData processo = null; +// if( path != null ) +// { +// EstruturaProcessoMutableTreeNode escolhido = ( EstruturaProcessoMutableTreeNode ) path.getLastPathComponent(); +// if( escolhido != null ) +// { +// processo = PROCESSOS_POR_ID.get( escolhido.getID() ); +// if( processo == null ) +// { +// processo = new TrabalhadoresProcessoData(); +// PROCESSOS_POR_ID.put( escolhido.getID(), processo ); +// } +// } +// } +// +// return processo; +// } public void addProcessoListener( ProcessoListener listener ) { @@ -241,6 +253,27 @@ public class EstruturaProcessoPanel extends JPanel return trabalhador; } + public void actualizarProcessoEscolhido( Integer id ) + throws Exception + { + TreePath path = mainTree.getSelectionPath(); + ProcessoMutableTreeNode processoNode = ( ProcessoMutableTreeNode ) path.getPathComponent( 1 ); + boolean vazio = processoNode.getID().intValue() == -1; + loadProcesso( id, processoNode ); + ( ( DefaultTreeModel ) mainTree.getModel() ).nodeChanged( processoNode ) ; + if( vazio ) + { + ProcessoMutableTreeNode novo = criarProcessoVazio(); + rootNode.insert( novo, 0 ); + ( ( DefaultTreeModel ) mainTree.getModel() ).nodesWereInserted( rootNode, new int[]{ 0 } ) ; + } + } + + public ProcessoMutableTreeNode criarProcessoVazio() + { + return new ProcessoMutableTreeNode( new Integer( -1 ), "Novo Processo..." ); + } + public void reload() { }