1 package com.quantum.view.bookmark;
3 import java.sql.SQLException;
5 import com.quantum.model.Column;
6 import com.quantum.model.Entity;
7 import com.quantum.model.EntityHolder;
8 import com.quantum.model.NotConnectedException;
9 import com.quantum.model.SchemaHolder;
10 import com.quantum.model.Table;
11 import com.quantum.model.View;
16 public class EntityNode extends TreeNode implements EntityHolder {
18 private Entity entity;
19 private boolean longFormName;
21 public EntityNode(TreeNode parent, Entity entity) {
22 this(parent, entity, false);
24 public EntityNode(TreeNode parent, Entity entity, boolean longFormName) {
27 this.longFormName = longFormName;
29 if (parent instanceof SchemaHolder) {
30 SchemaHolder schemaHolder = (SchemaHolder) parent;
31 if (!schemaHolder.getSchema().getDisplayName().equals(entity.getSchema())) {
32 this.longFormName = true;
37 public Object[] getChildren() throws NotConnectedException, SQLException {
39 if (this.children.size() > 0) {
40 return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]);
42 return BookmarkListNode.EMPTY_ARRAY;
46 protected synchronized void initializeChildren() throws NotConnectedException, SQLException {
47 this.children.clear();
48 Column[] columns = this.entity.getColumns();
49 for (int i = 0, length = (columns == null) ? 0 : columns.length;
52 this.children.add(new ColumnNode(this, columns[i]));
54 // TODO: fire property change event
57 public boolean hasChildren() {
65 public Entity getEntity() {
69 public String getName() {
70 return this.entity.getName();
73 public String getLabelName() {
74 return (this.longFormName) ? this.entity.getQualifiedName() : this.entity.getName();
77 public boolean isTable() {
78 return Entity.TABLE_TYPE.equals(this.entity.getType());
81 public boolean isView() {
82 return Entity.VIEW_TYPE.equals(this.entity.getType());
85 public boolean isSequence() {
86 return Entity.SEQUENCE_TYPE.equals(this.entity.getType());
89 protected String getImageName() {
91 return "sequence.gif";
92 } else if (isView()) {
95 return (this.entity.exists() == null || this.entity.exists().booleanValue())
96 ? "bigtable.gif" : "missingtable.gif";
100 public String getLabelDecorations(LabelDecorationInstructions instructions) {
101 String decoration = null;
102 if (instructions.isSizeVisible()) {
103 Integer size = getSize();
105 decoration = ((decoration == null) ? "" : decoration)
112 private Integer getSize() {
114 return ((Table) this.entity).getSize();
115 } else if (isView()) {
116 return ((View) this.entity).getSize();
122 public int compareTo(Object o) {
123 if (o instanceof EntityNode) {
124 EntityNode that = (EntityNode) o;
125 return this.entity.getQualifiedName().compareTo(
126 that.entity.getQualifiedName());
128 return super.compareTo(o);