2 * Created on 27/06/2003
5 package com.quantum.view.bookmark;
7 import java.sql.SQLException;
8 import java.util.HashMap;
9 import java.util.Iterator;
12 import com.quantum.Messages;
13 import com.quantum.model.Bookmark;
14 import com.quantum.model.Entity;
15 import com.quantum.model.Schema;
16 import com.quantum.model.SchemaHolder;
19 * GroupNode represents a level of grouping in the BookmarkView hierarchy
20 * It will have categories like "TABLE", "VIEW" and so on, usually gotten from
25 public class GroupNode extends TreeNode implements Comparable, SchemaHolder {
26 private String type = null;
27 private Schema schema = null;
29 public GroupNode(TreeNode parent, Schema schema, String type) {
34 public boolean hasChildren() {
35 if (!isInitialized()) {
38 return !this.children.isEmpty();
41 public Object[] getChildren() {
42 if (!isInitialized() && getBookmark().isConnected()) {
45 return (TreeNode[]) this.children.toArray(new TreeNode[this.children.size()]);
47 protected void initializeChildren() {
49 boolean firstTimeInitialization = !isInitialized();
50 boolean changed = false;
51 Map temp = new HashMap();
52 for (Iterator i = this.children.iterator(); i.hasNext();) {
53 TreeNode treeNode = (TreeNode) i.next();
54 temp.put(treeNode.getName(), treeNode);
56 this.children.clear();
58 Bookmark bookmark = getBookmark();
59 Entity[] entities = bookmark.getEntitiesForSchema(schema, type);
61 length = (entities == null) ? 0 : entities.length;
65 String name = entities[i].getName();
66 EntityNode entityNode = (EntityNode) temp.remove(name);
67 if (entityNode == null) {
68 this.children.add(new EntityNode(this, entities[i]));
71 this.children.add(entityNode);
74 if ((temp.size() > 0 || changed ) && !firstTimeInitialization) {
75 firePropertyChange("children", null, null);
77 } catch (SQLException e) {
80 public String getName() {
81 return Messages.getString(getClass().getName() + "." + this.type);
83 protected String getImageName() {
84 return "entitygroup.gif"; //$NON-NLS-1$
89 public Schema getSchema() {