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.
		
		
		
		
		
			
		
			
				
					
					
						
							196 lines
						
					
					
						
							6.1 KiB
						
					
					
				
			
		
		
	
	
							196 lines
						
					
					
						
							6.1 KiB
						
					
					
				/*
 | 
						|
 * EstruturaProcessoPanel.java
 | 
						|
 *
 | 
						|
 * Created on March 20, 2007, 12:07 PM
 | 
						|
 *
 | 
						|
 * To change this template, choose Tools | Template Manager
 | 
						|
 * and open the template in the editor.
 | 
						|
 */
 | 
						|
 | 
						|
package siprp.medicina.processo.estrutura;
 | 
						|
 | 
						|
import com.evolute.utils.data.IDObject;
 | 
						|
import com.evolute.utils.data.MappableObject;
 | 
						|
import com.evolute.utils.ui.DialogException;
 | 
						|
import java.awt.*;
 | 
						|
import java.text.DateFormat;
 | 
						|
import java.util.Date;
 | 
						|
import java.util.HashMap;
 | 
						|
import java.util.Locale;
 | 
						|
import java.util.Vector;
 | 
						|
import javax.swing.*;
 | 
						|
import javax.swing.event.TreeSelectionEvent;
 | 
						|
import javax.swing.event.TreeSelectionListener;
 | 
						|
import javax.swing.tree.DefaultMutableTreeNode;
 | 
						|
import javax.swing.tree.TreePath;
 | 
						|
import siprp.medicina.processo.*;
 | 
						|
import siprp.medicina.processo.data.MarcacoesProcessoData;
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @author fpalma
 | 
						|
 */
 | 
						|
