1 package com.quantum.view.bookmark;
3 import java.sql.SQLException;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.Iterator;
9 import com.quantum.Messages;
10 import com.quantum.model.Bookmark;
11 import com.quantum.model.Entity;
12 import com.quantum.model.Schema;
13 import com.quantum.model.SchemaHolder;
16 * GroupNode represents a level of grouping in the BookmarkView hierarchy
17 * It will have categories like "TABLE", "VIEW" and so on, usually gotten from
22 public class GroupNode extends TreeNode implements Comparable, SchemaHolder {
23 private String type = null;
24 private Schema schema = null;
25 private boolean initialized = false;
27 public GroupNode(TreeNode parent, Schema schema, String type) {
33 protected boolean isInitialized() {
34 return this.initialized;
36 public boolean hasChildren() {
37 if (!isInitialized()) {
40 return !this.children.isEmpty();
43 public Object[] getChildren() {
44 if (!isInitialized() && getBookmark().isConnected()) {
47 return (TreeNode[]) this.children.toArray(new TreeNode[this.children.size()]);
49 protected void initializeChildren() {
51 boolean firstTimeInitialization = !isInitialized();
52 Map temp = new HashMap();
53 for (Iterator i = this.children.iterator(); i.hasNext();) {
54 TreeNode treeNode = (TreeNode) i.next();
55 temp.put(treeNode.getName(), treeNode);
57 this.children.clear();
59 Bookmark bookmark = getBookmark();
60 Entity[] entities = bookmark.getEntitiesForSchema(schema, type);
62 length = (entities == null) ? 0 : entities.length;
66 String name = entities[i].getName();
67 EntityNode entityNode = (EntityNode) temp.remove(name);
68 if (entityNode == null) {
69 this.children.add(new EntityNode(this, entities[i]));
71 entityNode.setEntity(entities[i]);
72 this.children.add(entityNode);
75 for (Iterator i = temp.values().iterator(); i.hasNext();) {
76 ((TreeNode) i.next()).dispose();
79 Collections.sort(this.children);
80 if (!firstTimeInitialization) {
81 firePropertyChange("children", null, null);
84 this.initialized = true;
85 } catch (SQLException e) {
88 public String getName() {
89 return Messages.getString(getClass().getName() + "." + this.type);
91 protected String getImageName() {
92 return "entitygroup.gif"; //$NON-NLS-1$
97 public Schema getSchema() {
100 public String getType() {