From 4bfc89aa1c1814015d11e5b61391f8a9b2af10ac Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 5 Apr 2004 19:53:09 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@24 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/ficha/EmpresaPanel.java | 33 ++++++++++++++++- trunk/siprp/ficha/FichaWindow.java | 51 +++++++++++++++++++------- trunk/siprp/ficha/ValuesException.java | 22 +++++++++++ 3 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 trunk/siprp/ficha/ValuesException.java diff --git a/trunk/siprp/ficha/EmpresaPanel.java b/trunk/siprp/ficha/EmpresaPanel.java index f899ebdf..9f7b6865 100644 --- a/trunk/siprp/ficha/EmpresaPanel.java +++ b/trunk/siprp/ficha/EmpresaPanel.java @@ -222,6 +222,8 @@ public class EmpresaPanel extends JPanel public Object save() { + StringBuffer msg = new StringBuffer(); + boolean hasMsg = false; try { if( estabelecimento == null ) @@ -261,13 +263,40 @@ public class EmpresaPanel extends JPanel estabelecimento.setProperty( name, hash.get( name ) ); } estabelecimento.setProperty( provider.R_ESTABELECIMENTO_EMPRESA, empresa ); - return estabelecimento; + + if( ((String)empresa.getProperty( provider.DESIGNACAO_SOCIAL )).trim().length() == 0 ) + { + msg.append( "A empresa tem de ter uma design\u00e7\u00e3o social\n" ); + hasMsg = true; + } + if( empresa.getProperty( provider.SERVICO_SAUDE_TIPO ) == null ) + { + msg.append( "A empresa tem de ter um tipo de seri\00e7o de sa\u00fade\n" ); + hasMsg = true; + } + if( empresa.getProperty( provider.SERVICO_HIGIENE_TIPO ) == null ) + { + msg.append( "A empresa tem de ter um tipo de seri\00e7o de higiene\n" ); + hasMsg = true; + } + if( ((String)estabelecimento.getProperty( provider.NOME )).trim().length() == 0 ) + { + msg.append( "O estabelecimento tem de ter nome\n" ); + hasMsg = true; + } + } catch( Exception ex ) { ex.printStackTrace(); + return null; } - return null; + if( hasMsg ) + { + throw new ValuesException( msg.toString() ); + } + return estabelecimento; + } public void clear() diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index 59c82289..0b179be8 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -106,22 +106,47 @@ public class FichaWindow extends TabbedWindow new Runnable(){ public void run() { - MetaObject estabelecimento = (MetaObject)empresaPanel.save(); - try - { - estabelecimento.save(); - MetaObject trabalhador = (MetaObject)trabalhadorPanel.save(); - trabalhador.setProperty( fdpProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento ); - trabalhador.setProperty( fdpProvider.OBSERVACOES, observacoesPanel.save() ); - trabalhador.save(); - } - catch( Exception ex ) - { - DialogException.showExceptionMessage( ex, "Erro a guardar", true ); - } } }); + StringBuffer msg = new StringBuffer(); + MetaObject estabelecimento; + try + { + estabelecimento = (MetaObject)empresaPanel.save(); + } + catch( ValuesException vex ) + { + msg.append( vex.getMessage() ); + estabelecimento = null; + } + MetaObject trabalhador; + try + { + trabalhador = (MetaObject)trabalhadorPanel.save(); + } + catch( ValuesException vex ) + { + msg.append( vex.getMessage() ); + trabalhador = null; + } + if( estabelecimento == null || trabalhador == null ) + { + JOptionPane.showMessageDialog( this, msg.toString(), "Erro...", JOptionPane.ERROR_MESSAGE ); + return false; + } + trabalhador.setProperty( fdpProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento ); + trabalhador.setProperty( fdpProvider.OBSERVACOES, observacoesPanel.save() ); + try + { + + trabalhador.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a guardar", true ); + return false; + } return true; } diff --git a/trunk/siprp/ficha/ValuesException.java b/trunk/siprp/ficha/ValuesException.java new file mode 100644 index 00000000..e5a14882 --- /dev/null +++ b/trunk/siprp/ficha/ValuesException.java @@ -0,0 +1,22 @@ +/* + * ValuesException.java + * + * Created on 5 de Abril de 2004, 20:22 + */ + +package siprp.ficha; + +/** + * + * @author fpalma + */ +public class ValuesException extends RuntimeException +{ + + /** Creates a new instance of ValuesException */ + public ValuesException( String msg ) + { + super( msg ); + } + +}