added file extension php5
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / QuickListNode.java
1 package com.quantum.view.bookmark;
2
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
5 import java.util.ArrayList;
6 import java.util.Collections;
7 import java.util.Hashtable;
8 import java.util.List;
9 import java.util.Map;
10
11 import com.quantum.Messages;
12 import com.quantum.model.Bookmark;
13 import com.quantum.model.Entity;
14
15 /**
16  * <p>A "quick list" is a set of favourite entities that a user may want 
17  * to work with without having to sift through the (somtimes lengthy) longer
18  * list of tables.</p>
19  * 
20  * @author bcholmes
21  */
22 public class QuickListNode extends TreeNode implements PropertyChangeListener {
23     
24     private Map children = new Hashtable();
25
26     /**
27      * @param parent
28      */
29     public QuickListNode(BookmarkNode parent) {
30         super(parent);
31         
32         Bookmark bookmark = getBookmark();
33         bookmark.addPropertyChangeListener(this);
34     }
35     
36     /**
37      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
38      */
39     public void propertyChange(PropertyChangeEvent event) {
40         if ("quickList".equals(event.getPropertyName())) {
41             initializeChildren();
42             firePropertyChange("quickList", null, null);
43         }
44     }
45
46     /**
47      * @see com.quantum.view.bookmark.TreeNode#hasChildren()
48      */
49     public boolean hasChildren() {
50         return getBookmark().hasQuickList();
51     }
52     /**
53      * @see com.quantum.view.bookmark.TreeNode#getImageName()
54      */
55     protected String getImageName() {
56         return "group.gif";
57     }
58     
59     /**
60      * @see com.quantum.view.bookmark.TreeNode#getChildren()
61      */
62     public Object[] getChildren() {
63         Bookmark bookmark = getBookmark();
64         if (children.isEmpty() && bookmark.hasQuickList()) {
65             initializeChildren();
66         }
67         List list = new ArrayList(this.children.values());
68         Collections.sort(list);
69         
70         return (TreeNode[]) list.toArray(new TreeNode[list.size()]);
71     }
72
73     /**
74      * @see com.quantum.view.bookmark.TreeNode#getName()
75      */
76     public String getName() {
77         return Messages.getString(QuickListNode.class.getName() + ".labelName");
78     }
79     
80     protected synchronized void initializeChildren() {
81         this.children.clear();
82         Entity[] entities = getBookmark().getQuickListEntries();
83         for (int i = 0, length = (entities == null) ? 0 : entities.length;
84             i < length;
85             i++) {
86                 
87             this.children.put(entities[i].getQualifiedName(), 
88                 new EntityNode(this, entities[i], true));
89         }
90     }
91     /* (non-Javadoc)
92      * @see com.quantum.view.bookmark.TreeNode#isInitialized()
93      */
94     protected boolean isInitialized() {
95         return true;
96     }
97
98 }