package com.quantum.view.bookmark;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import com.quantum.model.Column;
import com.quantum.model.Entity;
import com.quantum.model.EntityHolder;
+import com.quantum.model.NotConnectedException;
import com.quantum.model.SchemaHolder;
import com.quantum.model.Table;
import com.quantum.model.View;
private Entity entity;
private boolean longFormName;
+ private List columns = Collections.synchronizedList(new ArrayList());
+ private List foreignKeys = Collections.synchronizedList(new ArrayList());
+ boolean initialized = false;
+
public EntityNode(TreeNode parent, Entity entity) {
this(parent, entity, false);
}
}
}
- public Object[] getChildren() {
- initializeChildren();
+ public Object[] getChildren() throws NotConnectedException, SQLException {
+ if (!isInitialized()) {
+ initializeChildren();
+ }
+
if (this.children.size() > 0) {
return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]);
} else {
}
}
- protected synchronized void initializeChildren() {
- this.children.clear();
+ protected synchronized void initializeChildren() throws NotConnectedException, SQLException {
+ boolean wasInitialized = isInitialized();
+ Map map = getChildrenAsMap();
Column[] columns = this.entity.getColumns();
+ this.children.clear();
for (int i = 0, length = (columns == null) ? 0 : columns.length;
i < length;
i++) {
- this.children.add(new ColumnNode(this, columns[i]));
+
+ ColumnNode node = (ColumnNode) map.get(columns[i].getName());
+ if (node == null) {
+ this.children.add(new ColumnNode(this, columns[i]));
+ } else {
+ node.setColumn(columns[i]);
+ this.children.add(node);
+ }
+
+ if (wasInitialized) {
+ firePropertyChange("columns", null, null);
+ }
}
- // TODO: fire property change event
+ }
+
+ private Map getChildrenAsMap() {
+ Map map = new HashMap();
+ for (Iterator i = this.children.iterator(); i.hasNext();) {
+ TreeNode node = (TreeNode) i.next();
+ map.put(node.getName(), node);
+ }
+ return map;
}
public boolean hasChildren() {
}
public String getLabelName() {
- return (this.longFormName) ? this.entity.getCondQualifiedName() : this.entity.getName();
+ return (this.longFormName) ? this.entity.getQualifiedName() : this.entity.getName();
}
public boolean isTable() {
public int compareTo(Object o) {
if (o instanceof EntityNode) {
EntityNode that = (EntityNode) o;
- return this.entity.getCondQualifiedName().compareTo(
- that.entity.getCondQualifiedName());
+ return this.entity.getQualifiedName().compareTo(
+ that.entity.getQualifiedName());
} else {
return super.compareTo(o);
}
}
+ void setEntity(Entity entity) {
+ this.entity = entity;
+ }
}