From 3fef2289edb26763e9a5ed03ca3df8bf0e0bbaf8 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Thu, 1 Apr 2004 18:03:26 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@21 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/ficha/EmpresaPanel.java | 50 ++++++++++++++++++- .../ficha/FichaAptidaoEditorManager.java | 1 - trunk/siprp/ficha/FichaWindow.java | 49 +++++++++++------- 3 files changed, 80 insertions(+), 20 deletions(-) diff --git a/trunk/siprp/ficha/EmpresaPanel.java b/trunk/siprp/ficha/EmpresaPanel.java index 4f8ef501..84b6917d 100644 --- a/trunk/siprp/ficha/EmpresaPanel.java +++ b/trunk/siprp/ficha/EmpresaPanel.java @@ -13,6 +13,7 @@ import java.util.*; import com.evolute.utils.data.*; import com.evolute.utils.dataui.*; import com.evolute.utils.metadb.*; +import com.evolute.utils.ui.*; import com.evolute.utils.ui.button.*; import com.evolute.utils.ui.panel.*; @@ -168,6 +169,53 @@ public class EmpresaPanel extends JPanel public void fill(Object value) { + clear(); + if( value != null ) + { + Integer empresaID = (Integer)((Object[])value)[0]; + Integer estabelecimentoID = (Integer)((Object[])value)[1]; + if( empresaID != null ) + { + try + { + empresa = provider.load( provider.EMPRESAS, new DBKey( empresaID ) ); + DBField fields[] = provider.EMPRESAS.getInsertFields(); + String empresaFields[] = new String[ fields.length ]; + Hashtable data = new Hashtable(); + for( int i = 0; i < empresaFields.length; ++i ) + { + empresaFields[ i ] = fields[ i ].FULL_NAME; + Object fieldValue = empresa.getProperty( empresaFields[ i ] ); + if( fieldValue != null ) + { + data.put( empresaFields[ i ], fieldValue ); + } + } + ComponentController.fill( empresaFields, data, components ); + if( estabelecimentoID != null ) + { + estabelecimento = provider.load( provider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) ); + fields = provider.ESTABELECIMENTOS.getInsertFields(); + String estabelecimentoFields[] = new String[ fields.length ]; + for( int i = 0; i < estabelecimentoFields.length; ++i ) + { + estabelecimentoFields[ i ] = fields[ i ].FULL_NAME; + Object fieldValue = estabelecimento.getProperty( estabelecimentoFields[ i ] ); + if( fieldValue != null ) + { + data.put( estabelecimentoFields[ i ], fieldValue ); + } + } + ComponentController.fill( estabelecimentoFields, data, components ); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os dados da Empresa", true ); + } + } + } + } public Object save() @@ -213,7 +261,7 @@ public class EmpresaPanel extends JPanel estabelecimento.setProperty( provider.R_ESTABELECIMENTO_EMPRESA, empresa ); empresa.save(); estabelecimento.save(); - return empresa.getPrimaryKeyValue(); + return estabelecimento; } catch( Exception ex ) { diff --git a/trunk/siprp/ficha/FichaAptidaoEditorManager.java b/trunk/siprp/ficha/FichaAptidaoEditorManager.java index 624e5dde..74028f52 100644 --- a/trunk/siprp/ficha/FichaAptidaoEditorManager.java +++ b/trunk/siprp/ficha/FichaAptidaoEditorManager.java @@ -148,7 +148,6 @@ public class FichaAptidaoEditorManager extends EditorManager { return; } - editor.enableComponents( index, false ); // new, edit, cancel, save, delete, select editor.actions( index, true, true, false, true, true, true ); state = STATE_EDIT; diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index a651fb35..830cb9f3 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -27,6 +27,9 @@ public class FichaWindow extends TabbedWindow private ExamePanel examePanel; private FichaDataProvider fdpProvider; + private Integer empresaID; + private Integer estabelecimentoID; + private Integer trabalhadorID; private static int permissions[][] = new int[][]{ { NEW_INDEX, CANCEL_INDEX, SAVE_INDEX, DELETE_INDEX } }; @@ -50,18 +53,6 @@ public class FichaWindow extends TabbedWindow setResizable( false ); setTitle( "Ficha de Aptid\u00e3o" ); -// upperPanel = new UpperPanel(); -// JTabbedPane tabbed = new JTabbedPane(); -// getContentPane().setLayout( new BorderLayout() ); -// getContentPane().add( upperPanel, BorderLayout.NORTH ); -// getContentPane().add( tabbed, BorderLayout.CENTER ); -// -// JPanel empresaTrabalhadorPanel = new JPanel(); -// JPanel exameRecomendacoesPanel = new JPanel(); -// -// tabbed.add( "Empresa/Trabalhador", empresaTrabalhadorPanel ); -// tabbed.add( "Exame", exameRecomendacoesPanel ); - JPanel empresaTrabalhadorPanel = getTab( 0 ); JPanel exameRecomendacoesPanel = getTab( 1 ); @@ -76,6 +67,7 @@ public class FichaWindow extends TabbedWindow constraints.weighty = 0; empresaPanel = new EmpresaPanel(); + empresaPanel.setEnabled( false ); gridbag.setConstraints( empresaPanel, constraints ); empresaTrabalhadorPanel.add( empresaPanel ); @@ -108,7 +100,13 @@ public class FichaWindow extends TabbedWindow public boolean save( int index ) { - System.out.println( "Empresa id: " + empresaPanel.save() ); + new ProgressDialog( this, "A gravar...", + new Runnable(){ + public void run() + { + empresaPanel.save(); + } + }); return true; } @@ -116,12 +114,13 @@ public class FichaWindow extends TabbedWindow { fdpProvider.setSearch( FichaDataProvider.SEARCH_EMPRESAS ); SearchDialog search = new SearchDialog( fdpProvider, null, true, null, true ); - Integer empresaID = ( Integer )search.getSelected(); + empresaID = ( Integer )search.getSelected(); if( empresaID == null ) { if( search.getIsNew() ) { + clear( 0 ); return true; } else @@ -133,12 +132,13 @@ public class FichaWindow extends TabbedWindow fdpProvider.setSearch( FichaDataProvider.SEARCH_ESTABELECIMENTOS ); fdpProvider.setSearchID( FichaDataProvider.SEARCH_EMPRESAS, empresaID.intValue() ); search = new SearchDialog( fdpProvider, null, true, null, true ); - Integer estabelecimentoID = ( Integer )search.getSelected(); + estabelecimentoID = ( Integer )search.getSelected(); if( estabelecimentoID == null ) { if( search.getIsNew() ) { + reload(0); return true; } else @@ -150,21 +150,22 @@ public class FichaWindow extends TabbedWindow fdpProvider.setSearch( FichaDataProvider.SEARCH_TRABALHADORES ); fdpProvider.setSearchID( FichaDataProvider.SEARCH_ESTABELECIMENTOS, estabelecimentoID.intValue() ); search = new SearchDialog( fdpProvider, null, true, null, false ); - Integer trabalhadorID = ( Integer )search.getSelected(); + trabalhadorID = ( Integer )search.getSelected(); if( trabalhadorID == null ) { if( search.getIsNew() ) { System.out.println( "FichaWindow: newItem: CRIAR TRABALHADOR" ); -return true; + reload(0); + return true; } else { return false; } } - + reload(0); return true; } @@ -175,5 +176,17 @@ return true; public void reload( int index ) { + Object empresaData[] = new Object[]{ empresaID, estabelecimentoID }; + empresaPanel.fill( empresaData ); + } + + public void enableComponents( int index, boolean enable ) + { + empresaPanel.setEnabled( enable ); + } + + public void clear( int index ) + { + empresaPanel.clear(); } }