|
|
|
@ -7,29 +7,44 @@
|
|
|
|
package siprp.ficha;
|
|
|
|
package siprp.ficha;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
import java.awt.event.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.evolute.utils.data.*;
|
|
|
|
import com.evolute.utils.dataui.*;
|
|
|
|
import com.evolute.utils.dataui.*;
|
|
|
|
|
|
|
|
import com.evolute.utils.metadb.*;
|
|
|
|
|
|
|
|
import com.evolute.utils.ui.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import siprp.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author fpalma
|
|
|
|
* @author fpalma
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class UpperPanel extends JPanel
|
|
|
|
public class UpperPanel extends JPanel
|
|
|
|
implements FillerSaverWrapper
|
|
|
|
implements ControllableComponent, ItemListener
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
protected JFrame owner;
|
|
|
|
private JTextField empresaText;
|
|
|
|
private JTextField empresaText;
|
|
|
|
private JTextField nomeText;
|
|
|
|
private JTextField nomeText;
|
|
|
|
private JTextField medicoText;
|
|
|
|
private JComboBox medicosCombo;
|
|
|
|
private JTextField cpText;
|
|
|
|
private JTextField cpText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private FichaDataProvider provider;
|
|
|
|
|
|
|
|
private Hashtable medicosHash;
|
|
|
|
|
|
|
|
|
|
|
|
/** Creates a new instance of UpperPanel */
|
|
|
|
/** Creates a new instance of UpperPanel */
|
|
|
|
public UpperPanel()
|
|
|
|
public UpperPanel()
|
|
|
|
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
provider = (FichaDataProvider)FichaDataProvider.getProvider();
|
|
|
|
|
|
|
|
medicosHash = new Hashtable();
|
|
|
|
setupComponents();
|
|
|
|
setupComponents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setupComponents()
|
|
|
|
private void setupComponents()
|
|
|
|
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
JLabel empresaLabel = new JLabel( "Empresa/Entidade" );
|
|
|
|
JLabel empresaLabel = new JLabel( "Empresa/Entidade" );
|
|
|
|
empresaText = new JTextField();
|
|
|
|
empresaText = new JTextField();
|
|
|
|
@ -38,10 +53,11 @@ public class UpperPanel extends JPanel
|
|
|
|
nomeText = new JTextField();
|
|
|
|
nomeText = new JTextField();
|
|
|
|
nomeText.setEditable( false );
|
|
|
|
nomeText.setEditable( false );
|
|
|
|
JLabel medicoLabel = new JLabel( "M\u00e9dico" );
|
|
|
|
JLabel medicoLabel = new JLabel( "M\u00e9dico" );
|
|
|
|
medicoText = new JTextField();
|
|
|
|
medicosCombo = new JComboBox();
|
|
|
|
JLabel cpLabel = new JLabel( "c.p." );
|
|
|
|
JLabel cpLabel = new JLabel( "c.p." );
|
|
|
|
cpText = new JTextField();
|
|
|
|
cpText = new JTextField();
|
|
|
|
|
|
|
|
cpText.setEditable( false );
|
|
|
|
|
|
|
|
fillCombo();
|
|
|
|
GridBagLayout gridbag = new GridBagLayout();
|
|
|
|
GridBagLayout gridbag = new GridBagLayout();
|
|
|
|
setLayout( gridbag );
|
|
|
|
setLayout( gridbag );
|
|
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
|
|
@ -77,8 +93,8 @@ public class UpperPanel extends JPanel
|
|
|
|
|
|
|
|
|
|
|
|
constraints.gridwidth = 1;
|
|
|
|
constraints.gridwidth = 1;
|
|
|
|
constraints.weightx = 0.8;
|
|
|
|
constraints.weightx = 0.8;
|
|
|
|
gridbag.setConstraints( medicoText, constraints );
|
|
|
|
gridbag.setConstraints( medicosCombo, constraints );
|
|
|
|
add( medicoText );
|
|
|
|
add( medicosCombo );
|
|
|
|
|
|
|
|
|
|
|
|
constraints.gridwidth = 1;
|
|
|
|
constraints.gridwidth = 1;
|
|
|
|
constraints.weightx = 0;
|
|
|
|
constraints.weightx = 0;
|
|
|
|
@ -90,14 +106,155 @@ public class UpperPanel extends JPanel
|
|
|
|
gridbag.setConstraints( cpText, constraints );
|
|
|
|
gridbag.setConstraints( cpText, constraints );
|
|
|
|
add( cpText );
|
|
|
|
add( cpText );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void fill(Object value)
|
|
|
|
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()
|
|
|
|
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;
|
|
|
|
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 );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|