public class EstruturaProcessoPanel extends JPanel
 | 
						|
		implements TreeSelectionListener
 | 
						|
{
 | 
						|
	protected static final DateFormat D_F = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) );
 | 
						|
	
 | 
						|
	protected JScrollPane mainScroll;
 | 
						|
	protected DefaultMutableTreeNode rootNode;
 | 
						|
	protected JTree mainTree;
 | 
						|
	
 | 
						|
	protected ProcessoDataProvider provider;
 | 
						|
	
 | 
						|
	protected IDObject trabalhador;
 | 
						|
	protected final HashMap<Integer,MarcacoesProcessoData> PROCESSOS_POR_ID = 
 | 
						|
			new HashMap<Integer,MarcacoesProcessoData>();
 | 
						|
	
 | 
						|
	private final Vector<ProcessoListener> PROCESSO_LISTENERS = new Vector<ProcessoListener>();
 | 
						|
	
 | 
						|
	/** Creates a new instance of EstruturaProcessoPanel */
 | 
						|
	public EstruturaProcessoPanel()
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		provider = ProcessoDataProvider.getProvider();
 | 
						|
		setupComponents();
 | 
						|
		setTrabalhador( new MappableObject( new Integer( 12 ), "Alexandre de Matos Monge" ) );
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void setupComponents()
 | 
						|
	{
 | 
						|
		mainScroll = new JScrollPane();
 | 
						|
		mainScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
 | 
						|
		mainScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
 | 
						|
//		rootNode = new DefaultMutableTreeNode( new MappableObject( new Integer( 12 ), "Frederico Palma" ) );
 | 
						|
		rootNode = new TrabalhadorMutableTreeNode( new Integer( 12 ), "Frederico Palma" );
 | 
						|
		mainTree = new JTree( rootNode );
 | 
						|
		mainTree.addTreeSelectionListener( this );
 | 
						|
		mainTree.setCellRenderer( new EstruturaProcessoRenderer() );
 | 
						|
		mainScroll.setViewportView( mainTree );
 | 
						|
		setLayout( new GridLayout( 1, 1 ) );
 | 
						|
		add( mainScroll );
 | 
						|
		
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void setTrabalhador( IDObject trabalhador )
 | 
						|
	{
 | 
						|
		this.trabalhador = trabalhador;
 | 
						|
//		rootNode.removeAllChildren();
 | 
						|
//		PROCESSOS_POR_ID.clear();
 | 
						|
//		rootNode.setUserObject( trabalhador );
 | 
						|
//		DefaultMutableTreeNode nodes[] = 
 | 
						|
//				loadProcessos( trabalhador.getID() );
 | 
						|
//		rootNode.add( new DefaultMutableTreeNode( new MappableObject( new Integer( -1 ), "Novo Processo..." ) ) );
 | 
						|
//		for( int n = 0; n < nodes.length; n++ )
 | 
						|
//		{
 | 
						|
//			rootNode.add( nodes[ n ] );
 | 
						|
//		}
 | 
						|
//		int count = mainTree.getRowCount();
 | 
						|
//		for( int n = count - 1; n >= 0; n-- )
 | 
						|
//		{
 | 
						|
//			mainTree.expandRow( n );
 | 
						|
//		}
 | 
						|
		
 | 
						|
		ProcessoMutableTreeNode p1 = new ProcessoMutableTreeNode( new Integer( 1 ), "Ocasional" );
 | 
						|
		rootNode.add( p1 );
 | 
						|
		ECDsMutableTreeNode e1 = new ECDsMutableTreeNode( new Integer( 2 ), "ECDs" );
 | 
						|
		p1.add( e1 );
 | 
						|
		DataMutableTreeNode d1 = new DataMutableTreeNode( new Integer( 8 ), "2006/01/01" );
 | 
						|
		e1.add( d1 );
 | 
						|
		ObservacoesMutableTreeNode o1 = new ObservacoesMutableTreeNode( new Integer( 16 ), "N\u00e3o apareceu" );
 | 
						|
		d1.add( o1 );
 | 
						|
		MailMutableTreeNode m1 = new MailMutableTreeNode( new Integer( 35 ), "teste@123.com" );
 | 
						|
		d1.add( m1 );
 | 
						|
		
 | 
						|
		DataMutableTreeNode d2 = new DataMutableTreeNode( new Integer( 8 ), "2006/04/01" );
 | 
						|
		e1.add( d2 );
 | 
						|
		MailMutableTreeNode m2 = new MailMutableTreeNode( new Integer( 35 ), "teste@123.com" );
 | 
						|
		d2.add( m2 );
 | 
						|
		
 | 
						|
		ConsultaMutableTreeNode c1 = new ConsultaMutableTreeNode( new Integer( 2 ), "Consulta" );
 | 
						|
		p1.add( c1 );
 | 
						|
		DataMutableTreeNode d3 = new DataMutableTreeNode( new Integer( 8 ), "2006/05/01" );
 | 
						|
		c1.add( d3 );
 | 
						|
		MailMutableTreeNode m3 = new MailMutableTreeNode( new Integer( 35 ), "teste@123.com" );
 | 
						|
		c1.add( m3 );
 | 
						|
		
 | 
						|
		FichaAptidaoMutableTreeNode f1 = new FichaAptidaoMutableTreeNode( new Integer( 1 ), "Ficha de Aptid\u00e3o - Apto" );
 | 
						|
		p1.add( f1 );
 | 
						|
		
 | 
						|
		repaint();
 | 
						|
	}
 | 
						|
	
 | 
						|
	protected DefaultMutableTreeNode[] loadProcessos( Integer trabalhadorID )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			Integer ids[] = provider.getIDsProcessosByTrabalhador( trabalhadorID );
 | 
						|
			DefaultMutableTreeNode nodes[] = new DefaultMutableTreeNode[ ids.length ];
 | 
						|
			for( int n = 0; n < ids.length; n++ )
 | 
						|
			{
 | 
						|
				MarcacoesProcessoData processo = provider.getProcessoByID( ids[ n ] );
 | 
						|
				Date dataInicio = ( Date ) processo.get( MarcacoesProcessoData.DATA_INICIO );
 | 
						|
				Date dataFim = ( Date ) processo.get( MarcacoesProcessoData.DATA_FIM );
 | 
						|
				String codigoEstado = ( String ) processo.get( MarcacoesProcessoData.ESTADO );
 | 
						|
				String estado = provider.getDescricaoEstadoProcessoByCodigo( codigoEstado );
 | 
						|
				String desc = D_F.format( dataInicio );
 | 
						|
				if( dataFim != null )
 | 
						|
				{
 | 
						|
					desc += " - " + D_F.format( dataFim );
 | 
						|
				}
 | 
						|
				desc += ": " + estado;
 | 
						|
				IDObject processoObject = 
 | 
						|
						new MappableObject( ids[ n ], desc );
 | 
						|
				nodes[ n ] = new DefaultMutableTreeNode( processoObject );
 | 
						|
				PROCESSOS_POR_ID.put( ids[ n ], processo );
 | 
						|
			}
 | 
						|
			return nodes;
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			DialogException.showExceptionMessage( ex, "Erro a carregar dados", true );
 | 
						|
			return new DefaultMutableTreeNode[ 0 ];
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void valueChanged(TreeSelectionEvent e)
 | 
						|
	{
 | 
						|
		
 | 
						|
	}
 | 
						|
	
 | 
						|
	public MarcacoesProcessoData getProcessoEscolhido()
 | 
						|
	{
 | 
						|
		TreePath path = mainTree.getSelectionPath();
 | 
						|
		MarcacoesProcessoData processo = null;
 | 
						|
		if( path != null )
 | 
						|
		{
 | 
						|
			IDObject escolhido = ( IDObject )( ( DefaultMutableTreeNode ) path.getLastPathComponent() ).getUserObject();
 | 
						|
			if( escolhido != null )
 | 
						|
			{
 | 
						|
				processo = PROCESSOS_POR_ID.get( escolhido.getID() );
 | 
						|
				if( processo == null )
 | 
						|
				{
 | 
						|
					processo = new MarcacoesProcessoData();
 | 
						|
					PROCESSOS_POR_ID.put( escolhido.getID(), processo );
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		
 | 
						|
		return processo;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void addProcessoListener( ProcessoListener listener )
 | 
						|
	{
 | 
						|
		PROCESSO_LISTENERS.add( listener );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public IDObject getTrabalhador()
 | 
						|
	{
 | 
						|
		return trabalhador;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void reload()
 | 
						|
	{
 | 
						|
	}
 | 
						|
}
 |