1 package com.quantum.view.bookmark;
3 import java.beans.PropertyChangeEvent;
4 import java.sql.SQLException;
5 import java.util.Iterator;
6 import java.util.Vector;
8 import com.quantum.ImageStore;
9 import com.quantum.model.Bookmark;
10 import com.quantum.model.BookmarkHolder;
11 import com.quantum.model.NotConnectedException;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.swt.graphics.Image;
17 * Base class for all nodes of the internal tree of data. Basically allows navigation.
20 public abstract class TreeNode
21 implements BookmarkHolder, Comparable, IAdaptable {
23 private TreeNode parent = null;
24 protected Vector children = new Vector();
25 private boolean disposed = false;
27 public TreeNode(TreeNode parent) {
31 public abstract Object[] getChildren() throws NotConnectedException, SQLException;
32 public TreeNode getParent() {
35 public abstract boolean hasChildren();
36 public abstract String getName();
38 public Bookmark getBookmark() {
39 return getParent().getBookmark();
42 public String getLabelName() {
47 * @return an Image object to appear in the view, null if not found
49 public Image getImage() {
50 return ImageStore.getImage(getImageName());
56 protected abstract String getImageName();
60 * @see java.lang.Comparable#compareTo(java.lang.Object)
62 public int compareTo(Object object) {
63 TreeNode that = (TreeNode) object;
64 return this.getLabelName().compareTo(that.getLabelName());
67 public String toString() {
68 return getLabelName();
71 public String getLabelDecorations(LabelDecorationInstructions labelDecorationInstructions) {
79 protected void firePropertyChange(
84 firePropertyChange(new PropertyChangeEvent(this, propertyName, oldValue, newValue));
92 protected void firePropertyChange(PropertyChangeEvent event) {
93 TreeNode parent = getParent();
94 if (parent != null && !this.disposed) {
95 parent.firePropertyChange(event);
99 protected void dispose() {
100 this.disposed = true;
103 protected void removeAllChildren() {
104 for (Iterator i = this.children.iterator(); i.hasNext();) {
105 TreeNode element = (TreeNode) i.next();
110 protected boolean isInitialized() {
111 return !this.children.isEmpty();
114 public Object getAdapter(Class adapter) {
117 protected abstract void initializeChildren() throws SQLException, NotConnectedException;
118 public void reload() throws NotConnectedException, SQLException {
119 if (isInitialized()) {
120 initializeChildren();
121 for (Iterator i = this.children.iterator(); i.hasNext(); ) {
122 ((TreeNode) i.next()).reload();