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

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;

import net.sf.hibern8ide.node.BaseNode;
import net.sf.hibern8ide.node.TypeNode;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.Type;

/**
 * @author max
 *
 */
public class MappingsTreeCellRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer {

	
		/* (non-Javadoc)
		 * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
		 */
		public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
			super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

            if(value instanceof BaseNode) {
			     setIcon(((BaseNode)value).getIcon());
            } else {
                //?
                
            }
            
			

			if (value instanceof TypeNode) {
				TypeNode tn = (TypeNode) value;
				Type type = tn.getType();

				String s = "<html>";
				s += "TypeClass: " + type.getClass() + "<br>";
				s += "TypeName:" + type.getName() + "<br>";
				s += "Association: " + type.isAssociationType() + "<br>";
				s += "Component: " + type.isComponentType() + "<br>";
				s += "Entity: " + type.isEntityType() + "<br>";
				s += "Mutable: " + type.isMutable() + "<br>";
				s += "ObjectType: " + type.isObjectType() + "<br>";
				s += "PersistentCollection: " + type.isPersistentCollectionType();

				if (type.isPersistentCollectionType()) {
					PersistentCollectionType ptype = (PersistentCollectionType) type;
					s += "Role: " + ptype.getRole();
				}
				setToolTipText(s);
			}

			return this;
		}

	}
