1 package com.quantum.view.bookmark;
3 import java.sql.SQLException;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.Iterator;
11 import com.quantum.model.Column;
12 import com.quantum.model.Entity;
13 import com.quantum.model.EntityHolder;
14 import com.quantum.model.NotConnectedException;
15 import com.quantum.model.SchemaHolder;
16 import com.quantum.model.Table;
17 import com.quantum.model.View;
22 public class EntityNode extends TreeNode implements EntityHolder {
24 private Entity entity;
25 private boolean longFormName;
27 private List columns = Collections.synchronizedList(new ArrayList());
28 private List foreignKeys = Collections.synchronizedList(new ArrayList());
29 boolean initialized = false;
31 public EntityNode(TreeNode parent, Entity entity) {
32 this(parent, entity, false);
34 public EntityNode(TreeNode parent, Entity entity, boolean longFormName) {
37 this.longFormName = longFormName;
39 if (parent instanceof SchemaHolder) {
40 SchemaHolder schemaHolder = (SchemaHolder) parent;
41 if (!schemaHolder.getSchema().getDisplayName().equals(entity.getSchema())) {
42 this.longFormName = true;
47 public Object[] getChildren() throws NotConnectedException, SQLException {
48 if (!isInitialized()) {
52 if (this.children.size() > 0) {
53 return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]);
55 return BookmarkListNode.EMPTY_ARRAY;
59 protected synchronized void initializeChildren() throws NotConnectedException, SQLException {
60 boolean wasInitialized = isInitialized();
61 Map map = getChildrenAsMap();
62 Column[] columns = this.entity.getColumns();
63 this.children.clear();
64 for (int i = 0, length = (columns == null) ? 0 : columns.length;
68 ColumnNode node = (ColumnNode) map.get(columns[i].getName());
70 this.children.add(new ColumnNode(this, columns[i]));
72 node.setColumn(columns[i]);
73 this.children.add(node);
77 firePropertyChange("columns", null, null);
82 private Map getChildrenAsMap() {
83 Map map = new HashMap();
84 for (Iterator i = this.children.iterator(); i.hasNext();) {
85 TreeNode node = (TreeNode) i.next();
86 map.put(node.getName(), node);
91 public boolean hasChildren() {
99 public Entity getEntity() {
103 public String getName() {
104 return this.entity.getName();
107 public String getLabelName() {
108 return (this.longFormName) ? this.entity.getQualifiedName() : this.entity.getName();
111 public boolean isTable() {
112 return Entity.TABLE_TYPE.equals(this.entity.getType());
115 public boolean isView() {
116 return Entity.VIEW_TYPE.equals(this.entity.getType());
119 public boolean isSequence() {
120 return Entity.SEQUENCE_TYPE.equals(this.entity.getType());
123 protected String getImageName() {
125 return "sequence.gif";
126 } else if (isView()) {
129 return (this.entity.exists() == null || this.entity.exists().booleanValue())
130 ? "bigtable.gif" : "missingtable.gif";
134 public String getLabelDecorations(LabelDecorationInstructions instructions) {
135 String decoration = null;
136 if (instructions.isSizeVisible()) {
137 Integer size = getSize();
139 decoration = ((decoration == null) ? "" : decoration)
146 private Integer getSize() {
148 return ((Table) this.entity).getSize();
149 } else if (isView()) {
150 return ((View) this.entity).getSize();
156 public int compareTo(Object o) {
157 if (o instanceof EntityNode) {
158 EntityNode that = (EntityNode) o;
159 return this.entity.getQualifiedName().compareTo(
160 that.entity.getQualifiedName());
162 return super.compareTo(o);
165 void setEntity(Entity entity) {
166 this.entity = entity;