com.ca.directory.jxplorer.tree
Class SmartNode

java.lang.Object
  |
  +--javax.swing.tree.DefaultMutableTreeNode
        |
        +--com.ca.directory.jxplorer.tree.SmartNode
All Implemented Interfaces:
java.lang.Cloneable, javax.swing.tree.MutableTreeNode, java.io.Serializable, java.awt.datatransfer.Transferable, javax.swing.tree.TreeNode

public class SmartNode
extends javax.swing.tree.DefaultMutableTreeNode
implements java.awt.datatransfer.Transferable

See Also:
Serialized Form

Field Summary
static java.lang.String DUMMYMESSAGE
           
static java.lang.String ROOTNAME
           
static java.awt.datatransfer.DataFlavor UNICODETEXT
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
SmartNode()
          Constructor for dummy nodes; used to flag possibly expandable nodes when their children status is unknown (due to not having been read from the directory yet.)
SmartNode(RDN rdn)
          Simple constructor, for when objectClass attributes are not known
SmartNode(SmartNode S)
          Copy constructor, for when an RDN is the same, but the tree position (and hence the full DN) is different.
SmartNode(java.lang.String rdnString)
          Simple constructor, for when objectClass attributes are not known
SmartNode(java.lang.String RDN, DXAttribute objectClasses)
          When objectClass attributes are known, we try to be cleverer getting the icon for this node.
 
Method Summary
 void copyChildren(java.util.Enumeration children)
          A utility ftn that makes copies of all the child nodes given to it, and adds the copies to the current node.
 java.lang.String getBlankRootName()
          Returns the name of the 'blank root' (i.e.
 java.lang.String getDistinguishedValue()
          Writes out the nodes RDN as a string, displaying just the value of the RDN
 DN getDN()
           
 java.lang.String getDummyMessage()
          Returns the string to display when the node is a 'dummy'.
 javax.swing.ImageIcon getIcon()
          gets the icon associated with this node.
 java.lang.String getIconName()
          returns the icon name (without the extension).
 java.lang.String getObjectClass()
          returns the ldap class type of the node
 javax.swing.JPopupMenu getPopupMenu()
          It is possible to register a special popup menu that is called when this node is 'right-clicked' on.
 RDN getRDN()
          Returns the RDN of the tree node as a String.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor df)
           
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
 boolean hasChild(RDN r)
          Returns whether this node has the corresponding node as a child.
 boolean hasChild(SmartNode n)
          Returns whether this node has the corresponding node as a child.
 boolean hasChild(java.lang.String testRDN)
          Returns whether this node has the corresponding node as a child.
 boolean hasDummy()
          Returns whether this node has a dummy node.
