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 index eb9d742..b45d6b8 100644 --- 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 @@ -1,6 +1,12 @@ 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; @@ -18,6 +24,10 @@ public class EntityNode extends TreeNode implements EntityHolder { 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); } @@ -35,7 +45,10 @@ public class EntityNode extends TreeNode implements EntityHolder { } public Object[] getChildren() throws NotConnectedException, SQLException { - initializeChildren(); + if (!isInitialized()) { + initializeChildren(); + } + if (this.children.size() > 0) { return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]); } else { @@ -44,14 +57,35 @@ public class EntityNode extends TreeNode implements EntityHolder { } protected synchronized void initializeChildren() throws NotConnectedException, SQLException { - this.children.clear(); + 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() { @@ -92,8 +126,15 @@ public class EntityNode extends TreeNode implements EntityHolder { } else if (isView()) { return "view.gif"; } else { - return (this.entity.exists() == null || this.entity.exists().booleanValue()) - ? "bigtable.gif" : "missingtable.gif"; + if (this.entity.exists() == null || this.entity.exists().booleanValue()){ + if (this.entity.isSynonym()) + return "big_syn_table.gif"; + else + return "bigtable.gif"; + } else + return "missingtable.gif"; + + } } @@ -128,4 +169,7 @@ public class EntityNode extends TreeNode implements EntityHolder { return super.compareTo(o); } } + void setEntity(Entity entity) { + this.entity = entity; + } }