forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
443 lines
15 KiB
443 lines
15 KiB
/*
|
|
* PrestadoresWindow.java
|
|
*
|
|
* Created on February 2, 2007, 9:44 AM
|
|
*
|
|
* To change this template, choose Tools | Template Manager
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package siprp.medicina.prestadores;
|
|
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.otilde;
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Dimension;
|
|
import java.awt.event.ItemEvent;
|
|
import java.awt.event.ItemListener;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Vector;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JSeparator;
|
|
import javax.swing.JTabbedPane;
|
|
import javax.swing.JTextArea;
|
|
import javax.swing.JTextField;
|
|
|
|
import leaf.ui.LeafDialog;
|
|
import siprp.clientes.ClientesDataProvider;
|
|
import siprp.clientes.ContactoPanel;
|
|
import siprp.data.outer.ContactosData;
|
|
import siprp.data.outer.PrestadoresData;
|
|
import siprp.database.cayenne.objects.Prestadores;
|
|
import siprp.database.cayenne.objects.PrtGruposProtocolo;
|
|
import siprp.database.cayenne.providers.MedicinaDAO;
|
|
import siprp.ui.SIPRPEditorWindow;
|
|
|
|
import com.evolute.entity.ProviderInterface;
|
|
import com.evolute.utils.Singleton;
|
|
import com.evolute.utils.data.IDObject;
|
|
import com.evolute.utils.dataui.ComponentController;
|
|
import com.evolute.utils.dataui.ComponentsHashtable;
|
|
import com.evolute.utils.dataui.JDOControllable;
|
|
import com.evolute.utils.dataui.JTextComponentPlainFillerSaver;
|
|
import com.evolute.utils.ui.DialogException;
|
|
import com.evolute.utils.ui.panel.CheckBoxPanel;
|
|
import com.evolute.utils.ui.search.SearchDialog;
|
|
|
|
/**
|
|
*
|
|
* @author fpalma
|
|
*/
|
|
public class PrestadoresWindow extends SIPRPEditorWindow
|
|
{
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public static final String TITLE = "Prestadores";
|
|
|
|
protected JTextField nomeText;
|
|
protected JCheckBox activoCheck;
|
|
protected JCheckBox consultasCheck;
|
|
protected JCheckBox ecdsCheck;
|
|
protected CheckBoxPanel ecdsPanel;
|
|
protected JTextArea moradaText;
|
|
protected JTextField codigoPostalText;
|
|
protected JTextField localidadeCodigoPostalText;
|
|
protected JTextField localidadeText;
|
|
protected ContactoPanel contactoPanel;
|
|
protected JTextField contribuinteText;
|
|
|
|
private final JLabel labelObservacoes = new JLabel( "Observa" + ccedil + otilde + "es" );
|
|
private final JTextArea textObservacoes = new JTextArea();
|
|
|
|
protected PrestadoresDataProvider provider;
|
|
protected ClientesDataProvider clientesProvider;
|
|
|
|
protected ComponentsHashtable components;
|
|
|
|
protected PrestadoresData prestador;
|
|
protected Integer gruposProtocolo[];
|
|
|
|
private final JTabbedPane tabbedPane = new JTabbedPane();
|
|
private final JPanel prestadoresPanel = new JPanel();
|
|
private final JPanel analisadoresPanel = new JPanel();
|
|
|
|
private final JLabel labelGrupos = new JLabel( "Tipos de ECDs" );
|
|
private final JLabel labelAnalisador = new JLabel( "Analisadores" );
|
|
private final JLabel labelMessage = new JLabel( " " );
|
|
|
|
private final Map<PrtGruposProtocolo, JLabel> mapLabel = new HashMap<PrtGruposProtocolo, JLabel>();
|
|
private final Map<PrtGruposProtocolo, JComboBox> mapComboBox = new HashMap<PrtGruposProtocolo, JComboBox>();
|
|
|
|
private final List<Prestadores> listAnalisadores = new ArrayList<Prestadores>();
|
|
private final List<PrtGruposProtocolo> listGrupos = new ArrayList<PrtGruposProtocolo>();
|
|
|
|
private final MedicinaDAO medicinaCayenneDAO = new MedicinaDAO();
|
|
|
|
/** Creates a new instance of PrestadoresWindow */
|
|
public PrestadoresWindow() throws Exception
|
|
{
|
|
super( new int[][] {
|
|
{
|
|
NEW_INDEX, EDIT_INDEX, CANCEL_INDEX, SAVE_INDEX, DELETE_INDEX, SELECT_BYNAME_INDEX
|
|
}
|
|
} );
|
|
provider = PrestadoresDataProvider.getProvider();
|
|
clientesProvider = (ClientesDataProvider) ClientesDataProvider.getProvider();
|
|
setupComponents();
|
|
setupComponentsHashtable();
|
|
}
|
|
|
|
private void setupComponents()
|
|
{
|
|
setTitle( TITLE );
|
|
setSize( 800, 600 );
|
|
tabbedPane.addTab( "Prestadores", prestadoresPanel );
|
|
tabbedPane.addTab( "Analisadores", analisadoresPanel );
|
|
|
|
setupAnalisadoresTab();
|
|
setupPrestadoresTab();
|
|
// pack();
|
|
}
|
|
|
|
private void setupPrestadoresTab()
|
|
{
|
|
try
|
|
{
|
|
JLabel nomeLabel = new JLabel( "Designa\u00e7\u00e3o" );
|
|
nomeText = new JTextField();
|
|
nomeText.setPreferredSize( new Dimension( 500, 20 ) );
|
|
activoCheck = new JCheckBox( "Activo (actualmente fornece servi\u00e7os \u00e0 SIPRP)" );
|
|
consultasCheck = new JCheckBox( "Faz consultas" );
|
|
ecdsCheck = new JCheckBox( "Faz ecds" );
|
|
List<IDObject> gruposProtocolo = new Vector<IDObject>();
|
|
IDObject gruposProtocoloReais[] = clientesProvider.getAllGruposProtocoloReais();
|
|
if( gruposProtocoloReais != null && gruposProtocoloReais.length > 0 )
|
|
{
|
|
gruposProtocolo.addAll( Arrays.asList( gruposProtocoloReais ) );
|
|
}
|
|
IDObject gruposProtocoloFalsos[] = clientesProvider.getAllGruposProtocoloFalsos();
|
|
if( gruposProtocoloFalsos != null && gruposProtocoloFalsos.length > 0 )
|
|
{
|
|
gruposProtocolo.addAll( Arrays.asList( gruposProtocoloFalsos ) );
|
|
}
|
|
ecdsPanel = new CheckBoxPanel( gruposProtocolo.toArray( new IDObject[gruposProtocolo.size()] ) );
|
|
JLabel contactoLabel = new JLabel( "Contacto" );
|
|
contactoPanel = new ContactoPanel();
|
|
contactoPanel.setPreferredSize( new Dimension( 350, 120 ) );
|
|
contactoPanel.setBorder( BorderFactory.createEtchedBorder() );
|
|
JLabel moradaLabel = new JLabel( "Morada" );
|
|
moradaText = new JTextArea();
|
|
moradaText.setLineWrap( true );
|
|
moradaText.setWrapStyleWord( true );
|
|
JScrollPane moradaScroll = new JScrollPane( moradaText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
|
moradaScroll.setPreferredSize( new Dimension( 500, 50 ) );
|
|
JLabel codigoPostalLabel = new JLabel( "C\u00f3digo Postal" );
|
|
codigoPostalText = new JTextField();
|
|
codigoPostalText.setPreferredSize( new Dimension( 100, 50 ) );
|
|
localidadeCodigoPostalText = new JTextField();
|
|
localidadeCodigoPostalText.setPreferredSize( new Dimension( 150, 50 ) );
|
|
JLabel localidadeLabel = new JLabel( "Localidade" );
|
|
localidadeText = new JTextField();
|
|
JLabel contribuinteLabel = new JLabel( "Contribuinte" );
|
|
contribuinteText = new JTextField();
|
|
contribuinteText.setPreferredSize( new Dimension( 100, 50 ) );
|
|
|
|
double cols[] = new double[] {
|
|
TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL
|
|
};
|
|
double rows[] = new double[] {
|
|
TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL
|
|
};
|
|
TableLayout tableLayout = new TableLayout( cols, rows );
|
|
prestadoresPanel.setLayout( tableLayout );
|
|
|
|
tableLayout = new TableLayout( new double[] {
|
|
TableLayout.FILL
|
|
}, new double[] {
|
|
TableLayout.FILL
|
|
} );
|
|
getContentPane().setLayout( tableLayout );
|
|
getContentPane().add( tabbedPane, new TableLayoutConstraints( 0, 0 ) );
|
|
|
|
prestadoresPanel.add( nomeLabel, new TableLayoutConstraints( 0, 0 ) );
|
|
prestadoresPanel.add( nomeText, new TableLayoutConstraints( 1, 0, 3, 0 ) );
|
|
prestadoresPanel.add( activoCheck, new TableLayoutConstraints( 0, 1, 2, 1 ) );
|
|
prestadoresPanel.add( consultasCheck, new TableLayoutConstraints( 0, 2 ) );
|
|
prestadoresPanel.add( ecdsCheck, new TableLayoutConstraints( 0, 3 ) );
|
|
prestadoresPanel.add( ecdsPanel, new TableLayoutConstraints( 1, 3, 2, 3 ) );
|
|
prestadoresPanel.add( contactoLabel, new TableLayoutConstraints( 0, 4 ) );
|
|
prestadoresPanel.add( contactoPanel, new TableLayoutConstraints( 1, 4, 2, 4 ) );
|
|
prestadoresPanel.add( moradaLabel, new TableLayoutConstraints( 0, 5 ) );
|
|
prestadoresPanel.add( moradaScroll, new TableLayoutConstraints( 1, 5, 3, 5 ) );
|
|
prestadoresPanel.add( codigoPostalLabel, new TableLayoutConstraints( 0, 6 ) );
|
|
prestadoresPanel.add( codigoPostalText, new TableLayoutConstraints( 1, 6 ) );
|
|
prestadoresPanel.add( localidadeCodigoPostalText, new TableLayoutConstraints( 2, 6, 3, 6 ) );
|
|
prestadoresPanel.add( localidadeLabel, new TableLayoutConstraints( 0, 7 ) );
|
|
prestadoresPanel.add( localidadeText, new TableLayoutConstraints( 1, 7, 3, 7 ) );
|
|
prestadoresPanel.add( contribuinteLabel, new TableLayoutConstraints( 0, 8 ) );
|
|
prestadoresPanel.add( contribuinteText, new TableLayoutConstraints( 1, 8 ) );
|
|
prestadoresPanel.add( labelObservacoes, new TableLayoutConstraints( 0, 9 ) );
|
|
prestadoresPanel.add( textObservacoes, new TableLayoutConstraints( 0, 10, 3, 10 ) );
|
|
} catch( Exception e )
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void setupComponentsHashtable()
|
|
{
|
|
components = new ComponentsHashtable();
|
|
components.putComponent( PrestadoresData.NOME, nomeText );
|
|
components.putComponent( PrestadoresData.NOME_PLAIN, new JTextComponentPlainFillerSaver( nomeText ) );
|
|
components.putComponent( PrestadoresData.MORADA, moradaText );
|
|
components.putComponent( PrestadoresData.CODIGO_POSTAL, codigoPostalText );
|
|
components.putComponent( PrestadoresData.LOCALIDADE_CP, localidadeCodigoPostalText );
|
|
components.putComponent( PrestadoresData.LOCALIDADE, localidadeText );
|
|
components.putComponent( PrestadoresData.CONTRIBUINTE, contribuinteText );
|
|
components.putComponent( PrestadoresData.OBSERVACOES, textObservacoes );
|
|
components.putComponent( PrestadoresData.ACTIVO, activoCheck );
|
|
components.putComponent( PrestadoresData.FAZ_CONSULTAS, consultasCheck );
|
|
components.putComponent( PrestadoresData.FAZ_ECDS, ecdsCheck );
|
|
components.putComponent( PrestadoresData.CONTACTO_ID,
|
|
new JDOControllable( (ProviderInterface) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ), ContactosData.class, new String[] {
|
|
ContactosData.ID
|
|
}, contactoPanel ) );
|
|
}
|
|
|
|
public boolean searchByName()
|
|
{
|
|
SearchDialog search = new SearchDialog( provider );
|
|
Integer id = (Integer) search.getSelected();
|
|
if( id == null )
|
|
{
|
|
return false;
|
|
}
|
|
clear( 0 );
|
|
try
|
|
{
|
|
prestador = provider.getPrestadorByID( id );
|
|
gruposProtocolo = provider.getGruposProtocoloIDByPrestadorID( id );
|
|
reload( 0 );
|
|
} catch( Exception ex )
|
|
{
|
|
DialogException.showExceptionMessage( ex, "Ocorreu um erro a carregar o prestador.", true );
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void enableComponents( int index, boolean enable )
|
|
{
|
|
String names[] = (String[]) components.keySet().toArray( new String[0] );
|
|
ComponentController.setEnabled( names, enable, components );
|
|
ecdsPanel.setEnabled( enable );
|
|
}
|
|
|
|
public void reload( int index )
|
|
{
|
|
try
|
|
{
|
|
String names[] = (String[]) components.keySet().toArray( new String[0] );
|
|
ComponentController.fill( names, prestador.getHashData(), components );
|
|
ecdsPanel.setSelected( gruposProtocolo );
|
|
} catch( Exception ex )
|
|
{
|
|
DialogException.showExceptionMessage( ex, "Erro a carregar dados", true );
|
|
|
|
}
|
|
}
|
|
|
|
public void clear( int index )
|
|
{
|
|
String names[] = (String[]) components.keySet().toArray( new String[0] );
|
|
ComponentController.clear( names, components );
|
|
ecdsPanel.clear();
|
|
prestador = null;
|
|
gruposProtocolo = null;
|
|
}
|
|
|
|
public boolean newItem( int index )
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public boolean save( int index )
|
|
{
|
|
if( prestador == null )
|
|
{
|
|
prestador = new PrestadoresData();
|
|
}
|
|
String names[] = (String[]) components.keySet().toArray( new String[0] );
|
|
Map<String,Object> data = prestador.getHashData();
|
|
ComponentController.save( names, data, components );
|
|
prestador.setHashData( data );
|
|
gruposProtocolo = ecdsPanel.getSelected();
|
|
try
|
|
{
|
|
provider.savePrestador( prestador );
|
|
provider.setGruposProtocoloForPrestador( (Integer) prestador.get( PrestadoresData.ID ), gruposProtocolo );
|
|
} catch( Exception ex )
|
|
{
|
|
DialogException.showExceptionMessage( ex, "Erro a guardar dados", true );
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void setupAnalisadoresTab()
|
|
{
|
|
loadAnalisadoresTabData();
|
|
setupAnalisadoresTabLayout();
|
|
setupAnalisadoresTabComponents();
|
|
placeAnalisadoresTabComponents();
|
|
setupAnalisadoresTabListeners();
|
|
}
|
|
|
|
private void loadAnalisadoresTabData()
|
|
{
|
|
clearAnalisadoresTabData();
|
|
listGrupos.addAll( medicinaCayenneDAO.getAllPrtGruposProtocolo() );
|
|
listAnalisadores.addAll( medicinaCayenneDAO.getAllPrestadores() );
|
|
}
|
|
|
|
private void clearAnalisadoresTabData()
|
|
{
|
|
mapComboBox.clear();
|
|
mapLabel.clear();
|
|
listGrupos.clear();
|
|
listAnalisadores.clear();
|
|
shout( null );
|
|
}
|
|
|
|
private void setupAnalisadoresTabLayout()
|
|
{
|
|
double[] cols = new double[] {
|
|
TableLayout.MINIMUM, TableLayout.FILL
|
|
};
|
|
double[] rows = new double[1 + listGrupos.size() + 2];
|
|
for( int i = 0; i < rows.length; ++i )
|
|
{
|
|
rows[i] = TableLayout.MINIMUM;
|
|
}
|
|
TableLayout layout = new TableLayout( cols, rows );
|
|
layout.setHGap( 5 );
|
|
layout.setVGap( 5 );
|
|
analisadoresPanel.setLayout( layout );
|
|
}
|
|
|
|
private void setupAnalisadoresTabComponents()
|
|
{
|
|
Object[] analisadores = listAnalisadores.toArray();
|
|
for( PrtGruposProtocolo grupo : listGrupos )
|
|
{
|
|
JLabel label = new JLabel( grupo.getDescricao() );
|
|
mapLabel.put( grupo, label );
|
|
JComboBox combo = new JComboBox( analisadores );
|
|
Prestadores analisador = grupo.getToAnalisador();
|
|
combo.setSelectedItem( analisador == null ? Prestadores.prestadorNulo : analisador );
|
|
mapComboBox.put( grupo, combo );
|
|
}
|
|
labelMessage.setForeground( Color.RED.darker().darker() );
|
|
}
|
|
|
|
private void placeAnalisadoresTabComponents()
|
|
{
|
|
analisadoresPanel.add( labelGrupos, new TableLayoutConstraints( 0, 0 ) );
|
|
analisadoresPanel.add( labelAnalisador, new TableLayoutConstraints( 1, 0 ) );
|
|
for( int i = 0; i < listGrupos.size(); ++i )
|
|
{
|
|
PrtGruposProtocolo grupo = listGrupos.get( i );
|
|
JLabel label = mapLabel.get( grupo );
|
|
analisadoresPanel.add( label, new TableLayoutConstraints( 0, i + 1 ) );
|
|
JComboBox combo = mapComboBox.get( grupo );
|
|
analisadoresPanel.add( combo, new TableLayoutConstraints( 1, i + 1 ) );
|
|
}
|
|
int line = listGrupos.size() + 1;
|
|
analisadoresPanel.add( new JSeparator(), new TableLayoutConstraints( 0, line, 1, line ) );
|
|
++line;
|
|
analisadoresPanel.add( labelMessage, new TableLayoutConstraints( 0, line, 1, line ) );
|
|
}
|
|
|
|
private void setupAnalisadoresTabListeners()
|
|
{
|
|
for( PrtGruposProtocolo grupo : listGrupos )
|
|
{
|
|
JComboBox combo = mapComboBox.get( grupo );
|
|
setupListenersFor( combo );
|
|
}
|
|
}
|
|
|
|
private void setupListenersFor( JComboBox combo )
|
|
{
|
|
combo.addItemListener( new ItemListener()
|
|
{
|
|
|
|
@Override
|
|
public void itemStateChanged( ItemEvent itemEvent )
|
|
{
|
|
try
|
|
{
|
|
if( ItemEvent.SELECTED == itemEvent.getStateChange() )
|
|
{
|
|
JComboBox combo = (JComboBox) itemEvent.getSource();
|
|
for( PrtGruposProtocolo grupo : mapComboBox.keySet() )
|
|
{
|
|
if( mapComboBox.get( grupo ).equals( combo ) )
|
|
{
|
|
Prestadores analisador = (Prestadores) combo.getSelectedItem();
|
|
grupo.setToAnalisador( Prestadores.prestadorNulo.equals( analisador ) ? null : analisador );
|
|
grupo.save();
|
|
shout( "Tipo de ECD: " + grupo.getDescricao() + " -> Analisador: " + analisador.getNome() + " [guardado]" );
|
|
}
|
|
}
|
|
}
|
|
} catch( Exception e )
|
|
{
|
|
LeafDialog.error( e );
|
|
}
|
|
}
|
|
|
|
} );
|
|
}
|
|
|
|
private void shout( String message )
|
|
{
|
|
labelMessage.setText( message == null ? " " : message );
|
|
}
|
|
|
|
}
|