com.sas.models
Class Node

com.sas.models.Node
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.lang.ObjectDataInterface, ModelInterface, MutableNodeInterface, MutableSimpleNodeInterface, NodeInterface, SimpleNodeInterface, StaticNodeStyleInterface, TreeInterface, java.io.Serializable
Direct Known Subclasses:
ActionNode, ClassNode, MenuBarNode, MenuItemNode, MenuNode, NodeIcon, SelectorMenuItemNode, TreeNode

public class Node
implements NodeInterface, ModelInterface, MutableNodeInterface, MutableSimpleNodeInterface, StaticNodeStyleInterface, TreeInterface, com.sas.lang.ObjectDataInterface, com.sas.beans.PropertyChangeSource, java.io.Serializable

Node is a generic implementation of NodeInterface and MutableSimpleNodeInterface. Node is a single unit in a hierarchical structure. It provides textual descriptions, children and user specified data. PropertyChangeEvent events will be fired for the properties of Node whenever they are set or modified.

See Also:
Serialized Form

Field Summary
protected  OrderedCollection children
          nodeChildren property.
protected  StaticPropertyBagInterface defaultNodeStyle
          defaultNodeStyle property.
protected  java.lang.String expandedNodeText
          nodeExpandedText property.
protected  boolean externalUpdateSupported
          externalUpdateSupported property.
protected  boolean hasChildren
          Field used for leaf property.
protected  StaticPropertyBagInterface nodeStyle
          nodeStyle property.
protected  java.lang.String nodeText
          nodeText property.
protected  java.lang.String nodeType
          nodeType property.
protected  java.lang.Object objectData
          objectData property.
static java.lang.String RB_KEY
           
 
Constructor Summary
Node()
          Constructs a Node object.
Node(java.lang.String nodeText)
          Constructs a Node object with the specified text.
Node(java.lang.String nodeText, java.lang.String nodeType)
          Constructs a Node object with the specified text and type.
 
Method Summary
 void addItems(java.util.Enumeration enumer)
          Appends the enumeration of SimpleNodeInterface objects to the children of the current node.
 void addNodeChild(SimpleNodeInterface node)
          Add the specified node to the end of the child list.
 void addNodeChild(SimpleNodeInterface node, int index)
          Adds a child at index.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a listener for the java.beans.PropertyChangeEvent event.
 boolean attachView()
          Called during an attachModel call on the view.
 int countNodeChildren(int maximumChildCount)
          Returns the number of children.
 void detachView()
          Called during a detachModel call on the view.
protected  void firePropertyChange(java.beans.PropertyChangeEvent event)
          Calls notifyPropertyChange to fire the event to all registered listeners.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Creates a PropertyChangeEvent and calls notifyPropertyChange to fire the event to all registered listeners.
 StaticPropertyBagInterface getDefaultNodeStyle()
          Returns the default node style for this node and all of this node's descendants.
 int getIndex(NodeInterface item, int startIndex)
          Returns the 0-based index associated with the NodeInterface object in the children collection (searches forward)
 SimpleNodeInterface getNodeChild(int index)
          Returns the child node at the specified 0-based index.
 int getNodeChildCount()
          Returns the number of children.
 StaticOrderedCollectionInterface getNodeChildren()
          Returns the children of the current node.
 SimpleNodeInterface[] getNodeChildren(int startIndex, int count)
          Returns a range of child nodes.
 java.lang.String getNodeExpandedText()
          Returns the expanded text for the current node.
 StaticPropertyBagInterface getNodeStyle()
          Returns the style for this node.
 java.lang.String getNodeText()
          Returns the text for the current node.
 java.lang.String getNodeType()
          Returns the type of the current node.
 java.lang.String[] getNodeTypes()
          Returns the complete set of types for a node.
 java.lang.Object getObjectData()
          Returns user-supplied data for the current node.
 NodeInterface getRoot()
          Returns the current node (this) to serve as the root node.
 boolean isExternalUpdateSupported()
           
 boolean isLeafNode()
          Indicates whether the current Node is a leaf (has no children).
 void moveNodeChild(int startIndex, int endIndex)
          Moves the child at startIndex to endIndex.
