1 package com.quantum.view.bookmark;
3 import com.quantum.model.Column;
4 import com.quantum.model.Entity;
5 import com.quantum.model.EntityHolder;
6 import com.quantum.model.SchemaHolder;
7 import com.quantum.model.Table;
8 import com.quantum.model.View;
13 public class EntityNode extends TreeNode implements EntityHolder {
15 private Entity entity;
16 private boolean longFormName;
18 public EntityNode(TreeNode parent, Entity entity) {
19 this(parent, entity, false);
21 public EntityNode(TreeNode parent, Entity entity, boolean longFormName) {
24 this.longFormName = longFormName;
26 if (parent instanceof SchemaHolder) {
27 SchemaHolder schemaHolder = (SchemaHolder) parent;
28 if (!schemaHolder.getSchema().getDisplayName().equals(entity.getSchema())) {
29 this.longFormName = true;
34 public Object[] getChildren() {
36 if (this.children.size() > 0) {
37 return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]);
39 return BookmarkListNode.EMPTY_ARRAY;
43 protected synchronized void initializeChildren() {
44 this.children.clear();
45 Column[] columns = this.entity.getColumns();
46 for (int i = 0, length = (columns == null) ? 0 : columns.length;
49 this.children.add(new ColumnNode(this, columns[i]));
51 // TODO: fire property change event
54 public boolean hasChildren() {
62 public Entity getEntity() {
66 public String getName() {
67 return this.entity.getName();
70 public String getLabelName() {
71 return (this.longFormName) ? this.entity.getCondQualifiedName() : this.entity.getName();
74 public boolean isTable() {
75 return Entity.TABLE_TYPE.equals(this.entity.getType());
78 public boolean isView() {
79 return Entity.VIEW_TYPE.equals(this.entity.getType());
82 public boolean isSequence() {
83 return Entity.SEQUENCE_TYPE.equals(this.entity.getType());
86 protected String getImageName() {
88 return "sequence.gif";
89 } else if (isView()) {
92 return (this.entity.exists() == null || this.entity.exists().booleanValue())
93 ? "bigtable.gif" : "missingtable.gif";
97 public String getLabelDecorations(LabelDecorationInstructions instructions) {
98 String decoration = null;
99 if (instructions.isSizeVisible()) {
100 Integer size = getSize();
102 decoration = ((decoration == null) ? "" : decoration)
109 private Integer getSize() {
111 return ((Table) this.entity).getSize();
112 } else if (isView()) {
113 return ((View) this.entity).getSize();
119 public int compareTo(Object o) {
120 if (o instanceof EntityNode) {
121 EntityNode that = (EntityNode) o;
122 return this.entity.getCondQualifiedName().compareTo(
123 that.entity.getCondQualifiedName());
125 return super.compareTo(o);