/*
 * SIPRPTracker.java
 *
 * Created on 18 de Maio de 2004, 19:46
 */

package siprp;

import javax.swing.tree.*;
import java.util.*;

import com.evolute.utils.*;
import com.evolute.utils.tracker.*;
import siprp.ficha.*;
import siprp.clientes.*;
import siprp.estatistica.*;
import siprp.higiene.mapa.*;
import siprp.higiene.marcacoes.*;
import siprp.impressaofichas.*;
import siprp.lembretes.LembretesWindow;
import siprp.medicina.*;
import siprp.medicina.locais_realizacao.LocaisRealizacaoWindow;
import siprp.medicina.presencas.RegistarPresencasWindow;
import siprp.medicina.prestadores.PrestadoresWindow;
import siprp.medicina.processo.ProcessoWindow;
import siprp.pesquisas.*;
/**
 *
 * @author  fpalma
 */
public class SIPRPTracker extends WindowTracker
{
	public static final String FICHA_APTIDAO = "Ficha de Aptid\u00e3o";
	public static final String CRIACAO_FICHA_APTIDAO = "Cria\u00e7\u00e3o de Fichas de Aptid\u00e3o";
	public static final String GESTAO_CLIENTES = "Gest\u00e3o de Clientes";
	public static final String MEDICINA = "Medicina";
	public static final String MEDICINA_MARCACOES = "Marca\u00e7\u00f5es";
	public static final String MEDICINA_LOCAIS = "Locais de Realiza\u00e7\u00e3o";
	public static final String MEDICINA_PRESENCAS = "Presen\u00e7as";
	public static final String HIGIENE_SEGURANCA = "Higiene e Seguran\u00e7a";
	public static final String RELATORIO_ANUAL = "Relat\u00f3rio Anual";
	public static final String LISTAGENS = "Listagens";
	
	private final AvisosPanel avisos;
	private ClientesWindow clientesWindow;
	private MedicinaWindow medicinaWindow;
	private MarcacoesHigieneWindow higieneWindow;
	
	/** Creates a new instance of SIPRPTracker */
	public SIPRPTracker( AvisosPanel avisosP )
	{
		Singleton.setInstance( SingletonConstants.SIPRP_TRACKER, this );
		this.avisos = avisosP;
		avisos.setTracker( this );
		Hashtable creators = new Hashtable();
		DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode( 
			Singleton.getInstance( SingletonConstants.COMPANY_ACRONYM ) );
		
		boolean hasFicha = ( (Boolean)Singleton.getInstance( SingletonConstants.MODULE_FICHA ) ).booleanValue();
		boolean hasGestao = ( (Boolean)Singleton.getInstance( SingletonConstants.MODULE_CLIENTES ) ).booleanValue();
		boolean hasRelatorio = ( (Boolean)Singleton.getInstance( SingletonConstants.MODULE_RELATORIO ) ).booleanValue();
		boolean hasListagens = ( (Boolean)Singleton.getInstance( SingletonConstants.MODULE_LISTAGENS ) ).booleanValue();
		
		if( hasGestao )
		{
			try
			{
				clientesWindow = new ClientesWindow( avisos );
				clientesWindow.setTracker( this );
				medicinaWindow = new MedicinaWindow();
				medicinaWindow.setTracker( this );
				higieneWindow = new MarcacoesHigieneWindow();
				higieneWindow.setTracker( this );
			}
			catch( Exception ex )
			{
				clientesWindow = null;
				medicinaWindow = null;
				higieneWindow = null;
				ex.printStackTrace();
			}
		}
		else
		{
			clientesWindow = null;
			medicinaWindow = null;
		}
		
		if( hasFicha )
		{
			DefaultMutableTreeNode fichaNode = new DefaultMutableTreeNode( FICHA_APTIDAO );
			
			fichaNode.add( new DefaultMutableTreeNode( CRIACAO_FICHA_APTIDAO ) );
			creators.put( CRIACAO_FICHA_APTIDAO, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return FichaWindow.getWindow();
					}
				} );
				
