1 package com.quantum.view.bookmark;
3 import java.beans.PropertyChangeEvent;
4 import java.util.Iterator;
5 import java.util.Vector;
7 import com.quantum.QuantumPlugin;
8 import com.quantum.model.Bookmark;
9 import com.quantum.model.BookmarkHolder;
11 import org.eclipse.core.runtime.IAdaptable;
12 import org.eclipse.swt.graphics.Image;
15 * Base class for all nodes of the internal tree of data. Basically allows navigation.
18 public abstract class TreeNode
19 implements BookmarkHolder, Comparable, IAdaptable {
21 private TreeNode parent = null;
22 protected Vector children = new Vector();
23 private boolean disposed = false;
25 public TreeNode(TreeNode parent) {
29 public abstract Object[] getChildren();
30 public TreeNode getParent() {
33 public abstract boolean hasChildren();
34 public abstract String getName();
36 public Bookmark getBookmark() {
37 return getParent().getBookmark();
40 public String getLabelName() {
45 * @return an Image object to appear in the view, null if not found
47 public Image getImage() {
48 return QuantumPlugin.getImage(getImageName());
54 protected abstract String getImageName();
58 * @see java.lang.Comparable#compareTo(java.lang.Object)
60 public int compareTo(Object object) {
61 TreeNode that = (TreeNode) object;
62 return this.getLabelName().compareTo(that.getLabelName());
65 public String toString() {
66 return getLabelName();
69 public String getLabelDecorations(LabelDecorationInstructions labelDecorationInstructions) {
77 protected void firePropertyChange(
82 firePropertyChange(new PropertyChangeEvent(this, propertyName, oldValue, newValue));
90 protected void firePropertyChange(PropertyChangeEvent event) {
91 TreeNode parent = getParent();
92 if (parent != null && !this.disposed) {
93 parent.firePropertyChange(event);
97 protected void dispose() {
101 protected void removeAllChildren() {
102 for (Iterator i = this.children.iterator(); i.hasNext();) {
103 TreeNode element = (TreeNode) i.next();
108 protected boolean isInitialized() {
109 return !this.children.isEmpty();
112 public Object getAdapter(Class adapter) {
115 protected abstract void initializeChildren();
116 public void reload() {
117 if (isInitialized()) {
118 initializeChildren();
119 for (Iterator i = this.children.iterator(); i.hasNext(); ) {
120 ((TreeNode) i.next()).reload();