com.guiseframework.model
Class DefaultTreeNodeModel<V>

java.lang.Object
  extended by com.globalmentor.beans.BoundPropertyObject
      extended by com.guiseframework.model.AbstractModel
          extended by com.guiseframework.model.AbstractValueModel<V>
              extended by com.guiseframework.model.DefaultValueModel<V>
                  extended by com.guiseframework.model.DefaultTreeNodeModel<V>
Type Parameters:
V - The type of value contained in the tree node.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, ActionListenable, ActionModel, Model, Selectable, TreeNodeModel<V>, Valued<V>, ValueModel<V>, java.lang.Iterable<TreeNodeModel<?>>
Direct Known Subclasses:
DummyTreeNodeModel, DynamicTreeNodeModel, RDFLiteralTreeNodeModel

public class DefaultTreeNodeModel<V>
extends DefaultValueModel<V>
implements TreeNodeModel<V>

A default node in a tree model. Property change events and action events on one tree node will be bubbled up the hierarchy, with the tree node initiating the event accessible via TargetedEvent.getTarget().

Author:
Garret Wilson

Field Summary
 
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
 
Fields inherited from interface com.guiseframework.model.TreeNodeModel
EXPANDED_PROPERTY
 
Fields inherited from interface com.guiseframework.model.ValueModel
VALIDATOR_PROPERTY, VALUE_PROPERTY
 
Fields inherited from interface com.guiseframework.model.Model
PLAIN_TEXT_CONTENT_TYPE, XHTML_CONTENT_TYPE, XHTML_FRAGMENT_CONTENT_TYPE
 
Fields inherited from interface com.guiseframework.model.Selectable
SELECTED_PROPERTY
 
Constructor Summary
DefaultTreeNodeModel(java.lang.Class<V> valueClass)
          Constructs a tree node model indicating the type of value it can hold.
DefaultTreeNodeModel(java.lang.Class<V> valueClass, V initialValue)
          Constructs a tree node model indicating the type of value it can hold, along with an initial value.
 
Method Summary
 void add(TreeNodeModel<?> treeNode)
          Adds a child tree node to this tree node.
 void addActionListener(ActionListener actionListener)
          Adds an action listener.
 void clear()
          Removes all of the child tree nodes from this tree node.
protected  void fireActionPerformed(ActionEvent actionEvent)
          Fires a given action event to all registered action listeners.
protected  void fireActionPerformed(int force, int option)
          Fires an action event to all registered action listeners.
 java.lang.Iterable<ActionListener> getActionListeners()
           
 java.util.List<TreeNodeModel<?>> getChildren()
          Returns a list of children.
 int getDepth()
          Returns the zero-based depth of the node within in its tree.
 TreeNodeModel<?> getParent()
           
protected  java.util.List<TreeNodeModel<?>> getTreeNodeList()
           
 boolean hasChild(TreeNodeModel<?> treeNode)
          Determines whether this tree node contains the given child tree node.
 boolean hasChildren()
           
 boolean isExpanded()
           
 boolean isLeaf()
          Determines whether this node could be considered a leaf node.
 boolean isSelected()
           
 java.util.Iterator<TreeNodeModel<?>> iterator()
           
 void performAction()
          Performs the action with default force and default option.
 void performAction(int force, int option)
          Performs the action with the given force and option.
 void remove(TreeNodeModel<?> treeNode)
          Removes a child tree node from this tree node.
 void removeActionListener(ActionListener actionListener)
          Removes an action listener.
 void setAllExpanded(boolean newAllExpanded)
          Sets whether all tree nodes, including this node, are expanded in this subtree.
 void setChildren(java.util.List<TreeNodeModel<?>> treeNodes)
          Sets the children in this container.
 void setExpanded(boolean newExpanded)
          Sets whether the node is expanded, showing its children, if any.
 void setParent(TreeNodeModel<?> newParent)
          Sets the parent of this tree node.
 void setSelected(boolean newSelected)
          Sets whether the tree node is selected.
 
Methods inherited from class com.guiseframework.model.DefaultValueModel
clearValue, getDefaultValue, getValue, resetValue, setValue
 