			fichaNode.add( new DefaultMutableTreeNode( ImpressaoFichasWindow.TITLE ) );
			creators.put( ImpressaoFichasWindow.TITLE, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new ImpressaoFichasWindow();
					}
				} );
	
			rootNode.add( fichaNode );
		}
		
		if( hasGestao )
		{
			rootNode.add( new DefaultMutableTreeNode( GESTAO_CLIENTES ) );
			creators.put( GESTAO_CLIENTES, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						if( clientesWindow == null )
						{
							clientesWindow = new ClientesWindow( avisos );
							clientesWindow.setTracker( SIPRPTracker.this );
						}
						return clientesWindow;
					}
				} );
				
			rootNode.add( new DefaultMutableTreeNode( LembretesWindow.TITLE ) );
			creators.put( LembretesWindow.TITLE, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new LembretesWindow();
					}
				} );
			
			DefaultMutableTreeNode medicinaNode = new DefaultMutableTreeNode( MEDICINA );
			
			medicinaNode.add( new DefaultMutableTreeNode( ProcessoWindow.TITLE ) );
			creators.put( ProcessoWindow.TITLE, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new ProcessoWindow();
					}
				} );
			
			medicinaNode.add( new DefaultMutableTreeNode( MEDICINA_MARCACOES ) );
			creators.put( MEDICINA_MARCACOES, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						if( medicinaWindow == null )
						{
							medicinaWindow = new MedicinaWindow();
							medicinaWindow.setTracker( SIPRPTracker.this );
						}
						return medicinaWindow;
					}
				} );
				
			medicinaNode.add( new DefaultMutableTreeNode( MEDICINA_LOCAIS ) );
			creators.put( MEDICINA_LOCAIS, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new LocaisRealizacaoWindow();
					}
				} );
				
			medicinaNode.add( new DefaultMutableTreeNode( MEDICINA_PRESENCAS ) );
			creators.put( MEDICINA_PRESENCAS, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new RegistarPresencasWindow();
					}
				} );
				
			medicinaNode.add( new DefaultMutableTreeNode( PrestadoresWindow.TITLE ) );
			creators.put( PrestadoresWindow.TITLE, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new PrestadoresWindow();
					}
				} );
				
			rootNode.add( medicinaNode );
				
			DefaultMutableTreeNode higieneNode = new DefaultMutableTreeNode( HIGIENE_SEGURANCA );
			
			higieneNode.add( new DefaultMutableTreeNode( MarcacoesHigieneWindow.TITLE ) );
			creators.put( MarcacoesHigieneWindow.TITLE, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						if( higieneWindow == null )
						{
							higieneWindow = new MarcacoesHigieneWindow();
							higieneWindow.setTracker( SIPRPTracker.this );
						}
						return higieneWindow;
					}
				} );
				
			higieneNode.add( new DefaultMutableTreeNode( MapaHigieneWindow.TITLE ) );
			creators.put( MapaHigieneWindow.TITLE, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new MapaHigieneWindow();
					}
				} );
				
			rootNode.add( higieneNode );
		}
		
		if( hasRelatorio )
		{
		rootNode.add( new DefaultMutableTreeNode( RELATORIO_ANUAL ) );
		creators.put( RELATORIO_ANUAL, new WindowCreator() {
				public TrackableWindow create()
					throws Exception
				{
					return new PesquisasWindow();
				}
			} );
		}
		
		if( hasListagens )
		{
			rootNode.add( new DefaultMutableTreeNode( LISTAGENS ) );
			creators.put( LISTAGENS, new WindowCreator() {
					public TrackableWindow create()
						throws Exception
					{
						return new EstatisticaWindow();
					}
				} );
		}
		setRoot( rootNode );
		setCreators( creators );
	}
	
	public ClientesWindow getClientesWindow()
	{
		return clientesWindow;
	}
	
	public MedicinaWindow getMedicinaWindow()
	{
		return medicinaWindow;
	}
	
	public MarcacoesHigieneWindow getHigieneWindow()
	{
		return higieneWindow;
	}
	
	public AvisosPanel getAvisosPanel()
	{
		return avisos;
	}
}
