org.openide.nodes
Class NodeOp

java.lang.Object
  |
  +--org.openide.nodes.NodeOp

public final class NodeOp
extends Object

Utility class for operations on nodes.


Method Summary
static int[] computePermutation(Node[] arr1, Node[] arr2)
          Compute a permutation between two arrays of nodes.
static String[] createPath(Node node, Node parent)
          Find a path (by name) from one node to the root or a parent.
static Node findChild(Node node, String name)
          Look for a node child of given name.
static JPopupMenu findContextMenu(Node[] nodes)
          Compute common menu for specified nodes.
static Node findPath(Node start, Enumeration names)
          Traverse a path from a parent node down, by an enumeration of names.
static Node findPath(Node start, String[] names)
          Traverse a path from a parent node down, by an enumeration of names.
static Node findRoot(Node node)
          Find the root for a given node.
static Node[] fromHandles(Node.Handle[] handles)
          Takes array of handles and creates array of nodes.
static SystemAction[] getDefaultActions()
          Get the default actions for all nodes.
static boolean isSon(Node parent, Node son)
          Test whether the second node is a (direct) child of the first one.
static void setDefaultActions(SystemAction[] def)
          Deprecated. Useless.
static Node.Handle[] toHandles(Node[] nodes)
          Takes array of nodes and creates array of handles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDefaultActions

public static SystemAction[] getDefaultActions()
Get the default actions for all nodes.
Returns:
array of default actions

setDefaultActions

public static void setDefaultActions(SystemAction[] def)
Deprecated. Useless.


findContextMenu

public static JPopupMenu findContextMenu(Node[] nodes)
Compute common menu for specified nodes. Provides only those actions supplied by all nodes in the list.
Parameters:
nodes - the nodes
Returns:
the menu for all nodes

isSon

public static boolean isSon(Node parent,
                            Node son)
Test whether the second node is a (direct) child of the first one.
Parameters:
parent - parent node
son - son node
Returns:
true if so

createPath

public static String[] createPath(Node node,
                                  Node parent)
Find a path (by name) from one node to the root or a parent.
Parameters:
node - the node to start in
parent - parent node to stop in (can be null for the root)
Returns:
list of child names--i.e. a path from the parent to the child node
Throws:
IllegalArgumentException - if node's getName() method returns null

findChild

public static Node findChild(Node node,
                             String name)
Look for a node child of given name.
Parameters:
node - node to search in
name - name of child to look for
Returns:
the found child, or null if there is no such child

findPath

public static Node findPath(Node start,
                            Enumeration names)
                     throws NodeNotFoundException
Traverse a path from a parent node down, by an enumeration of names.
Parameters:
start - node to start searching at
names - enumeration of Strings containing names of nodes along the path
Returns:
the node with such a path from the start node
Throws:
NodeNotFoundException - if the node with such name does not exists; the exception contains additional information about the failure.

findPath

public static Node findPath(Node start,
                            String[] names)
                     throws NodeNotFoundException
Traverse a path from a parent node down, by an enumeration of names.
Parameters:
start - node to start searching at
names - names of nodes along the path
Returns:
the node with such a path from the start node
Throws:
NodeNotFoundException - if the node with such name does not exists; the exception contains additional information about the failure.

findRoot

public static Node findRoot(Node node)
Find the root for a given node.
Parameters:
node - the node
Returns:
its root

computePermutation

public static int[] computePermutation(Node[] arr1,
                                       Node[] arr2)
                                throws IllegalArgumentException
Compute a permutation between two arrays of nodes. The arrays must have the same size. The permutation then can be applied to the first array to create the second array.
Parameters:
arr1 - first array
arr2 - second array
Returns:
the permutation, or null if the arrays are the same
Throws:
IllegalArgumentException - if the arrays cannot be permuted to each other. Either they have different sizes or they do not contain the same elements.

toHandles

public static Node.Handle[] toHandles(Node[] nodes)
Takes array of nodes and creates array of handles. The nodes that do not have handles are not included in the resulting array.
Parameters:
nodes - array of nodes
Returns:
array of Node.Handles

fromHandles

public static Node[] fromHandles(Node.Handle[] handles)
                          throws IOException
Takes array of handles and creates array of nodes.
Parameters:
handles - array of handles
Returns:
array of nodes
Throws:
IOException - if a node cannot be created from the handle


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.