Package io.guise.framework.model
Class DefaultTreeNodeModel<V>
- java.lang.Object
-
- com.globalmentor.beans.BoundPropertyObject
-
- io.guise.framework.model.AbstractModel
-
- io.guise.framework.model.AbstractValueModel<V>
-
- io.guise.framework.model.DefaultValueModel<V>
-
- io.guise.framework.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
,com.globalmentor.model.MutableValued<V>
,com.globalmentor.model.Valued<V>
,ActionListenable
,ActionModel
,Model
,Selectable
,TreeNodeModel<V>
,ValueModel<V>
,java.lang.Iterable<TreeNodeModel<?>>
- Direct Known Subclasses:
DummyTreeNodeModel
,DynamicTreeNodeModel
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 viaTargetedEvent.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 io.guise.framework.model.Selectable
SELECTED_PROPERTY
-
Fields inherited from interface io.guise.framework.model.TreeNodeModel
EXPANDED_PROPERTY
-
Fields inherited from interface io.guise.framework.model.ValueModel
VALIDATOR_PROPERTY, VALUE_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(int force, int option)
Fires an action event to all registered action listeners.protected void
fireActionPerformed(ActionEvent actionEvent)
Fires a given 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 object is selected.-
Methods inherited from class io.guise.framework.model.DefaultValueModel
clearValue, getDefaultValue, getValue, resetValue, setValue
-
Methods inherited from class io.guise.framework.model.AbstractValueModel
createPropertyVetoException, getValidator, getValueClass, isValidValue, setValidator, validateValue
-
Methods inherited from class io.guise.framework.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.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
-
Methods inherited from interface io.guise.framework.model.ValueModel
clearValue, getDefaultValue, getValidator, getValue, getValueClass, isValidValue, resetValue, setValidator, setValue, validateValue
-
-
-
-
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 isnull
.
-
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 isnull
.
-
-
Method Detail
-
isExpanded
public boolean isExpanded()
- Specified by:
isExpanded
in interfaceTreeNodeModel<V>
- Returns:
- Whether the node is expanded, showing its children, if any.
-
setExpanded
public void setExpanded(boolean newExpanded)
Description copied from interface:TreeNodeModel
Sets whether the node is expanded, showing its children, if any. This is a bound property of typeBoolean
.- Specified by:
setExpanded
in interfaceTreeNodeModel<V>
- Parameters:
newExpanded
-true
if the node is expanded.- See Also:
TreeNodeModel.EXPANDED_PROPERTY
-
setAllExpanded
public void setAllExpanded(boolean newAllExpanded)
Description copied from interface:TreeNodeModel
Sets whether all tree nodes, including this node, are expanded in this subtree.- Specified by:
setAllExpanded
in interfaceTreeNodeModel<V>
- Parameters:
newAllExpanded
-true
if all the nodes in this tree should be expanded, orfalse
if they should be collapsed.- See Also:
TreeNodeModel.setExpanded(boolean)
-
isSelected
public boolean isSelected()
- Specified by:
isSelected
in interfaceSelectable
- Returns:
- Whether the object is selected.
-
setSelected
public void setSelected(boolean newSelected)
Description copied from interface:Selectable
Sets whether the object is selected. This is a bound property of typeBoolean
.- Specified by:
setSelected
in interfaceSelectable
- Parameters:
newSelected
-true
if the object should be selected, elsefalse
.- 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 interfacejava.lang.Iterable<V>
-
isLeaf
public boolean isLeaf()
Description copied from interface:TreeNodeModel
Determines whether this node could be considered a leaf node. This method may returnfalse
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.- Specified by:
isLeaf
in interfaceTreeNodeModel<V>
- Returns:
true
if this is a leaf node, elsefalse
if this node should not be considered a leaf.
-
hasChildren
public boolean hasChildren()
This implementation delegates to the tree node list.
- Specified by:
hasChildren
in interfaceTreeNodeModel<V>
- Returns:
- Whether this tree node has children. This implementation delegates to the tree node list.
-
hasChild
public boolean hasChild(TreeNodeModel<?> treeNode)
Description copied from interface:TreeNodeModel
Determines whether this tree node contains the given child tree node.- Specified by:
hasChild
in interfaceTreeNodeModel<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)
Description copied from interface:TreeNodeModel
Adds a child tree node to this tree node.- Specified by:
add
in interfaceTreeNodeModel<V>
- Parameters:
treeNode
- The tree node to add.
-
remove
public void remove(TreeNodeModel<?> treeNode)
Description copied from interface:TreeNodeModel
Removes a child tree node from this tree node.- Specified by:
remove
in interfaceTreeNodeModel<V>
- Parameters:
treeNode
- The child tree node to remove.
-
clear
public void clear()
Description copied from interface:TreeNodeModel
Removes all of the child tree nodes from this tree node.- Specified by:
clear
in interfaceTreeNodeModel<V>
-
getParent
public TreeNodeModel<?> getParent()
- Specified by:
getParent
in interfaceTreeNodeModel<V>
- Returns:
- The parent of this node, or
null
if this node has no parent.
-
setParent
public void setParent(TreeNodeModel<?> newParent)
Description copied from interface:TreeNodeModel
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 interfaceTreeNodeModel<V>
- Parameters:
newParent
- The new parent for this tree node, ornull
if this tree node is being removed from a parent.- See Also:
TreeNodeModel.add(TreeNodeModel)
,TreeNodeModel.remove(TreeNodeModel)
-
getChildren
public java.util.List<TreeNodeModel<?>> getChildren()
Returns a list of children. This method along withsetChildren(List)
provides achildren
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 withgetChildren()
provides achildren
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()
Description copied from interface:TreeNodeModel
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 interfaceTreeNodeModel<V>
- Returns:
- The zero-based depth of this node from the root.
-
addActionListener
public void addActionListener(ActionListener actionListener)
Description copied from interface:ActionListenable
Adds an action listener.- Specified by:
addActionListener
in interfaceActionListenable
- Parameters:
actionListener
- The action listener to add.
-
removeActionListener
public void removeActionListener(ActionListener actionListener)
Description copied from interface:ActionListenable
Removes an action listener.- Specified by:
removeActionListener
in interfaceActionListenable
- Parameters:
actionListener
- The action listener to remove.
-
getActionListeners
public java.lang.Iterable<ActionListener> getActionListeners()
- Specified by:
getActionListeners
in interfaceActionModel
- Returns:
- all registered action listeners.
-
performAction
public void performAction()
Description copied from interface:ActionModel
Performs the action with default force and default option. AnActionEvent
is fired to all registeredActionListener
s. This method delegates toActionModel.performAction(int, int)
.- Specified by:
performAction
in interfaceActionModel
-
performAction
public void performAction(int force, int option)
Description copied from interface:ActionModel
Performs the action with the given force and option. AnActionEvent
is fired to all registeredActionListener
s.- Specified by:
performAction
in interfaceActionModel
- 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 initiated 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 tofireActionPerformed(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.
-
-