📄 smartnode.java
字号:
/**
* Writes out the nodes RDN as a string,
* @return the RDN, or a message string
* for special values (such as root, usually 'World', or dummy values, usually
* 'reading...'.
*/
public String toString()
{
if (blankRoot==true) return ROOTNAME;
if (dummy) return DUMMYMESSAGE;
//return distinguishedValue;
//return rdn.getRawVal(0);
//return getDistinguishedValue();
return rdn.toString();
}
/**
* returns the ldap class type of the node
* WARNING - Currently not properly implemented; Returns (first) attribute naming value instead...
* @return the ldap class type as a string.
*/
public String getObjectClass() { return nodeObjectClass; }
/**
* Writes out the nodes RDN as a string, displaying just the value of the RDN
* @return distinguishedValue the value part of the RDN
*/
//XXX performance - this is used by comparator, but currently is slow.
//XXX maybe speed up?
public String getDistinguishedValue()
{
if (rdn.isMultiValued())
{
int size = rdn.size();
StringBuffer val = new StringBuffer();
for (int i=0; i<size; i++)
{
if (i>0)
val.append(" + ");
val.append(rdn.getRawVal(i));
}
return val.toString();
}
else
return rdn.getRawVal(0);
}
/**
* 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.
* @return the string used to identify the icon.
*/
public String getIconName() { return nodeObjectClass; }
/**
* 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.
*
* @return whether this node is a dummy node holding no real data.
*/
public boolean isDummy() { return dummy; }
/**
* Returns whether this node has a dummy node.
* (In a normal tree, the dummy node will be the only node)
*
*/
public boolean hasDummy()
{
if (getChildCount() == 0) return false;
return ((SmartNode)getChildAt(0)).isDummy();
}
/**
* Returns the string to display when the node is a 'dummy'.
* @return dummy message, such as 'reading...'
*/
public String getDummyMessage()
{
return DUMMYMESSAGE;
}
/**
* 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...
*/
public boolean isRoot() { return root; }
/**
* 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.
*/
public boolean isBlankRoot() { return blankRoot; }
/**
* Returns the name of the 'blank root' (i.e. "World" or similar).
* @return the blank root name, suitable for display to a user.
*/
public String getBlankRootName() { return ROOTNAME; }
/**
* Experimental - returns true if the node should always
* 'refresh' when it is expanded by the tree...
*/
public boolean isAlwaysRefresh() { return alwaysRefresh; }
/**
* Experimental - sets if the node should always
* 'refresh' (i.e. reload all children) when it is expanded by the tree...
*/
public void setAlwaysRefresh(boolean state)
{
alwaysRefresh = 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.
*/
public void setRoot(boolean state)
{
root = state;
blankRoot = false;
if ((root == true) && ("".equals(rdn.toString())))
{
update("");
blankRoot = true;
nodeObjectClass = ROOTNAME.toLowerCase();
}
}
/**
* 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.
*
* @return the associated icon. This may be null, if not even the default
* icon has been set.
*/
public ImageIcon getIcon()
{
if (icon != null) return icon;
icon = (ImageIcon) icons.get(nodeObjectClass.toLowerCase());
if (icon == null)
icon = (ImageIcon) icons.get("default"); // this may still be null if no icons found...
return icon;
}
/**
* Rarely used method to force a particular icon to be used by this particular
* node.
*/
public void setIcon(ImageIcon newIcon) { icon = newIcon; }
/**
* Returns whether this node has the corresponding node as a child.
* @param n the child node.
*/
public boolean hasChild(SmartNode n) { return hasChild(n.toString());}
/**
* Returns whether this node has the corresponding node as a child.
* @param r the child node's RDN. (Test is case insensitive)
*/
public boolean hasChild(RDN r) { return hasChild(r.toString());}
/**
* Returns whether this node has the corresponding node as a child.
* @param testRDN the child node's RDN as a String. (Test is case insensitive)
*/
public boolean hasChild(String testRDN)
{
Enumeration children = children();
while (children.hasMoreElements())
{
if (testRDN.equalsIgnoreCase(children.nextElement().toString()))
{
return true;
}
}
return false;
}
public boolean isStructural() { return structural; }
public void setStructural(boolean val) { structural = val; }
/**
* Quicky comparator class to sort nodes by distinguished value, rather
* than (default) .toString()
*/
/*
class NodeComparator implements Comparable
{
Object myObject;
String compareString;
public NodeComparator(Object o)
{
myObject = (o==null)?"null":o;
if (myObject instanceof SmartNode)
compareString = ((SmartNode)myObject).getDistinguishedValue().toLowerCase();
else
compareString = myObject.toString().toLowerCase();
}
public int compareTo(Object compObject)
{
return compareString.compareTo(compObject.toString());
}
public String toString() { return compareString; }
public Object getObject() {return myObject; }
}
*/
/**
* Used for sorting of Smart Nodes.
* @param o the Smart Node to compare against.
* @return a negative integer, zero, or a positive integer as this Collation Key is less
* than, equal to, or greater than the given Object.
* @throws ClassCastException Thrown if the passed object is not another SmartNode.
*/
public int compareTo(Object o)
throws ClassCastException
{
if (o == null)
return -1;
if (((SmartNode)o).collationKey == null)
return -1;
if (collationKey == null)
return +1; // bingo
return collationKey.compareTo(((SmartNode)o).collationKey);
}
/**
* This sorts the children of the current node by the alphabetic
* value of their naming attribute value; e.g. in cn=doofus, by 'doofus'.
*
*/
public void sort()
{
TreeSet sortedSet = new TreeSet();
Enumeration kids = children();
while (kids.hasMoreElements())
{
Object kid = kids.nextElement();
//System.out.println("add node: '" + kid + "'");
sortedSet.add(kid);
}
removeAllChildren();
Iterator sortedKids = sortedSet.iterator();
while (sortedKids.hasNext())
{
SmartNode newNode = (SmartNode)sortedKids.next();
//System.out.println("node: " + newNode.toString() + "'");
add(newNode);
}
}
/**
* Check if a SmartNode has the same RDN as the passed RDN.
*
* @param testRDN the RDN to test against
* @return true if the RDNs are equal
*/
public boolean rdnEquals(RDN testRDN)
{
return (testRDN.equals(rdn));
}
/**
* It is possible to register a special popup menu that is called when
* this node is 'right-clicked' on. Usually you wouldn't bother.
* @param popupMenu the popupmenu to register.
*/
public void setPopupMenu(JPopupMenu popupMenu) { menu = 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, but
* this returns that menu if you have bothered, and null if you haven't.
* @return the pre-registered popupmenu, or (more usually) null.
*/
public JPopupMenu getPopupMenu() { return menu; }
/*
* Returns whether the rdn is multi-valued.
*/
public boolean isMultiValued()
{
return rdn.isMultiValued();
}
//
// *** DRAG 'n DROP MAGIC ***
//
public DN getDN()
{
if (root) return new DN();
DN ret = ((SmartNode)getParent()).getDN();
ret.add(getRDN());
return ret;
}
public Object getTransferData(DataFlavor df)
throws UnsupportedFlavorException, IOException
{
if (df.equals(flavours[0]) == false) // currently only support one flavour.
throw new UnsupportedFlavorException(df);
String dn = getDN().toString();
return dn;
}
//Returns an array of DataFlavor objects indicating the
//flavors the data can be provided in.
public DataFlavor[] getTransferDataFlavors()
{
return flavours;
}
//Returns whether or not the specified data flavor is supported for this object.
public boolean isDataFlavorSupported(DataFlavor flavour)
{
for (int i=0; i<flavours.length; i++)
if ( flavours[i].equals(flavour) ) return true;
return false;
}
public void setRdn(RDN rdn)
{
this.rdn = rdn;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -