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.
		
		
		
		
		
			
		
			
				
					
					
						
							184 lines
						
					
					
						
							5.1 KiB
						
					
					
				
			
		
		
	
	
							184 lines
						
					
					
						
							5.1 KiB
						
					
					
				/*
 | 
						|
 * EscolherMotivoDialog.java
 | 
						|
 *
 | 
						|
 * Created on 13 de Maio de 2007, 22:16
 | 
						|
 *
 | 
						|
 * To change this template, choose Tools | Template Manager
 | 
						|
 * and open the template in the editor.
 | 
						|
 */
 | 
						|
 | 
						|
package siprp.medicina.processo;
 | 
						|
 | 
						|
import com.evolute.utils.data.IDObject;
 | 
						|
import com.evolute.utils.data.MappableObject;
 | 
						|
import com.evolute.utils.ui.CustomJDialog;
 | 
						|
import java.awt.Dimension;
 | 
						|
import java.awt.FlowLayout;
 | 
						|
import java.awt.GridLayout;
 | 
						|
import java.awt.event.ActionEvent;
 | 
						|
import java.awt.event.ActionListener;
 | 
						|
import java.util.HashMap;
 | 
						|
import javax.swing.AbstractButton;
 | 
						|
import javax.swing.JButton;
 | 
						|
import javax.swing.JFrame;
 | 
						|
import javax.swing.JPanel;
 | 
						|
import javax.swing.JToggleButton;
 | 
						|
import javax.swing.SwingUtilities;
 | 
						|
import siprp.medicina.MedicinaConstants;
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @author Frederico
 | 
						|
 */
 | 
						|
