//
//  NomenclaturaInterfaceController.java
//  Structure
//
//  Created by Luc-Henri Barthélémy on Fri Oct 20 2006.
//  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
//

package Structure.client;

import com.webobjects.foundation.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoapplication.*;
import com.webobjects.eointerface.*;
import com.webobjects.eointerface.swing.*;

import javax.swing.*;


public class NomenclaturaInterfaceController extends EOInterfaceController {
	
	public EOFrame listWD;
	public EOFrame editWD,searchSonWD;
	public EODisplayGroup filsDG;
	public EODisplayGroup peresDG;
	public JButton selectItemFilsBT;
		
	//protected ChoixNomenclaturaIC choixFils;



    public NomenclaturaInterfaceController() {
        super();
    }

    public NomenclaturaInterfaceController(EOEditingContext substitutionEditingContext) {
        super(substitutionEditingContext);
    }
	
	public void connectionWasEstablished()
	{
		super.connectionWasEstablished();
        //editWD.setLocationRelativeTo(component());
		editWD.setVisible(true);
		ClicAndCloseButtonController myCAndC = new ClicAndCloseButtonController(selectItemFilsBT);
	}
	
	public void browseSon()
	{
		
		ChoixNomenclaturaIC choixFils;
		
		EOFrameController myFrame = new EOFrameController();
		
		choixFils = new ChoixNomenclaturaIC(editingContext(),"Racine",filsDG, myFrame);
		
		// ces ChoixNomenclaturaIC doivent etre disposes en cas de fermeture de cet objet
		disposableRegistry().addObject(choixFils);
		
		myFrame.setComponent(choixFils.component());
		choixFils.establishConnection();
		choixFils.setMethodeRetour("son");
		((JFrame)myFrame.window()).setResizable(true);
		((JFrame)myFrame.window()).setLocationRelativeTo(editWD);
		myFrame.activateWindow();
	}
	
	public void searchSon()
	{
		
		searchSonWD.setVisible(true);
        searchSonWD.setLocationRelativeTo(editWD);
	}

	
	public void addSonAndBrowse()
	{
		//filsDG.insert();
		//choixSon();
		browseSon();
		if(displayGroup().selectedObject() != null)
			UserInfo.addToObjectsToInvalidate((EOGenericRecord)displayGroup().selectedObject());
	}
	
	public void addSonAndSearch()
	{
		//filsDG.insert();
		searchSon();
		//browseSon();
		if(displayGroup().selectedObject() != null)
			UserInfo.addToObjectsToInvalidate((EOGenericRecord)displayGroup().selectedObject());
	}
	
	/**
	public void add()
	{
		//individuDG.fetch();
		//panelSetLoc(individuPanel,mainWD());
		if(useModal== false)
		{
			panelSetLoc(individuPanel,mainWD);
			individuPanel.setVisible(true);
		}
		else
			initChoixModal(individuPanel,"Choix d'un membre");
		
	}
	**/
	
	public void addSon()
	{
		filsDG.insert();
	}
	
	public void deleteSon()
	{
		if(filsDG.selectedObject()!=null)
		{
			filsDG.deleteSelection();
			UserInfo.addToObjectsToInvalidate((EOGenericRecord)displayGroup().selectedObject());
		}
	}
	
	public boolean editSonsAllowed()
	{
		if(editAllowed() && displayGroup().selectedObject()!=null)
		{
			return true;
		}
		else
			return false;
	}
	
	public boolean editAllowed()
	{
		if(UserInfo.isGrhumCreator() || (UserInfo.Agent() != null && (UserInfo.Agent().isSuperUser())) )
			return true;
		else
			return false;
	}
	
	public boolean alwaysDisabled()
	{
		return false;
	}
	
	
	public boolean editSonAllowed()
	{
		if(editAllowed() && filsDG.selectedObject()!=null)
		{
			return true;
		}
		else
			return false;
	}
	
	public void displayGroupDidChangeSelection(EODisplayGroup group)
	{
		
		//NSLog.out.appendln("displayGroupDidChangeSelection Fournisseur");
		_notify_associations(controllerDisplayGroup());
	}
	

	/**	
	public void addFat()
	{
		peresDG.insert();
		choixSon();
		if(displayGroup().selectedObject() != null)
			UserInfo.addToObjectsToInvalidate((EOGenericRecord)displayGroup().selectedObject());
	}
	
	public void deleteFat()
	{
		if(peresDG.selectedObject()!=null)
		{
			peresDG.deleteSelection();
			UserInfo.addToObjectsToInvalidate((EOGenericRecord)displayGroup().selectedObject());
		}
	}

	**/
	
	public void addLibel()
	{
		displayGroup().insert();
	}
	
	public void deleteLibel()
	{
		displayGroup().deleteSelection();
	}
	
	
	//
	// Ce truc sert a rafraichir les champs
	//
	// a passer avec la methode suivante ds une super classe
	// commune a ts les interfaceControllers
	//
	protected void _notify_associations (EODisplayGroup  
										 a_display_group) {
		java.util.Enumeration en = a_display_group.observingAssociations ().objectEnumerator();
		while (en.hasMoreElements ()) {
			EOAssociation myAss = (EOAssociation)en.nextElement();
			myAss.subjectChanged ();
		}
		//a_display_group.redisplay();
		a_display_group.updateDisplayedObjects();
	}
	
	
}
