X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java new file mode 100644 index 0000000..6d5adbe --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/EntityNode.java @@ -0,0 +1,128 @@ +package com.quantum.view.bookmark; + +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.model.EntityHolder; +import com.quantum.model.SchemaHolder; +import com.quantum.model.Table; +import com.quantum.model.View; + +/** + * @author BC + */ +public class EntityNode extends TreeNode implements EntityHolder { + + private Entity entity; + private boolean longFormName; + + public EntityNode(TreeNode parent, Entity entity) { + this(parent, entity, false); + } + public EntityNode(TreeNode parent, Entity entity, boolean longFormName) { + super(parent); + this.entity = entity; + this.longFormName = longFormName; + + if (parent instanceof SchemaHolder) { + SchemaHolder schemaHolder = (SchemaHolder) parent; + if (!schemaHolder.getSchema().getDisplayName().equals(entity.getSchema())) { + this.longFormName = true; + } + } + } + + public Object[] getChildren() { + initializeChildren(); + if (this.children.size() > 0) { + return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]); + } else { + return BookmarkListNode.EMPTY_ARRAY; + } + } + + protected synchronized void initializeChildren() { + this.children.clear(); + Column[] columns = this.entity.getColumns(); + for (int i = 0, length = (columns == null) ? 0 : columns.length; + i < length; + i++) { + this.children.add(new ColumnNode(this, columns[i])); + } + // TODO: fire property change event + } + + public boolean hasChildren() { + if (!isSequence()) { + return true; + } else { + return false; + } + } + + public Entity getEntity() { + return this.entity; + } + + public String getName() { + return this.entity.getName(); + } + + public String getLabelName() { + return (this.longFormName) ? this.entity.getCondQualifiedName() : this.entity.getName(); + } + + public boolean isTable() { + return Entity.TABLE_TYPE.equals(this.entity.getType()); + } + + public boolean isView() { + return Entity.VIEW_TYPE.equals(this.entity.getType()); + } + + public boolean isSequence() { + return Entity.SEQUENCE_TYPE.equals(this.entity.getType()); + } + + protected String getImageName() { + if (isSequence()) { + return "sequence.gif"; + } else if (isView()) { + return "view.gif"; + } else { + return (this.entity.exists() == null || this.entity.exists().booleanValue()) + ? "bigtable.gif" : "missingtable.gif"; + } + } + + public String getLabelDecorations(LabelDecorationInstructions instructions) { + String decoration = null; + if (instructions.isSizeVisible()) { + Integer size = getSize(); + if (size != null) { + decoration = ((decoration == null) ? "" : decoration) + + "[" + size + "]"; + } + } + return decoration; + } + + private Integer getSize() { + if (isTable()) { + return ((Table) this.entity).getSize(); + } else if (isView()) { + return ((View) this.entity).getSize(); + } else { + return null; + } + } + + public int compareTo(Object o) { + if (o instanceof EntityNode) { + EntityNode that = (EntityNode) o; + return this.entity.getCondQualifiedName().compareTo( + that.entity.getCondQualifiedName()); + } else { + return super.compareTo(o); + } + } +}