package my_tree;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.swing.tree.TreeNode;

import com.google.common.collect.Iterators;
@ManagedBean(name = "my_node")
@SessionScoped  
@ViewScoped
public class OptionTreeNode  implements Serializable,TreeNode{

	private static final long serialVersionUID = 1L;
	public String name;  
	public String type;
	private TreeNode parent;
	public List<TreeNode> child  = new ArrayList<TreeNode>();
	//final String type_str="node222";
	final String type_str="node";

	public OptionTreeNode(String name,TreeNode parent)
	{
		this.name=name;
		this.type=type_str;
		this.parent=parent;
	}
	public OptionTreeNode()
	{
		type=type_str;
		this.name="nam*";
	}
	  
    public String getName() { 
    	//System.out.println("getName() "+this);
        return this.name;  
    }  
  
    public void setName(String name) { 
    	//System.out.println("setName() "+name+" "+this);
        this.name = name;  
    }  
   /* @Override
    public String toString() {  
        return this.name;  
    }*/

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public Enumeration children() {
		// TODO Auto-generated method stub
		return Iterators.asEnumeration(child.iterator());
	}

	@Override
	public boolean getAllowsChildren() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public TreeNode getChildAt(int arg0) {
		// TODO Auto-generated method stub
		return  child.get(arg0);
	}

	@Override
	public int getChildCount() {
		// TODO Auto-generated method stub
		return child.size();
	}

	@Override
	public int getIndex(TreeNode arg0) {
		// TODO Auto-generated method stub
		return child.indexOf(arg0);
	}

	@Override
	public TreeNode getParent() {
		// TODO Auto-generated method stub
		return parent;
	}

	@Override
	public boolean isLeaf() {
		// TODO Auto-generated method stub
		return false;
	}

	public void addChild(OptionTreeNode child2) {
		// TODO Auto-generated method stub
		 child.add(child2);
	}


	public List<TreeNode> getChild() {
		//System.out.println("getChild() "+this.name);
		List<TreeNode> ch=new ArrayList<TreeNode>();
		ch.add(new OptionTreeNode("**",this));
		return ch;
	}
	public void setChild(List<TreeNode> child) {
		this.child = child;
	}
	
	public List<TreeNode> getChild2() {
		//System.out.println("getChild2() "+this.name);
		List<TreeNode> ch=new ArrayList<TreeNode>();
		ch.add(new OptionTreeNode("|**|",this));
		return ch;
	}
	


	
}