Methods inherited from class com.guiseframework.model.AbstractValueModel
createPropertyVetoException, getValidator, getValueClass, isValidValue, setValidator, validateValue
 
Methods inherited from class com.guiseframework.model.AbstractModel
getEventListenerManager, getPlainText
 
Methods inherited from class com.globalmentor.beans.BoundPropertyObject
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.guiseframework.model.ValueModel
clearValue, getDefaultValue, getValidator, getValue, getValueClass, isValidValue, resetValue, setValidator, setValue, validateValue
 
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface com.globalmentor.beans.PropertyConstrainable
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
 

Constructor Detail

DefaultTreeNodeModel

public DefaultTreeNodeModel(java.lang.Class<V> valueClass)
Constructs a tree node model indicating the type of value it can hold.

Parameters:
valueClass - The class indicating the type of value held in the model.
Throws:
java.lang.NullPointerException - if the given value class is null.

DefaultTreeNodeModel

public DefaultTreeNodeModel(java.lang.Class<V> valueClass,
                            V initialValue)
Constructs a tree node model indicating the type of value it can hold, along with an initial value.

Parameters:
valueClass - The class indicating the type of value held in the model.
initialValue - The initial value, which will not be validated.
Throws:
java.lang.NullPointerException - if the given value class is null.
Method Detail

isExpanded

public boolean isExpanded()
Specified by:
isExpanded in interface TreeNodeModel<V>
Returns:
Whether the node is expanded, showing its children, if any.

setExpanded

public void setExpanded(boolean newExpanded)
Sets whether the node is expanded, showing its children, if any. This is a bound property of type Boolean.

Specified by:
setExpanded in interface TreeNodeModel<V>
Parameters:
newExpanded - true if the node is expanded.
See Also:
TreeNodeModel.EXPANDED_PROPERTY

setAllExpanded

public void setAllExpanded(boolean newAllExpanded)
Sets whether all tree nodes, including this node, are expanded in this subtree.

Specified by:
setAllExpanded in interface TreeNodeModel<V>
Parameters:
newAllExpanded - true if all the nodes in this tree should be expanded, or false if they should be collapsed.
See Also:
setExpanded(boolean)

isSelected

public boolean isSelected()
Specified by:
isSelected in interface Selectable
Returns:
Whether the tree node is selected.

setSelected

public void setSelected(boolean newSelected)
Sets whether the tree node is selected. This is a bound property of type Boolean.

Specified by:
setSelected in interface Selectable
Parameters:
newSelected - true if the tree node should be selected, else false.
See Also:
Selectable.SELECTED_PROPERTY

getTreeNodeList

protected java.util.List<TreeNodeModel<?>> getTreeNodeList()
Returns:
The list of child tree nodes.

iterator

public java.util.Iterator<TreeNodeModel<?>> iterator()
Specified by:
iterator in interface java.lang.Iterable<TreeNodeModel<?>>
Returns:
An iterator to contained tree nodes.

isLeaf

public boolean isLeaf()
Determines whether this node could be considered a leaf node. This method may return false even if it currently has no children, if it intends to load them later and there is no way to know ahead of time if there will be children. This implementation returns the opposite value of hasChildren().

Specified by:
isLeaf in interface TreeNodeModel<V>
Returns:
true if this is a leaf node, else false if this node should not be considered a leaf.

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface TreeNodeModel<V>
Returns:
Whether this tree node has children. This implementation delegates to the tree node list.

hasChild

public boolean hasChild(TreeNodeModel<?> treeNode)
Determines whether this tree node contains the given child tree node.

Specified by:
hasChild in interface TreeNodeModel<V>
Parameters:
treeNode - The tree node to check.
Returns:
true if this tree node contains the given tree node.

add

public void add(TreeNodeModel<?> treeNode)
Adds a child tree node to this tree node.

Specified by:
add in interface TreeNodeModel<V>
Parameters:
treeNode - The tree node to add.
Throws:
java.lang.IllegalArgumentException - if the tree node already has a parent.

remove

