View Javadoc
1 package com.bonevich.erj.ui; 2 3 import com.bonevich.erj.model.*; 4 import com.bonevich.erj.ErjConstants; 5 6 import java.awt.Component; 7 import javax.swing.Icon; 8 import javax.swing.JLabel; 9 import javax.swing.JTree; 10 import javax.swing.tree.DefaultTreeCellRenderer; 11 12 /*** 13 * 14 * @author Jeffrey Bonevich <bonevich@telocity.com> 15 * @version $Id: ErjTreeCellRenderer.html,v 1.1 2009/03/07 17:55:32 jbonevic Exp $ 16 */ 17 public class ErjTreeCellRenderer 18 extends DefaultTreeCellRenderer 19 implements ErjConstants 20 { 21 public Component getTreeCellRendererComponent( 22 JTree tree, Object value, 23 boolean selected, boolean expanded, 24 boolean leaf, int row, boolean focus 25 ) 26 { 27 Component cmp = super.getTreeCellRendererComponent( 28 tree, value, selected, expanded, leaf, row, focus 29 ); 30 final JLabel label = (JLabel) cmp; 31 32 ErjTreeNode node = (ErjTreeNode) value; 33 34 if (node.getUserObject() instanceof ModelElement) 35 { 36 final ModelElement elt = (ModelElement) node.getUserObject(); 37 ModelElementVisitor visitor = new ModelElementVisitor() 38 { 39 public void visitSchema(Schema element) 40 { 41 label.setIcon(ICON_SCHEMA); 42 } 43 public void visitRelation(Relation element) 44 { 45 label.setIcon(ICON_RELATION); 46 } 47 public void visitAttribute(Attribute element) 48 { 49 Attribute attr = (Attribute) elt; 50 Icon icon = ICON_NULL; 51 if (attr.isPrimaryKey()) 52 { 53 icon = ICON_PK; 54 } 55 else if (attr.isUniqueKey()) 56 { 57 icon = ICON_AK; 58 } 59 else if (attr.isForeignKey()) 60 { 61 icon = ICON_FK; 62 } 63 else if (attr.getConstraint() == AttributeConstraint.NOTNULL) 64 { 65 icon = ICON_NOTNULL; 66 } 67 label.setIcon(icon); 68 } 69 public void visitDomain(Domain element) 70 { 71 label.setIcon(ICON_DOMAIN); 72 } 73 public void visitKey(KeyConstraint element) 74 { 75 label.setIcon(ICON_FOREIGNKEY); 76 } 77 }; 78 elt.accept(visitor); 79 } 80 81 return cmp; 82 } 83 } /*** end class ErjTreeCellRenderer */

This page was automatically generated by Maven