From 7737602509c19e816f068d1ec8e6bca496de5305 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 12 Apr 2004 18:05:20 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@31 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/FichaDataProvider.java | 12 +- trunk/siprp/ficha/EmpresaPanel.java | 6 +- .../ficha/FichaAptidaoEditorManager.java | 7 - trunk/siprp/ficha/FichaWindow.java | 132 ++++++++----- trunk/siprp/ficha/UpperPanel.java | 173 +++++++++++++++++- 5 files changed, 269 insertions(+), 61 deletions(-) diff --git a/trunk/siprp/FichaDataProvider.java b/trunk/siprp/FichaDataProvider.java index 7c79eae1..cd7b148c 100644 --- a/trunk/siprp/FichaDataProvider.java +++ b/trunk/siprp/FichaDataProvider.java @@ -86,7 +86,7 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { //medicos public static final String T_MEDICOS = "medicos"; - private static final String NUMERO_CEDULA = "numero_cedula"; + public static final String NUMERO_CEDULA = "numero_cedula"; public static final DBTable MEDICOS = new DBTable( T_MEDICOS, @@ -282,4 +282,14 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { public void showDetails(SearchDialog dialog, Object o) throws Exception { } + public Object [][]getAllMedicos() + throws Exception + { + Select select = new Select( new String[]{ T_MEDICOS }, + new String[]{ ID, NOME, NUMERO_CEDULA }, + null, new String[]{ NOME }, null ); + Virtual2DArray array = executer.executeQuery( select ); + return array.getObjects(); + } + } diff --git a/trunk/siprp/ficha/EmpresaPanel.java b/trunk/siprp/ficha/EmpresaPanel.java index 9f7b6865..bc1223c7 100644 --- a/trunk/siprp/ficha/EmpresaPanel.java +++ b/trunk/siprp/ficha/EmpresaPanel.java @@ -217,7 +217,10 @@ public class EmpresaPanel extends JPanel } } } - + else + { + estabelecimentoText.setText( "Sede" ); + } } public Object save() @@ -303,6 +306,7 @@ public class EmpresaPanel extends JPanel { String names[] = (String[])components.keySet().toArray( new String[0] ); ComponentController.clear( names, components ); + estabelecimentoText.setText( "Sede" ); } public void setEnabled( boolean enable ) diff --git a/trunk/siprp/ficha/FichaAptidaoEditorManager.java b/trunk/siprp/ficha/FichaAptidaoEditorManager.java index 43a8f391..24570c25 100644 --- a/trunk/siprp/ficha/FichaAptidaoEditorManager.java +++ b/trunk/siprp/ficha/FichaAptidaoEditorManager.java @@ -107,13 +107,6 @@ public class FichaAptidaoEditorManager extends EditorManager public void newItem() { // System.out.println( "EditorManager: new " + this ); - switch( state ) - { - case STATE_EDIT: case STATE_NEW: - saveItem(); - break; - } - editor.enableComponents( index, true ); // new, edit, cancel, save, delete, select editor.actions( index, false, false, true, true, true, false ); diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index 49820195..c9644826 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -44,6 +44,7 @@ public class FichaWindow extends TabbedWindow createPermissions( permissions ) ); setEditorManagerFactory( FichaAptidaoEditorManager.getEditorManagerFactory() ); upperPanel = (UpperPanel) getUpperPanel(); + upperPanel.owner = this; fdpProvider = ( FichaDataProvider ) FichaDataProvider.getProvider(); setupComponents(); } @@ -174,60 +175,99 @@ public class FichaWindow extends TabbedWindow public boolean newItem( int index ) { - fdpProvider.setSearch( FichaDataProvider.SEARCH_EMPRESAS ); - SearchDialog search = new SearchDialog( fdpProvider, null, true, null, true ); - empresaID = ( Integer )search.getSelected(); + fdpProvider.setSearch( FichaDataProvider.SEARCH_EMPRESAS ); + SearchDialog search; + Integer oldID = empresaID; +// if( empresaID != null ) +// { +// try +// { +// MetaObject empresa = fdpProvider.load( fdpProvider.EMPRESAS, new DBKey( empresaID ) ); +// String designacao = (String) empresa.getProperty( fdpProvider.DESIGNACAO_SOCIAL ); +// search = new SearchDialog( fdpProvider, null, true, new Object[]{ empresaID, designacao }, false ); +// } +// catch( Exception ex ) +// { +// search = new SearchDialog( fdpProvider, null, true, null, true ); +// } +// } +// else +// { +// search = new SearchDialog( fdpProvider, null, true, null, true ); +// } + search = new SearchDialog( fdpProvider, null, true, null, true ); + empresaID = ( Integer )search.getSelected(); - if( empresaID == null ) + if( empresaID == null ) + { + if( search.getIsNew() ) { - if( search.getIsNew() ) - { - clear( 0 ); - return true; - } - else - { - return false; - } + estabelecimentoID = null; + trabalhadorID = null; + clear( 0 ); + return true; } - - fdpProvider.setSearch( FichaDataProvider.SEARCH_ESTABELECIMENTOS ); - fdpProvider.setSearchID( FichaDataProvider.SEARCH_EMPRESAS, empresaID.intValue() ); - search = new SearchDialog( fdpProvider, null, true, null, true ); - estabelecimentoID = ( Integer )search.getSelected(); + else + { + return false; + } + } + + fdpProvider.setSearch( FichaDataProvider.SEARCH_ESTABELECIMENTOS ); + fdpProvider.setSearchID( FichaDataProvider.SEARCH_EMPRESAS, empresaID.intValue() ); +// if( oldID != null && oldID.equals( empresaID ) && estabelecimentoID != null ) +// { +// try +// { +// MetaObject estabelecimento = fdpProvider.load( fdpProvider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) ); +// String nome = (String) estabelecimento.getProperty( fdpProvider.NOME ); +// search = new SearchDialog( fdpProvider, null, true, new Object[]{ estabelecimentoID, nome }, false ); +// } +// catch( Exception ex ) +// { +// search = new SearchDialog( fdpProvider, null, true, null, true ); +// } +// } +// else +// { +// search = new SearchDialog( fdpProvider, null, true, null, true ); +// } + search = new SearchDialog( fdpProvider, null, true, null, true ); + estabelecimentoID = ( Integer )search.getSelected(); - if( estabelecimentoID == null ) + if( estabelecimentoID == null ) + { + if( search.getIsNew() ) { - if( search.getIsNew() ) - { - reload(0); - return true; - } - else - { - return false; - } + trabalhadorID = null; + reload(0); + return true; } + else + { + return false; + } + } - fdpProvider.setSearch( FichaDataProvider.SEARCH_TRABALHADORES ); - fdpProvider.setSearchID( FichaDataProvider.SEARCH_ESTABELECIMENTOS, estabelecimentoID.intValue() ); - search = new SearchDialog( fdpProvider, null, true, null, false ); - trabalhadorID = ( Integer )search.getSelected(); + fdpProvider.setSearch( FichaDataProvider.SEARCH_TRABALHADORES ); + fdpProvider.setSearchID( FichaDataProvider.SEARCH_ESTABELECIMENTOS, estabelecimentoID.intValue() ); + search = new SearchDialog( fdpProvider, null, true, null, true ); + trabalhadorID = ( Integer )search.getSelected(); - if( trabalhadorID == null ) + if( trabalhadorID == null ) + { + if( search.getIsNew() ) { - if( search.getIsNew() ) - { - reload(0); - return true; - } - else - { - return false; - } + reload(0); + return true; } - reload(0); - return true; + else + { + return false; + } + } + reload(0); + return true; } public boolean delete( int index ) @@ -237,6 +277,8 @@ public class FichaWindow extends TabbedWindow public void reload( int index ) { + Integer upperData[] = new Integer[]{ empresaID, estabelecimentoID, trabalhadorID }; + upperPanel.fill( upperData ); Object empresaData[] = new Object[]{ empresaID, estabelecimentoID }; empresaPanel.fill( empresaData ); trabalhadorPanel.fill( trabalhadorID ); @@ -246,6 +288,7 @@ public class FichaWindow extends TabbedWindow public void enableComponents( int index, boolean enable ) { + upperPanel.setEnabled( enable ); empresaPanel.setEnabled( enable ); trabalhadorPanel.setEnabled( enable ); observacoesPanel.setEnabled( enable ); @@ -254,6 +297,7 @@ public class FichaWindow extends TabbedWindow public void clear( int index ) { + upperPanel.clear(); empresaPanel.clear(); trabalhadorPanel.clear(); observacoesPanel.clear(); diff --git a/trunk/siprp/ficha/UpperPanel.java b/trunk/siprp/ficha/UpperPanel.java index 89a9b25e..6c46bcbf 100644 --- a/trunk/siprp/ficha/UpperPanel.java +++ b/trunk/siprp/ficha/UpperPanel.java @@ -7,29 +7,44 @@ package siprp.ficha; import java.awt.*; +import java.awt.event.*; import javax.swing.*; +import java.util.*; +import com.evolute.utils.data.*; import com.evolute.utils.dataui.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.ui.*; + +import siprp.*; /** * * @author fpalma */ public class UpperPanel extends JPanel - implements FillerSaverWrapper + implements ControllableComponent, ItemListener { + protected JFrame owner; private JTextField empresaText; private JTextField nomeText; - private JTextField medicoText; + private JComboBox medicosCombo; private JTextField cpText; + private FichaDataProvider provider; + private Hashtable medicosHash; + /** Creates a new instance of UpperPanel */ public UpperPanel() + throws Exception { + provider = (FichaDataProvider)FichaDataProvider.getProvider(); + medicosHash = new Hashtable(); setupComponents(); } private void setupComponents() + throws Exception { JLabel empresaLabel = new JLabel( "Empresa/Entidade" ); empresaText = new JTextField(); @@ -38,10 +53,11 @@ public class UpperPanel extends JPanel nomeText = new JTextField(); nomeText.setEditable( false ); JLabel medicoLabel = new JLabel( "M\u00e9dico" ); - medicoText = new JTextField(); + medicosCombo = new JComboBox(); JLabel cpLabel = new JLabel( "c.p." ); cpText = new JTextField(); - + cpText.setEditable( false ); + fillCombo(); GridBagLayout gridbag = new GridBagLayout(); setLayout( gridbag ); GridBagConstraints constraints = new GridBagConstraints(); @@ -77,8 +93,8 @@ public class UpperPanel extends JPanel constraints.gridwidth = 1; constraints.weightx = 0.8; - gridbag.setConstraints( medicoText, constraints ); - add( medicoText ); + gridbag.setConstraints( medicosCombo, constraints ); + add( medicosCombo ); constraints.gridwidth = 1; constraints.weightx = 0; @@ -90,14 +106,155 @@ public class UpperPanel extends JPanel gridbag.setConstraints( cpText, constraints ); add( cpText ); } - - + public void fill(Object value) { + Integer values[] = (Integer[])value; + Integer empresaID = values[0]; + Integer estabelecimentoID = values[1]; + Integer trabalhadorID = values[2]; + clear(); + try + { + MetaObject trabalhador; + MetaObject estabelecimento; + MetaObject empresa; + if( trabalhadorID != null ) + { + trabalhador = provider.load( provider.TRABALHADORES, new DBKey( trabalhadorID ) ); + String nome = (String) trabalhador.getProperty( provider.NOME ); + nomeText.setText( nome ); + } + String nomeEstabelecimento = ""; + if( estabelecimentoID != null ) + { + estabelecimento = provider.load( provider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) ); + nomeEstabelecimento = (String) estabelecimento.getProperty( provider.NOME ); + } + if( empresaID != null ) + { + empresa = provider.load( provider.EMPRESAS, new DBKey( empresaID ) ); + String nomeEmpresa = (String) empresa.getProperty( provider.DESIGNACAO_SOCIAL ); + empresaText.setText( nomeEmpresa + ( nomeEstabelecimento.length() > 0?" / " + nomeEstabelecimento:"" ) ); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os dados do cabe\u00e7alho...", true ); + } } public Object save() { + Integer id = ( (IDObject) medicosCombo.getSelectedItem() ).getID(); + if( id != null ) + { + try + { + MetaObject medico = provider.load( provider.MEDICOS, new DBKey( id ) ); + return medico; + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } return null; } + + public void fillCombo() + throws Exception + { + medicosCombo.removeItemListener( this ); + medicosCombo.removeAllItems(); + medicosHash.clear(); + Object medicos[][] = provider.getAllMedicos(); + for( int n = 0; n < medicos.length; n++ ) + { + Object medico[] = new Object[ 4 ]; + medico[ 0 ] = new Integer( ( (Number)medicos[n][0] ).intValue() ); + medico[ 1 ] = medicos[ n ][ 1 ]; + medico[ 2 ] = medicos[ n ][ 2 ]; + medico[ 3 ] = new Integer( n ); + medicosHash.put( medicos[ n ][ 0 ], medico ); + medicosCombo.addItem( new MappableObject( (Integer) medico[ 0 ], medico[ 1 ] ) ); + } + + if( medicos.length > 0 ) + { + medicosCombo.setSelectedIndex( 0 ); + cpText.setText( medicos[ 0 ][ 2 ] != null?(String)medicos[ 0 ][ 2 ]:"" ); + } + else + { + medicosCombo.addItem( new MappableObject( null, "" ) ); + medicosCombo.setSelectedIndex( 0 ); + cpText.setText( "" ); + } + medicosCombo.addItem( new MappableObject( new Integer( -1 ), "Novo/Editar" ) ); + medicosCombo.addItemListener( this ); + } + + public void itemStateChanged(java.awt.event.ItemEvent itemEvent) + { + int index = medicosCombo.getSelectedIndex(); + if( index == medicosCombo.getItemCount() - 1 ) + { + try + { + MedicoEditor me = new MedicoEditor( owner ); + me.show(); + boolean isNew = me.getIsNew(); + Integer id = me.getID(); + if( id == null ) + { + medicosCombo.setSelectedIndex( 0 ); + } + else + { + fillCombo(); + if( id != null ) + { + Object[] medico = (Object[])medicosHash.get( id ); + medicosCombo.setSelectedIndex( ((Integer)medico[ 3 ] ).intValue() ); + } + } + + } + catch( Exception ex ) + { + JOptionPane.showMessageDialog( null, "Erro a abrir a janela de edi\u00e7\u00e3o...", "Erro...", + JOptionPane.ERROR_MESSAGE ); + ex.printStackTrace(); + medicosCombo.setSelectedIndex( 0 ); + return; + } + } + else + { + IDObject selected = (IDObject)medicosCombo.getItemAt( index ); + Integer id = selected.getID(); + if( id == null ) + { + cpText.setText( "" ); + } + else + { + Object[] medico = (Object[])medicosHash.get( id ); + cpText.setText( medico[ 2 ] != null?(String)medico[ 2 ]:"" ); + } + } + } + + public void clear() + { + empresaText.setText( "" ); + nomeText.setText( "" ); + medicosCombo.setSelectedIndex( 0 ); + } + + public void setEnabled( boolean enable ) + { + medicosCombo.setEnabled( enable ); + } }