public void remove(TreeNodeModel<?> treeNode)
Removes a child tree node from this tree node.

Specified by:
remove in interface TreeNodeModel<V>
Parameters:
treeNode - The child tree node to remove.
Throws:
java.lang.IllegalArgumentException - if the tree node is not a child of this tree node.

clear

public void clear()
Removes all of the child tree nodes from this tree node.

Specified by:
clear in interface TreeNodeModel<V>

getParent

public TreeNodeModel<?> getParent()
Specified by:
getParent in interface TreeNodeModel<V>
Returns:
The parent of this node, or null if this node has no parent.

setParent

public void setParent(TreeNodeModel<?> newParent)
Sets the parent of this tree node. This method is managed by other tree nodes, and normally should not be called by applications. A tree node cannot be given a parent if it already has a parent. A tree node's parent cannot be removed this component is still a child of that parent. A tree node's parent cannot be set unless that parent already recognizes this tree node as one of its children. If a tree node is given the same parent it already has, no action occurs.

Specified by:
setParent in interface TreeNodeModel<V>
Parameters:
newParent - The new parent for this tree node, or null if this tree node is being removed from a parent.
Throws:
java.lang.IllegalStateException - if a parent is provided and this tree node already has a parent.
java.lang.IllegalStateException - if no parent is provided and this tree node's old parent still recognizes this tree node as its child.
java.lang.IllegalArgumentException - if a parent is provided and the given parent does not already recognize this tree node as its child.
See Also:
add(TreeNodeModel), remove(TreeNodeModel)

getChildren

public java.util.List<TreeNodeModel<?>> getChildren()
Returns a list of children. This method along with #setChildren() provides a children property for alternate children access.

Returns:
A list of tree node children in order.
See Also:
iterator()

setChildren

public void setChildren(java.util.List<TreeNodeModel<?>> treeNodes)
Sets the children in this container. This method along with getChildren() provides a children property for alternate children access.

Parameters:
treeNodes - The new children of this tree node in order.
See Also:
clear(), add(TreeNodeModel)

getDepth

public int getDepth()
Returns the zero-based depth of the node within in its tree. This result represents the number of levels above this node needed to reach the root node.

Specified by:
getDepth in interface TreeNodeModel<V>
Returns:
The zero-based depth of this node from the root.

addActionListener

public void addActionListener(ActionListener actionListener)
Adds an action listener.

Specified by:
addActionListener in interface ActionListenable
Parameters:
actionListener - The action listener to add.

removeActionListener

public void removeActionListener(ActionListener actionListener)
Removes an action listener.

Specified by:
removeActionListener in interface ActionListenable
Parameters:
actionListener - The action listener to remove.

getActionListeners

public java.lang.Iterable<ActionListener> getActionListeners()
Specified by:
getActionListeners in interface ActionModel
Returns:
all registered action listeners.

performAction

public void performAction()
Performs the action with default force and default option. An ActionEvent is fired to all registered ActionListeners. This method delegates to performAction(int, int).

Specified by:
performAction in interface ActionModel

performAction

public void performAction(int force,
                          int option)
Performs the action with the given force and option. An ActionEvent is fired to all registered ActionListeners.

Specified by:
performAction in interface ActionModel
Parameters:
force - The zero-based force, such as 0 for no force or 1 for an action initiated by from a mouse single click.
option - The zero-based option, such as 0 for an event initiated by a mouse left button click or 1 for an event initiaged by a mouse right button click.

fireActionPerformed

protected void fireActionPerformed(int force,
                                   int option)
Fires an action event to all registered action listeners. This method delegates to fireActionPerformed(ActionEvent).

Parameters:
force - The zero-based force, such as 0 for no force or 1 for an action initiated by from a mouse single click.
option - The zero-based option, such as 0 for an event initiated by a mouse left button click or 1 for an event initiaged by a mouse right button click.
See Also:
ActionListener, ActionEvent

fireActionPerformed

protected void fireActionPerformed(ActionEvent actionEvent)
Fires a given action event to all registered action listeners.

Parameters:
actionEvent - The action event to fire.


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.