/*
 * Created on 03-08-2003
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package net.sf.hibern8ide.node;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.TreeNode;

import net.sf.hibern8ide.Hibern8IDE;

/**
 * @author MAX
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public abstract class BaseNode implements TreeNode {

    // TODO: don't like to have knowledge about the icons in the treenodes.... 
    static final Icon mappedClassIcon = new ImageIcon(Hibern8IDE.class.getResource("images/mapped_class.gif"));
    static final Icon unmappedClassIcon = new ImageIcon(Hibern8IDE.class.getResource("images/unmapped_class.gif"));
    static final Icon propertyIcon = new ImageIcon(Hibern8IDE.class.getResource("images/property.gif"));
    static final Icon idpropertyIcon = new ImageIcon(Hibern8IDE.class.getResource("images/idproperty.gif"));
    static final Icon rootIcon = new ImageIcon(Hibern8IDE.class.getResource("images/types.gif"));
    
    BaseNode parent;
	NodeFactory factory;
	final List children = new ArrayList();
	protected String name = "!";
    Icon icon = unmappedClassIcon;
    
    public Icon getIcon() {
        return icon;
    }

    BaseNode(NodeFactory f, BaseNode parent) {
        factory = f;
        this.parent = parent;
    }    
    
    public TreeNode getChildAt(int childIndex) {
        return (TreeNode) children.get(childIndex);
    }

    public int getChildCount() {
        return children.size();
    }

    public TreeNode getParent() {
       return parent;
    }

    public int getIndex(TreeNode node) {
        return children.indexOf(node);
    }

    public boolean getAllowsChildren() {
        return true;
    }

    public boolean isLeaf() {
       return getChildCount()==0;
    }

    public Enumeration children() {
        return Collections.enumeration(children);
    }

	public abstract String getHQL();

	public String getName() {
        return name;
	}
    
    public String toString() {
        return getName();
    }
}
