package traduccion;

import java.util.Vector;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.w3c.dom.*;

/**
 * <p>Title: Generación de Coreografías de Servicios Web</p>
 *
 * <p>Description: Clase que genera el modelo necesario para la visualización
 * de documentos en formato de árbol </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: UCLM</p>
 *
 * @version 1.0
 */
public class ToolTreeModel implements TreeModel {
    private Document doc;
        private Vector<TreeModelListener> listenerList;
        public ToolTreeModel(Document d){
                doc=d;
                listenerList=new Vector<TreeModelListener>();
        }

       public Object getRoot() {
               // TODO Auto-generated method stub
               ToolNode root=new ToolNode(doc.getLastChild());
               return root;
       }

       public Object getChild(Object parent, int index) {
               // TODO Auto-generated method stub
               ToolNode n=(ToolNode)parent;
               return n.getChildren(index);
       }

       public int getChildCount(Object parent) {
               // TODO Auto-generated method stub
               ToolNode n=(ToolNode)parent;
               return n.ChildrenCount();
       }

       public boolean isLeaf(Object node) {
               // TODO Auto-generated method stub
               ToolNode n=(ToolNode)node;
               if(n.ChildrenCount()==0) return true;
               else return false;
       }

       public void valueForPathChanged(TreePath path, Object newValue) {
               // TODO Auto-generated method stub

       }

       public int getIndexOfChild(Object parent, Object child) {
               // TODO Auto-generated method stub
               ToolNode p=(ToolNode)parent;
               ToolNode c=(ToolNode)child;
               return p.getIndex(c);
       }

       public void addTreeModelListener(TreeModelListener l) {
               // TODO Auto-generated method stub
               if(!(listenerList.contains(l))) listenerList.add(l);

       }

       public void removeTreeModelListener(TreeModelListener l) {
               // TODO Auto-generated method stub
               if(listenerList.contains(l)) listenerList.remove(l);
       }

}
