ca.sqlpower.architect.swingui
Class DBTreeNode

java.lang.Object
  extended by ca.sqlpower.architect.swingui.DBTreeNode
All Implemented Interfaces:
javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class DBTreeNode
extends java.lang.Object
implements javax.swing.tree.MutableTreeNode


Nested Class Summary
 class DBTreeNode.TreeNodeEnumeration
          Enumerates the DBTreeNode objects associated with the given SQLObjects by using the userObjectToTreeNodeMap.
 
Field Summary
protected  javax.swing.tree.TreeNode parent
          We allow any node in a JTree to be our parent.
 SQLObject userObject
          The user object of a DBTreeNode is aways a subclass of SQLObject.
protected static java.util.Map userObjectToTreeNodeMap
           
 
Constructor Summary
DBTreeNode(SQLObject userObject)
          Makes a DBTreeNode with the given SQLObject as its user object.
DBTreeNode(SQLObject userObject, javax.swing.tree.TreeNode parent)
          Only use this if this node is not under a SQLObject.
 
Method Summary
 java.util.Enumeration children()
          Gets the children list from the userObject.
 boolean getAllowsChildren()
           
 javax.swing.tree.TreeNode getChildAt(int i)
           
 int getChildCount()
           
 int getIndex(javax.swing.tree.TreeNode node)
           
 javax.swing.tree.TreeNode getParent()
           
 SQLObject getSQLObject()
          Just returns the user object.
 java.lang.Object getUserObject()
          Satisfies the MutableTreeNode interface.
 void insert(javax.swing.tree.MutableTreeNode child, int index)
           
 boolean isLeaf()
           
 void remove(int index)
           
 void remove(javax.swing.tree.MutableTreeNode node)
           
 void removeFromParent()
          Removes this node from its parent if possible.
 void setParent(javax.swing.tree.MutableTreeNode newParent)
          the following may be incorrect: Moves this treeNode and its peer SQLObject to the new given parent.
protected  void setup(SQLObject userObject, javax.swing.tree.TreeNode parent)
          Sets up the required instance variables and inserts this node into the userObjectToTreeNodeMap.
 void setUserObject(java.lang.Object newSQLObject)
          Not supported.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

userObjectToTreeNodeMap

protected static java.util.Map userObjectToTreeNodeMap

userObject

public SQLObject userObject
The user object of a DBTreeNode is aways a subclass of SQLObject.


parent

protected javax.swing.tree.TreeNode parent
We allow any node in a JTree to be our parent.

Constructor Detail

DBTreeNode

public DBTreeNode(SQLObject userObject)
Makes a DBTreeNode with the given SQLObject as its user object. If the userObject has a parent SQLObject, this node will return that SQLObject in its getParent() method.


DBTreeNode

public DBTreeNode(SQLObject userObject,
                  javax.swing.tree.TreeNode parent)
Only use this if this node is not under a SQLObject. It's ok to put any SQLObject under any non-SQLObject, but you may not specify a SQLObject parent because that would be really weird.

Throws:
java.lang.IllegalArgumentException - if you are weird. (see above)
Method Detail

setup

protected void setup(SQLObject userObject,
                     javax.swing.tree.TreeNode parent)
Sets up the required instance variables and inserts this node into the userObjectToTreeNodeMap.


getAllowsChildren

public boolean getAllowsChildren()
Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode

getChildAt

public javax.swing.tree.TreeNode getChildAt(int i)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface javax.swing.tree.TreeNode

getIndex

public int getIndex(javax.swing.tree.TreeNode node)
Specified by:
getIndex in interface javax.swing.tree.TreeNode
Throws:
java.lang.ClassCastException - if node is not of type DBTreeNode.

getParent

public javax.swing.tree.TreeNode getParent()
Specified by:
getParent in interface javax.swing.tree.TreeNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface javax.swing.tree.TreeNode

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

children

public java.util.Enumeration children()
Gets the children list from the userObject. Doing this here is the key to the "lazy loading" feature of the tree.

Specified by:
children in interface javax.swing.tree.TreeNode

getSQLObject

public SQLObject getSQLObject()
Just returns the user object.


getUserObject

public java.lang.Object getUserObject()
Satisfies the MutableTreeNode interface. You will want to use getSQLObject instead.


insert

public void insert(javax.swing.tree.MutableTreeNode child,
                   int index)
Specified by:
insert in interface javax.swing.tree.MutableTreeNode

remove

public void remove(int index)
Specified by:
remove in interface javax.swing.tree.MutableTreeNode

remove

public void remove(javax.swing.tree.MutableTreeNode node)
Specified by:
remove in interface javax.swing.tree.MutableTreeNode

removeFromParent

public void removeFromParent()
                      throws java.lang.UnsupportedOperationException
Removes this node from its parent if possible.

Specified by:
removeFromParent in interface javax.swing.tree.MutableTreeNode
Throws:
java.lang.UnsupportedOperationException - if the parent is immutable.

setParent

public void setParent(javax.swing.tree.MutableTreeNode newParent)
the following may be incorrect: Moves this treeNode and its peer SQLObject to the new given parent. In many cases this will not be possible (you can't add a column directly to a database parent, but you can move a column from one table to another, etc.).

Specified by:
setParent in interface javax.swing.tree.MutableTreeNode

setUserObject

public void setUserObject(java.lang.Object newSQLObject)
Not supported.

Specified by:
setUserObject in interface javax.swing.tree.MutableTreeNode
Throws:
java.lang.UnsupportedOperationException - if you call it.


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca