fri.gui.swing.polytreetable
Class DefaultPolyTreeNode

java.lang.Object
  |
  +--fri.gui.swing.polytreetable.AbstractPolyTreeNode
        |
        +--fri.gui.swing.polytreetable.DefaultPolyTreeNode
All Implemented Interfaces:
MutablePolyTreeNode, PolyTreeNode
Direct Known Subclasses:
DefaultCachedPolyTreeNode

public class DefaultPolyTreeNode
extends AbstractPolyTreeNode
implements MutablePolyTreeNode

Implements a basic MutablePolyTreeNode. Such nodes can appear more than once in the tree view, as polyhierarchies can contain cycles (you get an array of rows if you request a PolyTreeNode from the view with treeTable.getTree().getViewRowsForNode(polyTreeNode)).
The usage of this class moves the responsibility for caching nodes to the client (use DefaultCachedPolyTreeNode!).

Override getChildCount() and getParentCount() to read data for the rendered structure, as they get messaged when a tree expansion takes place.

Remark:
This class is not derived from DefaultMutableTreeNode as DefaultMutableTreeNode does not satisfy the needs of PolyTreeNode. Its loops hardcode the fact that the root is the node that has a null parent: while ((node = getParent()) != null) ....
Furthermore the root of a PolyTreeTableModel is view dependent and can change at any time.
The PolyTreeTableModel is not a hierarchy but a network and can contain cycles, so even the Enumerations of DefaultMutableTreeNode would fail.

Author:
Ritzberger Fritz
See Also:
DefaultCachedPolyTreeNode

Field Summary
 
Fields inherited from class fri.gui.swing.polytreetable.AbstractPolyTreeNode
allowsChildren, allowsParents, children, EMPTY_ENUMERATION, parents, userObject
 
Constructor Summary
protected DefaultPolyTreeNode()
           
  DefaultPolyTreeNode(java.lang.Object userObject)
          Create a node that allows children and parents and hosts an user object.
  DefaultPolyTreeNode(java.lang.Object userObject, boolean allowsChildren, boolean allowsParents)
          Create a node that with an user object and parent/child flags.
 
Method Summary
 boolean getAllowsChildren()
          Returns true if the receiver allows children.
 boolean getAllowsParents()
          Returns true if the receiver allows parents.
 int getChildCount()
          Returns the number of children the receiver contains.
 java.lang.Object getColumnObject(int column)
          Convenience implementation for column objects in conjunction with DefaultPolyTreeTableModel.getValueAt().
 int getParentCount()
          Returns the number of parents the receiver contains.
 void insertChild(PolyTreeNode newNode, int index)
          Insert a new child at passed index if not alreay contained.
 void insertParent(PolyTreeNode newNode, int index)
          Insert a new parent at passed index if not alreay contained.
 boolean isCellEditable(int column)
          Convenience implementation for column objects in conjunction with CellEditor.
 void removeChild(int index)
          Remove the passed index from children list
 void removeParent(int index)
          Remove the passed index from parent list
 boolean setColumnObject(int column, java.lang.Object aValue)
          Convenience implementation for column objects in conjunction with DefaultPolyTreeTableModel.setValueAt().
 void setUserObject(java.lang.Object userObject)
          Sets the object representing the File or Document or whatever.
 
Methods inherited from class fri.gui.swing.polytreetable.AbstractPolyTreeNode
children, getChildAt, getChildIndex, getElementCount, getParentAt, getParentIndex, getUserObject, isChildLeaf, isNodeChild, isNodeParent, isParentLeaf, parents, setAllowsChildren, setAllowsParents, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fri.gui.swing.polytreetable.PolyTreeNode
children, getChildAt, getChildIndex, getParentAt, getParentIndex, getUserObject, isChildLeaf, isParentLeaf, parents
 

Constructor Detail

DefaultPolyTreeNode

protected DefaultPolyTreeNode()

DefaultPolyTreeNode

public DefaultPolyTreeNode(java.lang.Object userObject)
Create a node that allows children and parents and hosts an user object.


DefaultPolyTreeNode

public DefaultPolyTreeNode(java.lang.Object userObject,
                           boolean allowsChildren,
                           boolean allowsParents)
Create a node that with an user object and parent/child flags. These Flags will be considered only if model.asksAllowsChildren and model.asksAllowsParents was set to true (default)

Method Detail

isCellEditable

public boolean isCellEditable(int column)
Convenience implementation for column objects in conjunction with CellEditor. Default always returns false. If userObject is instanceof PolyTreeTableUserObject, this method delegates to userObject. Override this to set column data editable if you do not use PolyTreeTableUserObject.


getColumnObject

public java.lang.Object getColumnObject(int column)
Convenience implementation for column objects in conjunction with DefaultPolyTreeTableModel.getValueAt(). Default always returns the node itself. If userObject is instanceof PolyTreeTableUserObject, this method delegates to userObject. Override this to render data of different columns from userObject if you do not use PolyTreeTableUserObject.


setColumnObject

public boolean setColumnObject(int column,
                               java.lang.Object aValue)
Convenience implementation for column objects in conjunction with DefaultPolyTreeTableModel.setValueAt(). Default this does nothing. If userObject is instanceof PolyTreeTableUserObject, this method delegates to userObject and sets the returned Object as new userObject. Override this to change rendered data of different columns in userObject if you do not use PolyTreeTableUserObject.

Returns:
true if a real change was done

getChildCount

public int getChildCount()
Returns the number of children the receiver contains. Override this to read child nodes from a medium and store them to children before calling super.getChildCount().

Specified by:
getChildCount in interface PolyTreeNode

getParentCount

public int getParentCount()
Returns the number of parents the receiver contains. Override this to read parent nodes from a medium and store them to parents before calling super.getParentCount().

Specified by:
getParentCount in interface PolyTreeNode

getAllowsParents

public boolean getAllowsParents()
Returns true if the receiver allows parents. Overridden to check for PolyTreeTableUserObject.

Specified by:
getAllowsParents in interface PolyTreeNode
Overrides:
getAllowsParents in class AbstractPolyTreeNode

getAllowsChildren

public boolean getAllowsChildren()
Returns true if the receiver allows children. Overridden to check for PolyTreeTableUserObject.

Specified by:
getAllowsChildren in interface PolyTreeNode
Overrides:
getAllowsChildren in class AbstractPolyTreeNode

setUserObject

public void setUserObject(java.lang.Object userObject)
Sets the object representing the File or Document or whatever.

Specified by:
setUserObject in interface MutablePolyTreeNode

insertParent

public void insertParent(PolyTreeNode newNode,
                         int index)
Insert a new parent at passed index if not alreay contained. getUserObject().equals() is called to estimate this.

Specified by:
insertParent in interface MutablePolyTreeNode

insertChild

public void insertChild(PolyTreeNode newNode,
                        int index)
Insert a new child at passed index if not alreay contained. getUserObject().equals() is called to estimate this.

Specified by:
insertChild in interface MutablePolyTreeNode

removeParent

public void removeParent(int index)
Remove the passed index from parent list

Specified by:
removeParent in interface MutablePolyTreeNode

removeChild

public void removeChild(int index)
Remove the passed index from children list

Specified by:
removeChild in interface MutablePolyTreeNode