1 package com.explosion.datastream.exql.gui;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.Component;
23
24 import javax.swing.ImageIcon;
25 import javax.swing.JTree;
26 import javax.swing.tree.DefaultTreeCellRenderer;
27
28 import com.explosion.datastream.exql.EXQLConstants;
29 import com.explosion.expfmodules.rdbmsconn.dbom.DBEntity;
30 import com.explosion.expfmodules.rdbmsconn.dbom.DBEntityColumn;
31 import com.explosion.utilities.FileSystemUtils;
32
33 /***
34 * @author Stephen Cowx
35 */
36 public class MetaDataTreeCellRenderer extends DefaultTreeCellRenderer
37 {
38 ImageIcon table;
39 ImageIcon catalog;
40 ImageIcon db;
41 ImageIcon systemTable;
42 ImageIcon view;
43 ImageIcon schema;
44 ImageIcon synonym;
45 ImageIcon column;
46 ImageIcon primaryKey;
47 ImageIcon foreignKey;
48
49 /*** Creates a new instance of MetaDataTreeCellRenderer */
50 public MetaDataTreeCellRenderer(Component parent) throws Exception
51 {
52 table = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.TABLE_ICON_IMAGE, parent));
53 schema = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.SCHEMA_ICON_IMAGE, parent));
54 catalog = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.CATALOG_ICON_IMAGE, parent));
55 db = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.DB_ICON_IMAGE, parent));
56 systemTable = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.SYSTEM_TABLE_ICON_IMAGE, parent));
57 view = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.VIEW_ICON_IMAGE, parent));
58 synonym = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.SYNONYM_ICON_IMAGE, parent));
59 column = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.COLUMN_ICON_IMAGE, parent));
60 primaryKey = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.COLUMN_PK_ICON_IMAGE, parent));
61 foreignKey = new ImageIcon(FileSystemUtils.loadImage(EXQLConstants.COLUMN_FK_ICON_IMAGE, parent));
62 }
63
64 public Component getTreeCellRendererComponent(
65 JTree tree,
66 Object value,
67 boolean sel,
68 boolean expanded,
69 boolean leaf,
70 int row,
71 boolean hasFocus)
72 {
73
74 super.getTreeCellRendererComponent(
75 tree, value, sel,
76 expanded, leaf, row,
77 hasFocus);
78
79 if (((ExqlTreeNode) value).getUserObject() instanceof DBEntity)
80 {
81 DBEntity descriptor = (DBEntity) ((ExqlTreeNode) value).getUserObject();
82
83 switch (descriptor.getEntityType())
84 {
85 case (DBEntity.TYPE_CATALOG):
86 setClosedIcon(catalog);
87 setOpenIcon(catalog);
88 setIcon(catalog);
89 break;
90 case (DBEntity.TYPE_SCHEMA):
91 setClosedIcon(schema);
92 setOpenIcon(schema);
93 setIcon(schema);
94 break;
95 case (DBEntity.TYPE_TABLE):
96 setClosedIcon(table);
97 setOpenIcon(table);
98 setIcon(table);
99 break;
100 case (DBEntity.TYPE_VIEW):
101 setClosedIcon(view);
102 setOpenIcon(view);
103 setIcon(view);
104 break;
105 case (DBEntity.TYPE_SYSTEM_TABLE):
106 setClosedIcon(systemTable);
107 setOpenIcon(systemTable);
108 setIcon(systemTable);
109 break;
110 case (DBEntity.TYPE_SYNONYM):
111 setClosedIcon(synonym);
112 setOpenIcon(synonym);
113 setIcon(synonym);
114 break;
115 default :
116 }
117 }
118 else if (((ExqlTreeNode) value).getUserObject() instanceof DBEntityColumn)
119 {
120 DBEntityColumn col = (DBEntityColumn) ((ExqlTreeNode) value).getUserObject();
121 if (col.isPrimaryKey())
122 {
123 this.setClosedIcon(primaryKey);
124 this.setOpenIcon(primaryKey);
125 this.setIcon(primaryKey);
126 }
127 else if (col.isForeignKey())
128 {
129 this.setClosedIcon(foreignKey);
130 this.setOpenIcon(foreignKey);
131 this.setIcon(foreignKey);
132 }
133 else
134 {
135 this.setClosedIcon(column);
136 this.setOpenIcon(column);
137 this.setIcon(column);
138 }
139
140 }
141 else if (((ExqlTreeNode) value).isRoot())
142 {
143 setIcon(db);
144 setClosedIcon(db);
145 setOpenIcon(db);
146 }
147 else
148 {
149 setIcon(null);
150 }
151
152
153 return this;
154 }
155
156 }