1 package com.quantum.view.bookmark;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
5 import java.beans.PropertyChangeSupport;
6 import java.util.Arrays;
7 import java.util.Collections;
8 import java.util.Hashtable;
9 import java.util.Iterator;
12 import com.quantum.model.Bookmark;
13 import com.quantum.model.BookmarkCollection;
19 public final class BookmarkListNode extends TreeNode implements PropertyChangeListener {
20 final static BookmarkListNode instance = new BookmarkListNode();
21 final static TreeNode[] EMPTY_ARRAY = new TreeNode[0];
22 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
23 private boolean initialized = false;
25 private BookmarkListNode() {
29 public static BookmarkListNode getInstance() {
30 return BookmarkListNode.instance;
34 * @see com.quantum.view.bookmark.TreeNode#getChildren()
36 public Object[] getChildren() {
39 BookmarkCollection.getInstance().addPropertyChangeListener(this);
41 BookmarkNode[] nodes = (BookmarkNode[]) this.children.toArray(
42 new BookmarkNode[this.children.size()]);
48 * @see com.quantum.view.bookmark.TreeNode#hasChildren()
50 public boolean hasChildren() {
54 public String getName() {
55 return "ROOT"; //$NON-NLS-1$
57 protected String getImageName() {
63 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
64 this.propertyChangeSupport.addPropertyChangeListener(listener);
70 public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
71 this.propertyChangeSupport.removePropertyChangeListener(listener);
73 protected void firePropertyChange(PropertyChangeEvent event) {
74 this.propertyChangeSupport.firePropertyChange(event);
77 protected synchronized void initializeChildren() {
78 boolean changed = false;
79 Map temp = new Hashtable();
80 for (Iterator i = this.children.iterator(); i.hasNext();) {
81 BookmarkNode bookmark = (BookmarkNode) i.next();
82 temp.put(bookmark.getName(), bookmark);
85 this.children.clear();
87 Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
88 for (int i = 0, length = (bookmarks == null) ? 0 : bookmarks.length; i < length; i++) {
90 BookmarkNode node = (BookmarkNode) temp.remove(bookmarks[i].getName());
92 this.children.add(new BookmarkNode(this, bookmarks[i]));
95 this.children.add(node);
99 for (Iterator i = temp.values().iterator(); i.hasNext(); ) {
100 ((TreeNode) i.next()).dispose();
104 Collections.sort(this.children);
105 this.initialized = true;
108 firePropertyChange("bookmarks", null, null);
113 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
115 public void propertyChange(PropertyChangeEvent event) {
116 if ("bookmarks".equals(event.getPropertyName())) {
117 initializeChildren();