Quantum version 2.4.1
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / SchemaNode.java
1 package com.quantum.view.bookmark;
2
3 import java.sql.SQLException;
4
5 import com.quantum.model.Bookmark;
6 import com.quantum.model.NotConnectedException;
7 import com.quantum.model.Schema;
8 import com.quantum.model.SchemaHolder;
9
10 /**
11  * @author BC
12  */
13 public class SchemaNode extends TreeNode implements SchemaHolder {
14
15     private Schema schema;
16     /**
17      * @param parent
18      */
19     public SchemaNode(TreeNode parent, Schema schema) {
20         super(parent);
21         this.schema = schema;
22     }
23
24     /**
25      * @see com.quantum.view.bookmark.TreeNode#getChildren()
26      */
27     public Object[] getChildren() {
28         Bookmark bookmark = getBookmark();
29         if (!bookmark.isConnected()) {
30             return BookmarkListNode.EMPTY_ARRAY;
31         } else {
32             if (this.children.isEmpty()) {
33                 initializeChildren();
34             }
35         }
36         return (TreeNode[]) this.children.toArray(new TreeNode[this.children.size()]);
37     }
38
39     protected void initializeChildren() {
40         this.children.clear();
41         Bookmark bookmark = getBookmark();
42         try {
43             String[] types = bookmark.getDatabase().getEntityTypes();
44             for (int i = 0, length = (types == null) ? 0 : types.length;
45                 i < length;
46                 i++) {
47                 this.children.add(new GroupNode(this, this.schema, types[i]));
48             }
49         } catch (NotConnectedException e) {
50         } catch (SQLException e) {
51         }
52     }
53
54     /**
55      * @see com.quantum.view.bookmark.TreeNode#hasChildren()
56      */
57     public boolean hasChildren() {
58         return getBookmark().isConnected();
59     }
60
61     /**
62      * @see com.quantum.view.bookmark.TreeNode#getName()
63      */
64     public String getName() {
65         return this.schema.getDisplayName();
66     }
67
68     /**
69      * @see com.quantum.view.bookmark.TreeNode#getImageName()
70      */
71     protected String getImageName() {
72         return this.schema.isDefault() 
73                         ? "user.gif" 
74                         :  this.schema.exists() 
75                                 ? "schema.gif" 
76                                 : "missingschema.gif";
77     }
78
79     /**
80      * @see com.quantum.model.SchemaHolder#getSchema()
81      */
82     public Schema getSchema() {
83         return this.schema;
84     }
85 }