protected  void notifyPropertyChange(java.beans.PropertyChangeEvent event)
          Sends a PropertyChangeEvent event to all the PropertyChangeListener objects in the listener list.
 void removeAllNodeChildren()
          Removes all children.
 void removeNodeChild(int index)
          Removes the child at index.
 void removeNodeChild(SimpleNodeInterface node)
          Removes node from the current node.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a listener for the java.beans.PropertyChangeEvent event.
 void setDefaultNodeStyle(StaticPropertyBagInterface newValue)
          Sets the default node style for this node and all of this node's descendants.
 void setExternalUpdateSupported(boolean newValue)
          Sets the value of the externalUpdateSupported property.
 void setNodeChildren(StaticOrderedCollectionInterface newValue)
          Sets the children for the current node.
 void setNodeExpandedText(java.lang.String newValue)
          Sets the expanded text of the current node.
 void setNodeStyle(StaticPropertyBagInterface newValue)
          Sets the node style for this node and all of this node's descendants.
 void setNodeText(java.lang.String newValue)
          Sets the text of the current node.
 void setNodeType(java.lang.String newValue)
          Sets the type of the current node.
 void setObjectData(java.lang.Object newValue)
          Sets the object data for the current node.
 void sort(com.sas.util.Comparator comparator)
          Sorts the children collection in place using the provided comparison function.
 java.lang.String toString()
          Returns the value of the nodeText property.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

hasChildren

protected boolean hasChildren
Field used for leaf property. A value of false indicates that the current node is a leaf.


children

protected OrderedCollection children
nodeChildren property.


expandedNodeText

protected java.lang.String expandedNodeText
nodeExpandedText property.


externalUpdateSupported

protected boolean externalUpdateSupported
externalUpdateSupported property.


nodeText

protected java.lang.String nodeText
nodeText property.


nodeType

protected java.lang.String nodeType
nodeType property.


objectData

protected java.lang.Object objectData
objectData property.


nodeStyle

protected StaticPropertyBagInterface nodeStyle
nodeStyle property.


defaultNodeStyle

protected StaticPropertyBagInterface defaultNodeStyle
defaultNodeStyle property.

Constructor Detail

Node

public Node()
Constructs a Node object.


Node

public Node(java.lang.String nodeText)
Constructs a Node object with the specified text. The nodeText property will be initialized with the specified text string.

Parameters:
nodeText - the initial value for the nodeText property

Node

public Node(java.lang.String nodeText,
            java.lang.String nodeType)
Constructs a Node object with the specified text and type. The nodeText and nodeType properties will be initialized with the specified text and type strings.

Parameters:
nodeText - the initial value for the nodeText property
nodeType - the initial value for the nodeType property
Method Detail

countNodeChildren

public int countNodeChildren(int maximumChildCount)
Returns the number of children. This is provided for the implementation of SimpleNodeInterface. Since the child count can never be unknown, countNodeChildren should not be called. It ignores the maximumChildCount parameter and returns the result of getNodeChildCount.

Specified by:
countNodeChildren in interface SimpleNodeInterface
Parameters:
maximumChildCount - this parameter is ignored
Returns:
the result of getNodeChildCount

getNodeChildCount

public int getNodeChildCount()
Returns the number of children.

Specified by:
getNodeChildCount in interface SimpleNodeInterface
Returns:
the number of children or 0 if no children

isLeafNode

public boolean isLeafNode()
Indicates whether the current Node is a leaf (has no children).

Specified by:
isLeafNode in interface SimpleNodeInterface
Returns:
true if the current node is a leaf, otherwise false

getNodeChild

public SimpleNodeInterface getNodeChild(int index)
Returns the child node at the specified 0-based index. If there are no children, null is returned.

Specified by:
getNodeChild in interface SimpleNodeInterface
Parameters:
index - the 0-based index of the child to get
Returns:
the child node object (as type SimpleNodeInterface) at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range [0, nodeChildCount-1]
See Also:
getNodeChildren(int, int), setNodeChildren(com.sas.collection.StaticOrderedCollectionInterface)

getNodeChildren

public SimpleNodeInterface[] getNodeChildren(int startIndex,
                                             int count)
Returns a range of child nodes. The number of nodes specified by count are returned starting at startIndex. If there are no children, null is returned.

Specified by:
getNodeChildren in interface SimpleNodeInterface
Parameters:
startIndex - 0-based index which identifies the start of the range
count - the amount of children to get
Returns:
an array of child node objects (as type SimpleNodeInterface) for the specified range
Throws:
java.lang.IndexOutOfBoundsException - if startIndex is out of range [0, nodeChildCount-1] or if startIndex + count > nodeChildCount
See Also:
getNodeChild(int), setNodeChildren(com.sas.collection.StaticOrderedCollectionInterface)

getNodeExpandedText

public java.lang.String getNodeExpandedText()
Returns the expanded text for the current node. The expanded text is used to provide a more descriptive text string for a node.

Specified by:
getNodeExpandedText in interface NodeInterface
Returns:
the value of the nodeExpandedText property
See Also:
setNodeExpandedText(java.lang.String)

