org.fopps.model
Class TreeItem

java.lang.Object
  |
  +--org.fopps.model.AbstractItem
        |
        +--org.fopps.model.TreeItem
Direct Known Subclasses:
ConfigurationItem, Feature

public class TreeItem
extends AbstractItem

TreeItem is the base class for all entities with a tree-like structure. Each tree item has a unique parant and may have zero or more children. In addition it provides some convenience methods for tree maintenance (depth, complete path, etc.)

Note: Class TreeItem has a different behaviour regarding events. An event will also passed to the parent node, if present. Normally you only have to listen to the root node of the tree.

Author:
Oliver Wieland

Field Summary
protected  java.util.List mChildren
           
protected  TreeItem mParent
           
 
Fields inherited from class org.fopps.model.AbstractItem
ADDED_EVENT, CHANGE_EVENT, name, REMOVED_EVENT
 
Constructor Summary
TreeItem(java.lang.String pName)
          Same as TreeItem(pName, null).
TreeItem(java.lang.String pName, TreeItem pParent)
          Creates a tree item with a given parent node.
TreeItem(java.lang.String pName, TreeItem pParent, boolean pChildrenAllowed)
          Creates a tree item with a given parent node
 
Method Summary
 void addChildren(TreeItem pChildren)
          Adds one element to association Children
 int allChildrenCount()
          Returns the number of all children.
 boolean childrenAllowed()
          Returns true, if tree item may have child nodes.
 int childrenCount()
          Returns the number of children
 void delete()
          Deletes the feature (unlink connection to parent)
 TreeItem first()
          Returns the first child or null, if TreeItem is a leaf
 TreeItem getChildAt(int i)
          Returns child node by index
 java.util.Collection getChildren()
          Getter Association Children.
 int getDepth()
          Retuns depth of current TreeItem.
 int getIndexOfChild(TreeItem pChild)
          Returns the index of a given child
 TreeItem getParent()
          Getter of association Parent
 TreeItem[] getPath()
          Returns the path from root to this TreeItem (useful for tree display)
 TreeItem getRoot()
          Returns the root TreeItem.
 boolean isLeaf()
          Returns true, if TreeItem has no children
 TreeItem last()
          Returns the last child or null, if TreeItem is a leaf
 void notifyListeners(ModelEvent pEvent)
          Notify all listeners of the item
 void removeAllChildren()
          Removes one element to association Children
 void removeAllChildrenRecursive()
          Drops whole subtree of TreeItem
 void removeChildren(TreeItem pChildren)
          Removes one element to association Children
 void setChildren(java.util.Collection pChildren)
          Setter Association Children
 void setParent(TreeItem pParent)
          Setter of association Parent
 
Methods inherited from class org.fopps.model.AbstractItem
addIncoming, addListener, addOutgoing, commitGhostRelations, containsType, copyAttributes, filterElements, fireItemAdded, fireItemChanged, fireItemRemoved, getConstraints, getDescription, getIncoming, getIncomingConstraints, getListeners, getName, getOutgoing, getOutgoingConstraints, getRelationTo, hasConstraints, isBlockEvents, isConnectedWith, removeAllConstraints, removeAllIncoming, removeAllListener, removeAllOutgoing, removeAllRelations, removeGhostRelations, removeIncoming, removeListener, removeOutgoing, removeRelationTo, setBlockEvents, setDescription, setIncoming, setName, setOutgoing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mParent

protected TreeItem mParent

mChildren

protected java.util.List mChildren
Constructor Detail

TreeItem

public TreeItem(java.lang.String pName)
Same as TreeItem(pName, null). Children are allowed.

Parameters:
pName - Name of the tree item

TreeItem

public TreeItem(java.lang.String pName,
                TreeItem pParent)
Creates a tree item with a given parent node. Children are allowed.

Parameters:
pName - Name of the tree item
pParent - Parent node of item

TreeItem

public TreeItem(java.lang.String pName,
                TreeItem pParent,
                boolean pChildrenAllowed)
Creates a tree item with a given parent node

Parameters:
pName - Name of the tree item
pParent - Parent node of item
pChildrenAllowed - Flag which determines, if children are allowed or not
Method Detail

setParent

public void setParent(TreeItem pParent)
Setter of association Parent


getParent

public TreeItem getParent()
Getter of association Parent


getChildren

public java.util.Collection getChildren()
Getter Association Children.

Returns:
Children of this TreeItem. If no children present, an empty list is returned

setChildren

public void setChildren(java.util.Collection pChildren)
Setter Association Children


addChildren

public void addChildren(TreeItem pChildren)
Adds one element to association Children


removeChildren

public void removeChildren(TreeItem pChildren)
Removes one element to association Children


removeAllChildren

public void removeAllChildren()
Removes one element to association Children


removeAllChildrenRecursive

public void removeAllChildrenRecursive()
Drops whole subtree of TreeItem


childrenCount

public int childrenCount()
Returns the number of children


getChildAt

public TreeItem getChildAt(int i)
Returns child node by index


getIndexOfChild

public int getIndexOfChild(TreeItem pChild)
Returns the index of a given child

Returns:
Index of child or -1 if not found

isLeaf

public boolean isLeaf()
Returns true, if TreeItem has no children


first

public TreeItem first()
Returns the first child or null, if TreeItem is a leaf


last

public TreeItem last()
Returns the last child or null, if TreeItem is a leaf


getPath

public TreeItem[] getPath()
Returns the path from root to this TreeItem (useful for tree display)


getRoot

public TreeItem getRoot()
Returns the root TreeItem. If no parent node present, this method returns 'this'


getDepth

public int getDepth()
Retuns depth of current TreeItem. The root TreeItem has depth 1


allChildrenCount

public int allChildrenCount()
Returns the number of all children.


notifyListeners

public void notifyListeners(ModelEvent pEvent)
Notify all listeners of the item

Overrides:
notifyListeners in class AbstractItem

delete

public void delete()
Deletes the feature (unlink connection to parent)

Overrides:
delete in class AbstractItem
See Also:
delete()

childrenAllowed

public boolean childrenAllowed()
Returns true, if tree item may have child nodes. If false, getChildren() will alwas return an empty list. Default is true.



Fopps 0.19 - Copyright © 2002 Oliver Wieland. All Rights Reserved.