at.spardat.xma.mdl.tree
Class TreeNode

java.lang.Object
  extended byat.spardat.xma.mdl.tree.TreeNode

public class TreeNode
extends java.lang.Object

Represents a node in a tree widget model.


Constructor Summary
protected TreeNode()
          Internal use constructor.
  TreeNode(java.lang.Object parent, int index, java.lang.String key, java.lang.String text, int imageId)
          Constructs a TreeNode and makes it the child of parent at a specified zero based index in the child sequence.
  TreeNode(java.lang.Object parent, int index, java.lang.String key, java.lang.String text, int imageId, boolean addDummyNode)
          Constructs a TreeNode and makes it the child of parent at a specified zero based index in the child sequence.
  TreeNode(java.lang.Object parent, java.lang.String key, java.lang.String text, int imageId)
          Constructs a TreeNode and makes it the last child of parent.
  TreeNode(java.lang.Object parent, java.lang.String key, java.lang.String text, int imageId, boolean addDummyNode)
          Constructs a TreeNode and makes it the last child of parent.
 
Method Summary
 boolean addDummyNode()
          Adds a dummy node as child to this node to make this node expandable.
protected  TreeNode cloneSubTree(java.lang.Object parent)
          This method makes a copy of the subtree rooted at this and returns it.
 void deselect()
          Deselects this tree node if it is selected.
protected  void externalize(XmaOutput o)
          Writes this node to the output stream.
 NodeColor getBackgroundColor()
          Returns the foreground color set of null, if no color is set.
 TreeNode getChild(int i)
          Returns the child at the zero based index i which must be greater equal zero and less than getChildCount().
 int getChildCount()
          Returns the number of childs this node has.
 TreeNode[] getChilds()
          Returns an array of TreeNode objects that are the childs of this TreeNode.
 NodeColor getForegroundColor()
          Returns the foreground color set of null, if no color is set.
 short getImageId()
          Returns the image id of the image of this node or 0 if none has been set.
 java.lang.String getKey()
          Returns the key of this node.
 TreeNode getParent()
          Returns the parent of this tree node or null, if this node is a root node.
protected  java.lang.String getParentKey()
          Returns the key of the parent node of this if this node is an inner node or null, if this node is a root.
 java.lang.String getProperty(java.lang.String key)
          Returns an auxiliary property for a given key.
 java.lang.String getText()
          Returns the text of this node.
static TreeNode getTreeNodeFor(java.lang.Object uiTreeItem)
          This is the inverse method to getUITreeItem.
 java.lang.Object getUITreeItem()
          At the client side, this TreeNode has a representation in a UI library.
 boolean hasDummyNode()
          Tests if a dummy node exists to this node.
protected  void internalize(XmaInput in)
          Reads the instance variables text_, key_ and imageId_ from the stream.
 boolean isDummyNode()
          Tests if a node is a dummy node created by addDummyNode() or by the TreeNode constructor.
 boolean isLazy()
          Shows if this node supports the lazy loading of child nodes.
 boolean isLeaf()
          Returns true if this node does not have child nodes.
static boolean isReservedPropertyKey(java.lang.String s)
          Returns true if s denotes a reserved property key.
 boolean isRoot()
          Returns true if this node is a root node, i.e., there is no other node where one of its childs is this node.
 boolean isSelected()
          Returns true if this tree node is selected, false otherwise.
 void remove()
          Removes this tree node from the tree.
 boolean removeDummyNode()
          Removes a dummy node created by addDummyNode() or by the TreeNode constructor.
 void select()
          Marks this tree node to be selected.
 void setBackgroundColor(NodeColor c)
          Sets the foreground color of this TreeNode.
 void setExpanded(boolean expanded)
          Sets the expansion status of this tree node.
 void setForegroundColor(NodeColor c)
          Sets the foreground color of this TreeNode.
 void setImageId(short s)
          Sets a new image id.
 void setProperty(java.lang.String key, java.lang.String value)
          Sets an auxiliary property.
 void setText(java.lang.String string)
          Sets a new text.
protected  int streamedSize()
          Returns the size of the hypothetical byte stream if this node would be externalized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode(java.lang.Object parent,
                int index,
                java.lang.String key,
                java.lang.String text,
                int imageId,
                boolean addDummyNode)
Constructs a TreeNode and makes it the child of parent at a specified zero based index in the child sequence.