getNodeType

public java.lang.String getNodeType()
Returns the type of the current node. The type is a text string which allows the user of a node hierarchy to add more information to nodes. For example nodes in a file system viewer could use "file" or "directory" as the type to distinguish between nodes representing files and directories.

Specified by:
getNodeType in interface NodeInterface
Returns:
the type of the current node
See Also:
setNodeType(java.lang.String)

getNodeText

public java.lang.String getNodeText()
Returns the text for the current node.

Specified by:
getNodeText in interface NodeInterface
Returns:
the text for the current node.
See Also:
setNodeText(java.lang.String)

addNodeChild

public void addNodeChild(SimpleNodeInterface node)
Add the specified node to the end of the child list. This is a convience method for addNodeChild(node, -1).

Parameters:
node - the child to add

addNodeChild

public void addNodeChild(SimpleNodeInterface node,
                         int index)
Adds a child at index. A value of -1 for index indicates that the child is to be appended to the child list.

Specified by:
addNodeChild in interface MutableSimpleNodeInterface
Parameters:
node - the child to add
index - the position at which to add the child
See Also:
MutableSimpleNodeInterface

removeNodeChild

public void removeNodeChild(SimpleNodeInterface node)
Removes node from the current node. This is an alias to removeNodeChild(int).

Specified by:
removeNodeChild in interface MutableSimpleNodeInterface
Parameters:
node - the child to remove
See Also:
removeNodeChild(int), MutableSimpleNodeInterface

removeNodeChild

public void removeNodeChild(int index)
Removes the child at index.

Specified by:
removeNodeChild in interface MutableSimpleNodeInterface
Parameters:
index - the position at which to remove the child
See Also:
MutableSimpleNodeInterface

removeAllNodeChildren

public void removeAllNodeChildren()
Removes all children.

Specified by:
removeAllNodeChildren in interface MutableSimpleNodeInterface
See Also:
MutableSimpleNodeInterface

moveNodeChild

public void moveNodeChild(int startIndex,
                          int endIndex)
Moves the child at startIndex to endIndex.

Specified by:
moveNodeChild in interface MutableSimpleNodeInterface
Parameters:
startIndex - the current position of the child
endIndex - the new position of the child
See Also:
MutableSimpleNodeInterface

isExternalUpdateSupported

public boolean isExternalUpdateSupported()
Specified by:
isExternalUpdateSupported in interface MutableSimpleNodeInterface
See Also:
MutableSimpleNodeInterface.isExternalUpdateSupported(), setExternalUpdateSupported(boolean)

getNodeStyle

public StaticPropertyBagInterface getNodeStyle()
Returns the style for this node. Any values in the node style will not be inherited by descendants of this node.

Specified by:
getNodeStyle in interface StaticNodeStyleInterface
Returns:
a StaticPropertyBagInterface or null
See Also:
setNodeStyle(com.sas.collection.StaticPropertyBagInterface)

getDefaultNodeStyle

public StaticPropertyBagInterface getDefaultNodeStyle()
Returns the default node style for this node and all of this node's descendants.

Specified by:
getDefaultNodeStyle in interface StaticNodeStyleInterface
Returns:
a StaticPropertyBagInterface or null
See Also:
setDefaultNodeStyle(com.sas.collection.StaticPropertyBagInterface)

getNodeTypes

public java.lang.String[] getNodeTypes()
Returns the complete set of types for a node. NOTE: This property is not currently used.

Specified by:
getNodeTypes in interface StaticNodeStyleInterface
Returns:
null, or a string array of all the possible node types.

addItems

public void addItems(java.util.Enumeration enumer)
Appends the enumeration of SimpleNodeInterface objects to the children of the current node.

Parameters:
enumer - the SimpleNodeInterface objects to add as children

getIndex

public int getIndex(NodeInterface item,
                    int startIndex)
Returns the 0-based index associated with the NodeInterface object in the children collection (searches forward)

Parameters:
item - NodeInterface to search for
startIndex - the position where the search should start
Returns:
int the 0-based index corresponding to the NodeInterface object or -1 if the item is not found.
Throws:
java.lang.IndexOutOfBoundsException - if the start index is invalid

getNodeChildren

public StaticOrderedCollectionInterface getNodeChildren()
Returns the children of the current node. The return value will never be null. This property is not serialized, therefore any listeners to the returned collection need to be setup again after deserialization.

Returns:
children of the current node

getObjectData

public java.lang.Object getObjectData()
Returns user-supplied data for the current node.

Specified by:
getObjectData in interface com.sas.lang.ObjectDataInterface
Returns:
user data for this node
See Also:
setObjectData(java.lang.Object)

