2 * Created on 27/06/2003
5 package com.quantum.view.bookmark;
7 import java.sql.SQLException;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Iterator;
13 import com.quantum.Messages;
14 import com.quantum.model.Bookmark;
15 import com.quantum.model.Entity;
16 import com.quantum.model.Schema;
17 import com.quantum.model.SchemaHolder;
20 * GroupNode represents a level of grouping in the BookmarkView hierarchy
21 * It will have categories like "TABLE", "VIEW" and so on, usually gotten from
26 public class GroupNode extends TreeNode implements Comparable, SchemaHolder {
27 private String type = null;
28 private Schema schema = null;
30 public GroupNode(TreeNode parent, Schema schema, String type) {
35 public boolean hasChildren() {
36 if (!isInitialized()) {
39 return !this.children.isEmpty();
42 public Object[] getChildren() {
43 if (!isInitialized() && getBookmark().isConnected()) {
46 return (TreeNode[]) this.children.toArray(new TreeNode[this.children.size()]);
48 protected void initializeChildren() {
50 boolean firstTimeInitialization = !isInitialized();
51 boolean changed = false;
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]));
72 this.children.add(entityNode);
75 Collections.sort(this.children);
76 if ((temp.size() > 0 || changed ) && !firstTimeInitialization) {
77 firePropertyChange("children", null, null);
79 } catch (SQLException e) {
82 public String getName() {
83 return Messages.getString(getClass().getName() + "." + this.type);
85 protected String getImageName() {
86 return "entitygroup.gif"; //$NON-NLS-1$
91 public Schema getSchema() {