public class EscolherMotivoDialog extends CustomJDialog
 | 
						|
	implements ActionListener, MedicinaConstants
 | 
						|
{
 | 
						|
	protected IDObject MOTIVOS[] = 
 | 
						|
		new IDObject[]{
 | 
						|
			new MappableObject( MOTIVO_ADMISSAO_INTEGER, MOTIVO_ADMISSAO_STR ), 
 | 
						|
			new MappableObject( MOTIVO_PERIODICO_INTEGER, MOTIVO_PERIODICO_STR ),
 | 
						|
			new MappableObject( MOTIVO_PERIODICO_INICIAL_INTEGER, MOTIVO_PERIODICO_INICIAL_STR ),
 | 
						|
			new MappableObject( MOTIVO_OCASIONAL_INTEGER, MOTIVO_OCASIONAL_STR )
 | 
						|
	};
 | 
						|
 | 
						|
	protected IDObject SUB_MOTIVOS[][] = 
 | 
						|
		new IDObject[][]{
 | 
						|
			{},
 | 
						|
			{},
 | 
						|
			{},
 | 
						|
			{ new MappableObject( SUB_MOTIVO_APOS_DOENCA_INTEGER, SUB_MOTIVO_APOS_DOENCA_STR ), 
 | 
						|
				new MappableObject( SUB_MOTIVO_APOS_ACIDENTE_INTEGER, SUB_MOTIVO_APOS_ACIDENTE_STR ),
 | 
						|
				new MappableObject( SUB_MOTIVO_PEDIDO_TRABALHADOR_INTEGER, SUB_MOTIVO_PEDIDO_TRABALHADOR_STR ), 
 | 
						|
				new MappableObject( SUB_MOTIVO_PEDIDO_SERVICO_INTEGER, SUB_MOTIVO_PEDIDO_SERVICO_STR ),
 | 
						|
				new MappableObject( SUB_MOTIVO_MUDANCA_FUNCAO_INTEGER, SUB_MOTIVO_MUDANCA_FUNCAO_STR ),
 | 
						|
				new MappableObject( SUB_MOTIVO_ALTERACAO_CONDICOES_INTEGER, SUB_MOTIVO_ALTERACAO_CONDICOES_STR ),
 | 
						|
				new MappableObject( SUB_MOTIVO_OUTRO_INTEGER, SUB_MOTIVO_OUTRO_STR )
 | 
						|
			}
 | 
						|
	};
 | 
						|
	
 | 
						|
	protected AbstractButton motivoButtons[];
 | 
						|
	protected HashMap<AbstractButton,JButton[]> subMotivoButtons;
 | 
						|
	protected HashMap<AbstractButton,Integer> motivoButtonIDs;
 | 
						|
	protected HashMap<JButton,Integer> subMotivoButtonIDs;
 | 
						|
	protected JPanel motivoPanel;
 | 
						|
	protected JPanel subMotivoPanel;
 | 
						|
	
 | 
						|
	protected Integer motivoTemp;
 | 
						|
	protected Integer motivo;
 | 
						|
	protected Integer subMotivo;
 | 
						|
	
 | 
						|
	/** Creates a new instance of EscolherMotivoDialog */
 | 
						|
	public EscolherMotivoDialog( JFrame owner )
 | 
						|
	{
 | 
						|
		super( owner, true );
 | 
						|
		setupComponents();
 | 
						|
		
 | 
						|
		if( owner != null )
 | 
						|
		{
 | 
						|
			centerSuper();
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			center();
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void setupComponents()
 | 
						|
	{
 | 
						|
		setTitle( "Escolher Motivo" );
 | 
						|
		setLayout( new FlowLayout( FlowLayout.LEFT ) );
 | 
						|
		motivoButtons = new JToggleButton[ MOTIVOS.length ];
 | 
						|
		subMotivoButtons = new HashMap<AbstractButton,JButton[]>();
 | 
						|
		motivoButtonIDs = new HashMap<AbstractButton,Integer>();
 | 
						|
		subMotivoButtonIDs = new HashMap<JButton,Integer>();
 | 
						|
		for( int m = 0; m < MOTIVOS.length; m++ )
 | 
						|
		{
 | 
						|
			JToggleButton motivoButton = new JToggleButton( MOTIVOS[ m ].toString() );
 | 
						|
			motivoButton.addActionListener( this );
 | 
						|
			motivoButtonIDs.put( motivoButton, MOTIVOS[ m ].getID() );
 | 
						|
			motivoButton.setPreferredSize( new Dimension( 250, 20 ) );
 | 
						|
			motivoButtons[ m ] = motivoButton;
 | 
						|
			if( SUB_MOTIVOS[ m ].length > 0 )
 | 
						|
			{
 | 
						|
				JButton subButtons[] = new JButton[ SUB_MOTIVOS[ m ].length ];
 | 
						|
				for( int sm = 0; sm < SUB_MOTIVOS[ m ].length; sm++ )
 | 
						|
				{
 | 
						|
					JButton subButton = new JButton( SUB_MOTIVOS[ m ][ sm ].toString() );
 | 
						|
					subMotivoButtonIDs.put( subButton, SUB_MOTIVOS[ m ][ sm ].getID() );
 | 
						|
					subButtons[ sm ] = subButton;
 | 
						|
					subButton.setPreferredSize( new Dimension( 300, 20 ) );
 | 
						|
					subButton.addActionListener( this );
 | 
						|
				}
 | 
						|
				subMotivoButtons.put( motivoButton, subButtons );
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				subMotivoButtons.put( motivoButton, null );
 | 
						|
			}
 | 
						|
		}
 | 
						|
		motivoPanel = new JPanel();
 | 
						|
		subMotivoPanel = new JPanel();
 | 
						|
		
 | 
						|
		motivoPanel.setLayout( new GridLayout( motivoButtons.length + 1, 1 ) );
 | 
						|
		for( int n = 0; n < motivoButtons.length; n++ )
 | 
						|
		{
 | 
						|
			motivoPanel.add( motivoButtons[ n ] );
 | 
						|
		}
 | 
						|
		
 | 
						|
		add( motivoPanel );
 | 
						|
		add( subMotivoPanel );
 | 
						|
		
 | 
						|
		pack();
 | 
						|
	}
 | 
						|
 | 
						|
	public void actionPerformed(ActionEvent e)
 | 
						|
	{
 | 
						|
		AbstractButton source = ( AbstractButton ) e.getSource();
 | 
						|
		if( motivoButtonIDs.containsKey( source ) )
 | 
						|
		{
 | 
						|
			motivoTemp = motivoButtonIDs.get( source );
 | 
						|
		}
 | 
						|
		else if( subMotivoButtonIDs.containsKey( source ) )
 | 
						|
		{
 | 
						|
			motivo = motivoTemp;
 | 
						|
			subMotivo = subMotivoButtonIDs.get( source );
 | 
						|
			close();
 | 
						|
		}
 | 
						|
		if( subMotivoButtons.containsKey( source ) )
 | 
						|
		{
 | 
						|
			JButton subButtons[] = subMotivoButtons.get( source );
 | 
						|
			if( subButtons == null || subButtons.length == 0 )
 | 
						|
			{
 | 
						|
				motivo = motivoTemp;
 | 
						|
				close();
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				subMotivoPanel.removeAll();
 | 
						|
				subMotivoPanel.setLayout( new GridLayout( 0, 1 ) );
 | 
						|
				for( int n = 0; n < subButtons.length; n++ )
 | 
						|
				{
 | 
						|
					subMotivoPanel.add( subButtons[ n ] );
 | 
						|
				}
 | 
						|
				pack();
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	protected void close()
 | 
						|
	{
 | 
						|
		SwingUtilities.invokeLater( new Runnable(){
 | 
						|
			public void run()
 | 
						|
			{
 | 
						|
				setVisible( false );
 | 
						|
				dispose();
 | 
						|
			}
 | 
						|
		} );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public Integer[] getMotivo()
 | 
						|
	{
 | 
						|
		return new Integer[]{ motivo, subMotivo };
 | 
						|
	}
 | 
						|
}
 |