X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/GroupNode.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/GroupNode.java new file mode 100644 index 0000000..1064faa --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/GroupNode.java @@ -0,0 +1,92 @@ +/* + * Created on 27/06/2003 + * + */ +package com.quantum.view.bookmark; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import com.quantum.Messages; +import com.quantum.model.Bookmark; +import com.quantum.model.Entity; +import com.quantum.model.Schema; +import com.quantum.model.SchemaHolder; + +/** + * GroupNode represents a level of grouping in the BookmarkView hierarchy + * It will have categories like "TABLE", "VIEW" and so on, usually gotten from + * the JDBC driver. + * + * @author panic + */ +public class GroupNode extends TreeNode implements Comparable, SchemaHolder { + private String type = null; + private Schema schema = null; + + public GroupNode(TreeNode parent, Schema schema, String type) { + super(parent); + this.schema = schema; + this.type = type; + } + public boolean hasChildren() { + if (!isInitialized()) { + return true; + } else { + return !this.children.isEmpty(); + } + } + public Object[] getChildren() { + if (!isInitialized() && getBookmark().isConnected()) { + initializeChildren(); + } + return (TreeNode[]) this.children.toArray(new TreeNode[this.children.size()]); + } + protected void initializeChildren() { + try { + boolean firstTimeInitialization = !isInitialized(); + boolean changed = false; + Map temp = new HashMap(); + for (Iterator i = this.children.iterator(); i.hasNext();) { + TreeNode treeNode = (TreeNode) i.next(); + temp.put(treeNode.getName(), treeNode); + } + this.children.clear(); + + Bookmark bookmark = getBookmark(); + Entity[] entities = bookmark.getEntitiesForSchema(schema, type); + for (int i = 0, + length = (entities == null) ? 0 : entities.length; + i < length; + i++) { + + String name = entities[i].getName(); + EntityNode entityNode = (EntityNode) temp.remove(name); + if (entityNode == null) { + this.children.add(new EntityNode(this, entities[i])); + changed = true; + } else { + this.children.add(entityNode); + } + } + if (changed && !firstTimeInitialization) { + firePropertyChange("children", null, null); + } + } catch (SQLException e) { + } + } + public String getName() { + return Messages.getString(getClass().getName() + "." + this.type); + } + protected String getImageName() { + return "entitygroup.gif"; //$NON-NLS-1$ + } + /** + * @return + */ + public Schema getSchema() { + return schema; + } +}