getRoot

public NodeInterface getRoot()
Returns the current node (this) to serve as the root node. This is the implementation of TreeInterface which allows a single node to be set as the model for a viewer that requires TreeInterface (such as com.sas.visuals.TreeView).

Specified by:
getRoot in interface TreeInterface
Returns:
the current node (this)
See Also:
TreeInterface, TreeView

setExternalUpdateSupported

public void setExternalUpdateSupported(boolean newValue)
Sets the value of the externalUpdateSupported property.

Parameters:
newValue - true to allow external updates, false otherwise
See Also:
isExternalUpdateSupported()

setNodeChildren

public void setNodeChildren(StaticOrderedCollectionInterface newValue)
Sets the children for the current node.

Parameters:
newValue - the new set of children
See Also:
getNodeChild(int), getNodeChildren(int, int)

setNodeExpandedText

public void setNodeExpandedText(java.lang.String newValue)
Sets the expanded text of the current node.

Specified by:
setNodeExpandedText in interface MutableNodeInterface
Parameters:
newValue - the new value for the nodeExpandedText property
See Also:
getNodeExpandedText()

setNodeType

public void setNodeType(java.lang.String newValue)
Sets the type of the current node. The type can be used for categorizing nodes.

Specified by:
setNodeType in interface MutableNodeInterface
Parameters:
newValue - the new value for the nodeType property
See Also:
getNodeType()

setNodeText

public void setNodeText(java.lang.String newValue)
Sets the text of the current node.

Specified by:
setNodeText in interface MutableNodeInterface
Parameters:
newValue - the new value for the nodeText property
See Also:
getNodeText()

setObjectData

public void setObjectData(java.lang.Object newValue)
Sets the object data for the current node.

Specified by:
setObjectData in interface com.sas.lang.ObjectDataInterface
Parameters:
newValue - the new value for the objectData property
See Also:
getObjectData()

sort

public void sort(com.sas.util.Comparator comparator)
Sorts the children collection in place using the provided comparison function.

Parameters:
comparator - the comparison function to use for sorting

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Creates a PropertyChangeEvent and calls notifyPropertyChange to fire the event to all registered listeners.

Parameters:
propertyName - the name of the property that has changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

protected void firePropertyChange(java.beans.PropertyChangeEvent event)
Calls notifyPropertyChange to fire the event to all registered listeners.

Parameters:
event - the event being fired

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a listener for the java.beans.PropertyChangeEvent event.

Specified by:
addPropertyChangeListener in interface com.sas.beans.PropertyChangeSource
Parameters:
listener - an object which handles PropertyChangeEvent events. The listener is not added a second time if it already exists in the list of listeners for this event.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a listener for the java.beans.PropertyChangeEvent event. Nothing happens if the listener is not in the list of listeners for this event.

Specified by:
removePropertyChangeListener in interface com.sas.beans.PropertyChangeSource
Parameters:
listener - an object which handles PropertyChangeEvent events

notifyPropertyChange

protected void notifyPropertyChange(java.beans.PropertyChangeEvent event)
Sends a PropertyChangeEvent event to all the PropertyChangeListener objects in the listener list. The listener list is copied first, so the event is sent only to each item which is in the list at the time of this copy, even if adds or removes are performed after the send has started.

Parameters:
event - the event to send

attachView

public boolean attachView()
Called during an attachModel call on the view. Node always returns true indicating that attaching to a viewer is allowed.

Specified by:
attachView in interface ModelInterface
Returns:
Always returns true
See Also:
ModelInterface.detachView(), ViewInterface.attachModel(com.sas.ModelInterface)

detachView

public void detachView()
Called during a detachModel call on the view. The detachView method serves as a hook to receive notification that a view is detaching from it.

Specified by:
detachView in interface ModelInterface
See Also:
ModelInterface.attachView(), ViewInterface.detachModel(com.sas.ModelInterface)

toString

public java.lang.String toString()
Returns the value of the nodeText property.

Overrides:
toString in class java.lang.Object
Returns:
the value of the nodeText property

setNodeStyle

public void setNodeStyle(StaticPropertyBagInterface newValue)
Sets the node style for this node and all of this node's descendants.

Parameters:
newValue - the new StaticPropertyBagInterface value for the nodeStyle property
See Also:
getNodeStyle()

setDefaultNodeStyle

public void setDefaultNodeStyle(StaticPropertyBagInterface newValue)
Sets the default node style for this node and all of this node's descendants.

Parameters:
newValue - the new StaticPropertyBagInterface value for the defaultNodeStyle property
See Also:
getDefaultNodeStyle()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.