Parameters:
parent - may be ITreeWM in which case this node becomes a root node or a TreeNode in which case this becomes a direct child of parent.
index - the zero based index into the sequence of childs this node should get. 0 inserts in front, getChildCount() inserts at the tail of the childs.
key - the key of the new node. This key must not already be contained in the tree.
text - the text that is displayed in the node
imageId - an optinal id of an image to be displayed. Specify 0 if no image should be displayed.
addDummyNode - adds a dummy node as child to this node to make this node expandable. The dummy node is automatically removed at the client side if an expand event occurs on this node.
Throws:
java.lang.RuntimeException - on invalid arguments.

TreeNode

public TreeNode(java.lang.Object parent,
                int index,
                java.lang.String key,
                java.lang.String text,
                int imageId)
Constructs a TreeNode and makes it the child of parent at a specified zero based index in the child sequence.

Parameters:
parent - may be ITreeWM in which case this node becomes a root node or a TreeNode in which case this becomes a direct child of parent.
index - the zero based index into the sequence of childs this node should get. 0 inserts in front, getChildCount() inserts at the tail of the childs.
key - the key of the new node. This key must not already be contained in the tree.
text - the text that is displayed in the node
imageId - an optinal id of an image to be displayed. Specify 0 if no image should be displayed.
Throws:
java.lang.RuntimeException - on invalid arguments.

TreeNode

public TreeNode(java.lang.Object parent,
                java.lang.String key,
                java.lang.String text,
                int imageId,
                boolean addDummyNode)
Constructs a TreeNode and makes it the last child of parent.

Parameters:
parent - may be TreeWM in which case this node becomes a root node or a TreeNode in which case this becomes a direct child of parent.
key - the key of the new node. This key must not already be contained in the tree.
text - the text that is displayed in the node
imageId - an optinal id of an image to be displayed. Specify 0 if no image should be displayed.
addDummyNode - adds a dummy node as child to this node to make this node expandable. The dummy node is automatically removed at the client side if an expand event occurs on this node.
Throws:
java.lang.RuntimeException - on invalid arguments.

TreeNode

public TreeNode(java.lang.Object parent,
                java.lang.String key,
                java.lang.String text,
                int imageId)
Constructs a TreeNode and makes it the last child of parent.

Parameters:
parent - may be TreeWM in which case this node becomes a root node or a TreeNode in which case this becomes a direct child of parent.
key - the key of the new node. This key must not already be contained in the tree.
text - the text that is displayed in the node
imageId - an optinal id of an image to be displayed. Specify 0 if no image should be displayed.
Throws:
java.lang.RuntimeException - on invalid arguments.

TreeNode

protected TreeNode()
Internal use constructor.

Method Detail

hasDummyNode

public boolean hasDummyNode()
Tests if a dummy node exists to this node. (A dummy node created by addDummyNode() or by the TreeNode constructor)

Returns:
true if a dummy node exists to this node - otherwise false.
Since:
version_number

addDummyNode

public boolean addDummyNode()
Adds a dummy node as child to this node to make this node expandable. The dummy node is automatically removed at the client side if an expand event occurs on this node. There can only exitst one dummy node for every node. Therefore a repeated call to this method does nothing.

Returns:
true - if a dummy node was added, false otherwise.
Since:
version_number

removeDummyNode

public boolean removeDummyNode()
Removes a dummy node created by addDummyNode() or by the TreeNode constructor. If no dummy node exists thsi method does nothing. This method is called by the XMA framework if an expand event occurs on this node.

Returns:
true - if a dummy node was removed, false otherwise.
Since:
version_number

isDummyNode

public boolean isDummyNode()
Tests if a node is a dummy node created by addDummyNode() or by the TreeNode constructor.

Returns:
true if this node is a dummy node.
Since:
version_number

getChilds

public TreeNode[] getChilds()
Returns an array of TreeNode objects that are the childs of this TreeNode.

Returns:
the childs of this. The array is empty if this does not has childs.

getChild

public TreeNode getChild(int i)
Returns the child at the zero based index i which must be greater equal zero and less than getChildCount().

Parameters:
i - zero based index of the child
Returns:
the requested child
Throws:
java.lang.RuntimeException - if index is invalid

getParent

public TreeNode getParent()
Returns the parent of this tree node or null, if this node is a root node.


getChildCount

public int getChildCount()
Returns the number of childs this node has.


getImageId

public short getImageId()
Returns the image id of the image of this node or 0 if none has been set.


getKey

public java.lang.String getKey()
Returns the key of this node.

Returns:
the key which is never null.

getText

public java.lang.String getText()
Returns the text of this node.

Returns:
the text wich is never null.

setImageId

public void setImageId(short s)
Sets a new image id.


setText

public void setText(java.lang.String string)
Sets a new text.

