forked from Coded/SIPRP
no message
git-svn-id: https://svn.coded.pt/svn/SIPRP@364 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
25cce0976d
commit
fb4fedb68d
@ -0,0 +1,254 @@
|
||||
/*
|
||||
* ProcessoUpperPanel.java
|
||||
*
|
||||
* Created on February 1, 2006, 6:48 PM
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package siprp.medicina.processo;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.util.*;
|
||||
import com.evolute.utils.dataui.*;
|
||||
import com.evolute.utils.tables.*;
|
||||
import com.evolute.utils.ui.*;
|
||||
import siprp.medicina.MedicinaDataProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public class ProcessoUpperPanel extends JPanel
|
||||
implements ListSelectionListener, ControllableComponent
|
||||
{
|
||||
protected BaseTable empresasTable;
|
||||
protected VectorTableModel empresasModel;
|
||||
protected BaseTable estabelecimentosTable;
|
||||
protected VectorTableModel estabelecimentosModel;
|
||||
protected BaseTable trabalhadoresTable;
|
||||
protected VectorTableModel trabalhadoresModel;
|
||||
|
||||
protected MedicinaDataProvider provider;
|
||||
|
||||
protected final Vector listeners;
|
||||
|
||||
protected boolean editing = false;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ProcessoUpperPanel
|
||||
*/
|
||||
public ProcessoUpperPanel()
|
||||
throws Exception
|
||||
{
|
||||
provider = ( MedicinaDataProvider ) MedicinaDataProvider.getProvider();
|
||||
listeners = new Vector();
|
||||
setupComponents();
|
||||
}
|
||||
|
||||
private void setupComponents()
|
||||
throws Exception
|
||||
{
|
||||
empresasModel = new VectorTableModel( new String[]{ "empresas" } );
|
||||
empresasTable = new BaseTable( empresasModel );
|
||||
empresasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
||||
empresasTable.setNonResizableNorReordable();
|
||||
JScrollPane empresasScroll =
|
||||
new JScrollPane( empresasTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||
empresasTable.getSelectionModel().addListSelectionListener( this );
|
||||
estabelecimentosModel = new VectorTableModel( new String[]{ "estabelecimentos" } );
|
||||
estabelecimentosTable = new BaseTable( estabelecimentosModel );
|
||||
estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
||||
estabelecimentosTable.setNonResizableNorReordable();
|
||||
JScrollPane estabelecimentosScroll =
|
||||
new JScrollPane( estabelecimentosTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||
estabelecimentosTable.getSelectionModel().addListSelectionListener( this );
|
||||
trabalhadoresModel = new VectorTableModel( new String[]{ "trabalhadores" } );
|
||||
trabalhadoresTable = new BaseTable( trabalhadoresModel );
|
||||
trabalhadoresTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
||||
trabalhadoresTable.setNonResizableNorReordable();
|
||||
JScrollPane trabalhadoresScroll =
|
||||
new JScrollPane( trabalhadoresTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||
trabalhadoresTable.getSelectionModel().addListSelectionListener( this );
|
||||
|
||||
GridBagLayout gridbag = new GridBagLayout();
|
||||
setLayout( gridbag );
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.insets = new Insets( 1, 1, 1, 1 );
|
||||
constraints.fill = GridBagConstraints.BOTH;
|
||||
constraints.gridwidth = 1;
|
||||
constraints.gridheight = 1;
|
||||
constraints.weightx = 0.3;
|
||||
constraints.weighty = 1;
|
||||
|
||||
gridbag.setConstraints( empresasScroll, constraints );
|
||||
|
||||
gridbag.setConstraints( estabelecimentosScroll, constraints );
|
||||
|
||||
constraints.weightx = 0.4;
|
||||
constraints.gridheight = GridBagConstraints.REMAINDER;
|
||||
gridbag.setConstraints( trabalhadoresScroll, constraints );
|
||||
|
||||
add( empresasScroll );
|
||||
add( estabelecimentosScroll );
|
||||
add( trabalhadoresScroll );
|
||||
|
||||
ColumnizedMappable empresas[] = provider.getAllEmpresas();
|
||||
Vector values = empresasModel.getValues();
|
||||
values.addAll( Arrays.asList( empresas ) );
|
||||
empresasModel.setValues( values );
|
||||
}
|
||||
|
||||
public void valueChanged( ListSelectionEvent e )
|
||||
{
|
||||
Object source = e.getSource();
|
||||
if( e.getValueIsAdjusting() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( source.equals( empresasTable.getSelectionModel() ) )
|
||||
{
|
||||
carregarEstabelecimentos();
|
||||
}
|
||||
else if( source.equals( estabelecimentosTable.getSelectionModel() ) )
|
||||
{
|
||||
carregarTrabalhadores();
|
||||
}
|
||||
else if( source.equals( trabalhadoresTable.getSelectionModel() ) )
|
||||
{
|
||||
notifyListeners( e );
|
||||
}
|
||||
}
|
||||
|
||||
protected void carregarEstabelecimentos()
|
||||
{
|
||||
estabelecimentosTable.clearSelection();
|
||||
int selected = empresasTable.getSelectedRow();
|
||||
estabelecimentosModel.clearAll();
|
||||
if( selected > -1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer empresaID = ( ( ColumnizedMappable ) empresasModel.getRowAt( selected ) ).getID();
|
||||
ColumnizedMappable estabelecimentos[] = provider.getAllEstabelecimentosForEmpresa( empresaID);
|
||||
Vector values = estabelecimentosModel.getValues();
|
||||
values.addAll( Arrays.asList( estabelecimentos ) );
|
||||
estabelecimentosModel.setValues( values );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
DialogException.showExceptionMessage( ex, "Erro a carregar os estabelecimentos.", true );
|
||||
estabelecimentosModel.clearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void carregarTrabalhadores()
|
||||
{
|
||||
trabalhadoresTable.clearSelection();
|
||||
int selected = estabelecimentosTable.getSelectedRow();
|
||||
trabalhadoresModel.clearAll();
|
||||
if( selected > -1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer estabelecimentoID = ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( selected ) ).getID();
|
||||
ColumnizedMappable trabalhadores[] = provider.getAllTrabalhadoresForEstabelecimento( estabelecimentoID );
|
||||
Vector values = trabalhadoresModel.getValues();
|
||||
values.addAll( Arrays.asList( trabalhadores ) );
|
||||
trabalhadoresModel.setValues( values );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
DialogException.showExceptionMessage( ex, "Erro a carregar trabalhadores.", true );
|
||||
trabalhadoresModel.clearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void notifyListeners( ListSelectionEvent e )
|
||||
{
|
||||
for( int n = 0; n < listeners.size(); n++ )
|
||||
{
|
||||
ListSelectionEvent event =
|
||||
new ListSelectionEvent( this, e.getFirstIndex(), e.getLastIndex(), e.getValueIsAdjusting() );
|
||||
( ( ListSelectionListener ) listeners.elementAt( n ) ).valueChanged( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void addListSelectionListener( ListSelectionListener listener )
|
||||
{
|
||||
listeners.add( listener );
|
||||
}
|
||||
|
||||
public void removeSelectionListener( ListSelectionListener listener )
|
||||
{
|
||||
listeners.remove( listener );
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
// empresasTable.clearSelection();
|
||||
}
|
||||
|
||||
public void fill( Object value )
|
||||
{
|
||||
if( value == null )
|
||||
{
|
||||
clear();
|
||||
}
|
||||
Integer ids[] = ( Integer [] ) value;
|
||||
for( int n = 0; n < empresasTable.getRowCount(); n++ )
|
||||
{
|
||||
if( ( ( ColumnizedMappable ) empresasModel.getRowAt( n ) ).getID().equals( ids[ 0 ] ) )
|
||||
{
|
||||
empresasTable.setRowSelectionInterval( n, n );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( int n = 0; n < estabelecimentosTable.getRowCount(); n++ )
|
||||
{
|
||||
if( ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( n ) ).getID().equals( ids[ 1 ] ) )
|
||||
{
|
||||
estabelecimentosTable.setRowSelectionInterval( n, n );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( int n = 0; n < trabalhadoresTable.getRowCount(); n++ )
|
||||
{
|
||||
if( ( ( ColumnizedMappable ) trabalhadoresModel.getRowAt( n ) ).getID().equals( ids[ 2 ] ) )
|
||||
{
|
||||
trabalhadoresTable.setRowSelectionInterval( n, n );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object save()
|
||||
{
|
||||
int empresaSelected = empresasTable.getSelectedRow();
|
||||
int estabelecimentoSelected = estabelecimentosTable.getSelectedRow();
|
||||
int trabalhadorSelected = trabalhadoresTable.getSelectedRow();
|
||||
return new Integer[]{
|
||||
empresaSelected == -1 ? null : ( ( ColumnizedMappable ) empresasModel.getRowAt( empresaSelected ) ).getID(),
|
||||
estabelecimentoSelected == -1 ? null : ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( estabelecimentoSelected ) ).getID(),
|
||||
trabalhadorSelected == -1 ? null : ( ( ColumnizedMappable ) trabalhadoresModel.getRowAt( trabalhadorSelected ) ).getID()
|
||||
};
|
||||
}
|
||||
|
||||
public void setEnabled( boolean enable )
|
||||
{
|
||||
editing = !enable;
|
||||
empresasTable.setEnabled( enable );
|
||||
estabelecimentosTable.setEnabled( enable );
|
||||
trabalhadoresTable.setEnabled( enable );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* EstadoChooser.java
|
||||
*
|
||||
* Created on 13 de Maio de 2007, 11:54
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package siprp.medicina.processo.detalhes;
|
||||
|
||||
import com.evolute.utils.ui.CustomJDialog;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import siprp.medicina.MedicinaConstants;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Frederico
|
||||
*/
|
||||
public class EstadoChooser extends CustomJDialog
|
||||
implements MedicinaConstants, ActionListener
|
||||
{
|
||||
protected int tipo;
|
||||
protected int estado;
|
||||
protected HashMap<JButton,Integer> buttonMap;
|
||||
|
||||
/** Creates a new instance of EstadoChooser */
|
||||
public EstadoChooser( JFrame owner, int tipo, int estadoActual )
|
||||
{
|
||||
super( owner, true );
|
||||
this.tipo = tipo;
|
||||
estado = estadoActual;
|
||||
setupComponents();
|
||||
|
||||
if( owner != null )
|
||||
{
|
||||
centerSuper();
|
||||
}
|
||||
else
|
||||
{
|
||||
center();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupComponents()
|
||||
{
|
||||
setTitle( "Escolha o novo estado" );
|
||||
setLayout( new GridLayout( ESTADOS_STR[ tipo ].length, 1 ) );
|
||||
for( int n = 0; n < ESTADOS_STR[ tipo ].length; n++ )
|
||||
{
|
||||
JButton button = new JButton( ESTADOS_STR[ tipo ][ n ] );
|
||||
if( n == estado )
|
||||
{
|
||||
button.setForeground( Color.green );
|
||||
}
|
||||
buttonMap.put( button, new Integer( n ) );
|
||||
add( button );
|
||||
button.addActionListener( this );
|
||||
}
|
||||
pack();
|
||||
}
|
||||
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
JButton source = ( JButton ) e.getSource();
|
||||
estado = buttonMap.get( source ).intValue();
|
||||
close();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
SwingUtilities.invokeLater( new Runnable(){
|
||||
public void run()
|
||||
{
|
||||
setVisible( false );
|
||||
dispose();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
public int getEstado()
|
||||
{
|
||||
return estado;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* ObservacoesDialog.java
|
||||
*
|
||||
* Created on 13 de Maio de 2007, 13:13
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package siprp.medicina.processo.detalhes;
|
||||
|
||||
import com.evolute.utils.ui.CustomJDialog;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Frederico
|
||||
*/
|
||||
public class ObservacoesDialog extends CustomJDialog
|
||||
implements ActionListener
|
||||
{
|
||||
protected JTextArea observacoesText;
|
||||
protected JButton okButton;
|
||||
protected JButton cancelButton;
|
||||
|
||||
protected boolean ok = false;
|
||||
|
||||
public static void main( String args[] )
|
||||
{
|
||||
ObservacoesDialog dialog = new ObservacoesDialog( null );
|
||||
dialog.editarObservacao( "ISto e a observba" );
|
||||
System.exit( 0 );
|
||||
}
|
||||
|
||||
/** Creates a new instance of ObservacoesDialog */
|
||||
public ObservacoesDialog( JFrame owner )
|
||||
{
|
||||
super( owner, true );
|
||||
setupComponents();
|
||||
|
||||
if( owner != null )
|
||||
{
|
||||
centerSuper();
|
||||
}
|
||||
else
|
||||
{
|
||||
center();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupComponents()
|
||||
{
|
||||
setTitle( "Coment\u00e1rio" );
|
||||
setSize( 400, 200 );
|
||||
observacoesText = new JTextArea();
|
||||
observacoesText.setLineWrap( true );
|
||||
observacoesText.setWrapStyleWord( true );
|
||||
JScrollPane scp = new JScrollPane( observacoesText,
|
||||
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||
okButton = new JButton( "Ok" );
|
||||
okButton.addActionListener( this );
|
||||
cancelButton = new JButton( "Cancelar" );
|
||||
cancelButton.addActionListener( this );
|
||||
JPanel buttonPanel = new JPanel();
|
||||
|
||||
setLayout( new BorderLayout() );
|
||||
add( scp, BorderLayout.CENTER );
|
||||
add( buttonPanel, BorderLayout.SOUTH );
|
||||
|
||||
buttonPanel.setLayout( new GridLayout( 1, 2 ) );
|
||||
buttonPanel.add( okButton );
|
||||
buttonPanel.add( cancelButton );
|
||||
}
|
||||
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
Object source = e.getSource();
|
||||
if( source.equals( okButton ) )
|
||||
{
|
||||
ok = true;
|
||||
close();
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public String editarObservacao( String observacao )
|
||||
{
|
||||
observacoesText.setText( observacao );
|
||||
setVisible( true );
|
||||
return ok ? observacoesText.getText() : null;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
SwingUtilities.invokeLater( new Runnable(){
|
||||
public void run()
|
||||
{
|
||||
setVisible( false );
|
||||
dispose();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue