package cl.jtv;
/*
 * NodeTreeMachine.java
 *
 * Created on 17 de enero de 2003, 04:51 PM
 */

/**
 *
 * @author  Administrador
 * @version 
 */
import javax.swing.tree.*;
import java.util.*;


public class NodeTreeMachine extends javax.swing.tree.DefaultMutableTreeNode {

    public Vector2 vector2;
    public Maquina maquina;
    private DefaultTreeModel treeModel;
    public static boolean copy=false;
    /** Creates new NodeTreeMachine */
    public NodeTreeMachine(String name,Vector2 vector2) {
        
        super(name);
        vector2 = vector2;
        
    }
    
    public NodeTreeMachine() {
        
        super();
               
    }
    
    public NodeTreeMachine(String name) {
        
        super(name);
               
    }
    
    /** Getter for property treeModel.
     * @return Value of property treeModel.
     */
    public DefaultTreeModel getTreeModel() {
        return treeModel;
    }    
    
    /** Setter for property treeModel.
     * @param treeModel New value of property treeModel.
     */
    public void setTreeModel(DefaultTreeModel treeModel) {
        this.treeModel = treeModel;
    }
    
    
    public void insertMachines(DefaultTreeModel treeModel,Hashtable dicOfMachinesParse){
        
        //OBTENGO LA SUBMAQUINAS QUE PUEDE INVOCAR
        Vector calledMachines = Vector2.getCalledMachines(vector2.getNombreLargo(),dicOfMachinesParse);
        dicOfMachinesParse.remove(vector2.getNombreLargo());
        //INSERTO LOS NODOS
        Enumeration en = calledMachines.elements();
        while(en.hasMoreElements()){
            Vector2 vector2 = (Vector2)en.nextElement();
            NodeTreeMachine newChild = new NodeTreeMachine(vector2.getNombreLargo());
            newChild.vector2 = vector2;
            newChild.maquina = null;
            treeModel.insertNodeInto(newChild,this,this.getChildCount());
            newChild.insertMachines(treeModel,dicOfMachinesParse);
        }
    }
    
    public void refreshUserObject(){
           
            this.setUserObject(vector2.getNombreLargo());
    }
    
    public void refreshChildDependences(){
        
        Enumeration en = this.children();
        while(en.hasMoreElements()){
            NodeTreeMachine child = (NodeTreeMachine)en.nextElement();
            child.vector2.setDependencia((String)this.getUserObject());            
        }      
    }
        

}