Throws:
java.lang.IllegalArgumentException - if text is null.

remove

public void remove()
Removes this tree node from the tree. This method also removes all nodes which are direct or indirect childs of this node. You cannot access this and its direct or indirect childs anymore after this method terminates.


select

public void select()
Marks this tree node to be selected. Calling this method is the same as calling select(key) on the tree widget model.


deselect

public void deselect()
Deselects this tree node if it is selected. If it is not selected, this method does nothing. The same as calling deselect(key) on the tree widget model.


isSelected

public boolean isSelected()
Returns true if this tree node is selected, false otherwise.


setExpanded

public void setExpanded(boolean expanded)
Sets the expansion status of this tree node.

This method must not be called at the server side, but only on the client side in the state where the UI is created. If the UI is not created yet or this method is called in server side code, this method does nothing.

Parameters:
expanded - true, if this tree node should be shown in an expanded state.

getUITreeItem

public java.lang.Object getUITreeItem()
At the client side, this TreeNode has a representation in a UI library. In the case of SWT, every TreeNode has a SWT TreeItem assigned. If you want to set some visual attributes on the TreeItem, you may call this method and cast the returned Object down to a SWT-TreeItem.

You must not change the text or the image of the returned SWT TreeItem. If you want to change these attributes, use either setText or setImageId in this class.

Returns:
if SWT is your UI-library, returns a SWT-TreeItem if your code is running at the client side and you have a constructed UI. Otherwise returns null. Note that the SWT UI widget (Tree) must be alive in order for this method to work.

getTreeNodeFor

public static TreeNode getTreeNodeFor(java.lang.Object uiTreeItem)
This is the inverse method to getUITreeItem. It returns the TreeNode that corresponds to the tree item of the underlying UI library. In the case of SWT, the argument must be an instance of class TreeItem.

Parameters:
uiTreeItem - SWT-TreeItem if SWT the UI-library you are using. Must not be null. The SWT-TreeItem must not be disposed.
Returns:
TreeNode for the given TreeItem

isRoot

public boolean isRoot()
Returns true if this node is a root node, i.e., there is no other node where one of its childs is this node.


isLeaf

public boolean isLeaf()
Returns true if this node does not have child nodes.


setForegroundColor

public void setForegroundColor(NodeColor c)
Sets the foreground color of this TreeNode.

Parameters:
c - object denoting the foreground color or null if the color should be cleared.

setBackgroundColor

public void setBackgroundColor(NodeColor c)
Sets the foreground color of this TreeNode.

Parameters:
c - object denoting the foreground color or null if the color should be cleared.

getForegroundColor

public NodeColor getForegroundColor()
Returns the foreground color set of null, if no color is set.


getBackgroundColor

public NodeColor getBackgroundColor()
Returns the foreground color set of null, if no color is set.


setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Sets an auxiliary property.

Parameters:
key - the key of the property. Must not be a key of length 1 because those are reserved. Must not be null.
value - the value. If null, the property is cleared.

getProperty

public java.lang.String getProperty(java.lang.String key)
Returns an auxiliary property for a given key.

Parameters:
key - the key of the property. Must not be a key of length 1 because those are reserved. Must not be null.
Returns:
value of the property or null, if this property is not set.

streamedSize

protected int streamedSize()
Returns the size of the hypothetical byte stream if this node would be externalized.


getParentKey

protected java.lang.String getParentKey()
Returns the key of the parent node of this if this node is an inner node or null, if this node is a root.


cloneSubTree

protected TreeNode cloneSubTree(java.lang.Object parent)
This method makes a copy of the subtree rooted at this and returns it. The subtree is a perfect deep copy. The tree_ instance in the copied subtree is the same as in the original one.

Parameters:
parent - the new parent of the returned TreeNode.

externalize

protected void externalize(XmaOutput o)
                    throws java.io.IOException
Writes this node to the output stream. Just this node, not the childs nor any child information.

Throws:
java.io.IOException

internalize

protected void internalize(XmaInput in)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
Reads the instance variables text_, key_ and imageId_ from the stream.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

isReservedPropertyKey

public static boolean isReservedPropertyKey(java.lang.String s)
Returns true if s denotes a reserved property key.


isLazy

public boolean isLazy()
Shows if this node supports the lazy loading of child nodes. The lazy loading is implemented by adding a dummynode to this node and so making a childless node expandable. The dummynode is removed before the expand event at the client side, the isLazy() returns true in the expand event but is set to false after the first expand event occured on this node.

Returns:
true if a node is lazy, i.e. expandable without real child nodes.