static void init(javax.swing.JComponent tempDisplay, CBResourceLoader resourceLoader)
          Pre load the image icons... we'll be using them a lot Image icons are stored in the 'icons' hashtable, keyed on their file name stem.
 boolean isAlwaysRefresh()
          Experimental - returns true if the node should always 'refresh' when it is expanded by the tree...
 boolean isBlankRoot()
          The root node is sometimes blank.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavour)
           
 boolean isDummy()
          Sometimes a dummy node is used to signal that there may be child nodes below a given node, but we haven't actually read those nodes yet.
 boolean isMultiValued()
           
 boolean isRoot()
          The root node is sometimes blank, but displayed to the user with a different name.
 boolean isStructural()
           
 boolean rdnEquals(RDN testRDN)
          Check if a SmartNode has the same RDN as the passed RDN.
 void setAlwaysRefresh(boolean state)
          Experimental - sets if the node should always 'refresh' (i.e. reload all children) when it is expanded by the tree...
 void setIcon(javax.swing.ImageIcon newIcon)
          Rarely used method to force a particular icon to be used by this particular node.
 void setPopupMenu(javax.swing.JPopupMenu popupMenu)
          It is possible to register a special popup menu that is called when this node is 'right-clicked' on.
 void setRoot(boolean state)
          This sets the root status of the node (default=false).
 void setStructural(boolean val)
           
 void setTrueObjectClass(DXAttribute objectClasses)
          If available, it is best to use the object class of the entry (to determine which icon to display 'n stuff).
 boolean setTrueObjectClass(java.lang.String value)
          This attempts to set the object class of the node to a particular value.
 void sort()
          This sorts the children of the current node by the alphabetic value of their naming attribute value; e.g. in cn=doofus, by 'doofus'.
 java.lang.String toString()
          Writes out the nodes RDN as a string,
 void update(RDN newRDN)
           
 void update(java.lang.String rdn)
          Takes an ldap RDN string such as 'ou=DemoCorp', and breaks it into a nodeObjectClass ('ou') and a distinguished value ('DemoCorp'), and replaces the existing values of these variables.
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROOTNAME

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

DUMMYMESSAGE

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

UNICODETEXT

public static final java.awt.datatransfer.DataFlavor UNICODETEXT
Constructor Detail

SmartNode

public SmartNode()
Constructor for dummy nodes; used to flag possibly expandable nodes when their children status is unknown (due to not having been read from the directory yet.)


SmartNode

public SmartNode(java.lang.String rdnString)
Simple constructor, for when objectClass attributes are not known


SmartNode

public SmartNode(RDN rdn)
Simple constructor, for when objectClass attributes are not known


SmartNode

public SmartNode(SmartNode S)
Copy constructor, for when an RDN is the same, but the tree position (and hence the full DN) is different. Does Not makes copies of children: use copyChildren() separately if you want this.

Parameters:
S - the node to copy for initial values.

SmartNode

public SmartNode(java.lang.String RDN,
                 DXAttribute objectClasses)
When objectClass attributes are known, we try to be cleverer getting the icon for this node.

Parameters:
RDN - the RDN of the new node (e.g. 'cn=fnord')
objectClasses - a javax.naming.directory Attribute containing a list of the node's ldap objectClasses.
Method Detail

init

public static void init(javax.swing.JComponent tempDisplay,
                        CBResourceLoader resourceLoader)
Pre load the image icons... we'll be using them a lot Image icons are stored in the 'icons' hashtable, keyed on their file name stem. (i.e. person.gif is stored with key 'person')


setTrueObjectClass

public void setTrueObjectClass(DXAttribute objectClasses)
If available, it is best to use the object class of the entry (to determine which icon to display 'n stuff). This does a quick 'n dirty search if the object class attribute is known. Better is to manually set the deepest object class, but this requires knowledge of the schema 'n stuff...


setTrueObjectClass

public boolean setTrueObjectClass(java.lang.String value)
This attempts to set the object class of the node to a particular value. It returns true if an icon is available for that object class, false otherwise.


update

public void update(java.lang.String rdn)
Takes an ldap RDN string such as 'ou=DemoCorp', and breaks it into a nodeObjectClass ('ou') and a distinguished value ('DemoCorp'), and replaces the existing values of these variables.


update

public void update(RDN newRDN)

copyChildren

public void copyChildren(java.util.Enumeration children)
A utility ftn that makes copies of all the child nodes given to it, and adds the copies to the current node.

Parameters:
children - an enumeration of SmartNode(s), to copy and add.

getRDN

public RDN getRDN()
Returns the RDN of the tree node as a String.

Returns:
the RDN as a string.

toString

public java.lang.String toString()
Writes out the nodes RDN as a string,

Overrides:
toString in class javax.swing.tree.DefaultMutableTreeNode
Returns:
the RDN, or a message string for special values (such as root, usually 'World', or dummy values, usually 'reading...'.

getObjectClass

public java.lang.String getObjectClass()
returns the ldap class type of the node

Returns:
the ldap class type as a string.

getDistinguishedValue

public java.lang.String getDistinguishedValue()
Writes out the nodes RDN as a string, displaying just the value of the RDN

Returns:
distinguishedValue the value part of the RDN

getIconName

public java.lang.String getIconName()
returns the icon name (without the extension). The Icon name is either one of the objectClass names (that an icon can be found for) or failing that the ldap class name.

Returns:
the string used to identify the icon.

isDummy

public boolean isDummy()
Sometimes a dummy node is used to signal that there may be child nodes below a given node, but we haven't actually read those nodes yet.

Returns:
whether this node is a dummy node holding no real data.

hasDummy

public boolean hasDummy()
Returns whether this node has a dummy node. (In a normal tree, the dummy node will be the only node)


getDummyMessage

public java.lang.String getDummyMessage()
Returns the string to display when the node is a 'dummy'.

Returns:
dummy message, such as 'reading...'

isRoot

public boolean isRoot()
The root node is sometimes blank, but displayed to the user with a different name. This simply returns whether the node is the root node - use @isBlankRoot to determine whether it is both a root node and blank...

Overrides:
isRoot in class javax.swing.tree.DefaultMutableTreeNode

isBlankRoot

public boolean isBlankRoot()
The root node is sometimes blank. This means it is displayed as ROOTNAME (usually 'cn=World') in the tree, and written out as a zero length string in other contexts such as dumping ldif files.


getBlankRootName

public java.lang.String getBlankRootName()
Returns the name of the 'blank root' (i.e. "World" or similar).


isAlwaysRefresh

public boolean isAlwaysRefresh()
Experimental - returns true if the node should always 'refresh' when it is expanded by the tree...


setAlwaysRefresh

public void setAlwaysRefresh(boolean state)
Experimental - sets if the node should always 'refresh' (i.e. reload all children) when it is expanded by the tree...


setRoot

public void setRoot(boolean state)
This sets the root status of the node (default=false). If set to true, the root node will return ROOTSTRING as a name for display, rather than a blank.


getIcon

public javax.swing.ImageIcon getIcon()
gets the icon associated with this node. These are taken from a central pool of icons - there is no local copy of the icon held in the node.

Returns:
the associated icon. This may be null, if not even the default icon has been set.

setIcon

public void setIcon(javax.swing.ImageIcon newIcon)
Rarely used method to force a particular icon to be used by this particular node.


hasChild

public boolean hasChild(SmartNode n)
Returns whether this node has the corresponding node as a child.


hasChild

public boolean hasChild(RDN r)
Returns whether this node has the corresponding node as a child.


hasChild

public boolean hasChild(java.lang.String testRDN)
Returns whether this node has the corresponding node as a child.


isStructural

public boolean isStructural()

setStructural

public void setStructural(boolean val)

sort

public void sort()
This sorts the children of the current node by the alphabetic value of their naming attribute value; e.g. in cn=doofus, by 'doofus'.


rdnEquals

public boolean rdnEquals(RDN testRDN)
Check if a SmartNode has the same RDN as the passed RDN.

Returns:
true if the RDNs are equal

setPopupMenu

public void setPopupMenu(javax.swing.JPopupMenu popupMenu)
It is possible to register a special popup menu that is called when this node is 'right-clicked' on. Usually you wouldn't bother.


getPopupMenu

public javax.swing.JPopupMenu getPopupMenu()
It is possible to register a special popup menu that is called when this node is 'right-clicked' on. Usually you wouldn't bother, but this returns that menu if you have bothered, and null if you haven't.

Returns:
the pre-registered popupmenu, or (more usually) null.

isMultiValued

public boolean isMultiValued()

getDN

public DN getDN()

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor df)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavour)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable