Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.openide.nodes 6.7.22
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.openide.nodes
Class Node

    java.lang.Object
      java.beans.FeatureDescriptor
          org.openide.nodes.Node

All Implemented Interfaces:
  HelpCtx.Provider, Lookup.Provider

Direct Known Subclasses:
  AbstractNode, FilterNode

    public abstract class Node

extends FeatureDescriptor
implements Lookup.Provider, HelpCtx.Provider

A node represents one element in a hierarchy of objects (beans). It provides all methods that are needed for communication between the IDE and the bean.

The node has three purposes:

1. visually represent the object in the tree hierarchy (i.e. Explorer)
2. provide sets of properties for that object (i.e. Component Inspector, Property Sheet)
3. offer actions to perform on itself

Frequently nodes are created to represent `DataObject`s. But they may also represent anything to be displayed to the user or manipulated programmatically, even if they have no data directly stored behind them; for example, a control panel or debugger breakpoint.

There are two listeners in this class: `PropertyChangeListener` and `NodeListener` (which extends `PropertyChangeListener`). The first is designed to listen on properties that can be returned from `getPropertySets()`, the later for listening on changes in the node itself (including the name, children, parent, set of properties, icons, etc.). Be sure to distinguish between these two.

The node is cloneable. When a node is cloned, it is initialized with an empty set of listeners and no parent. The display name and short description are copied to the new node. The set of properties is shared.

Implements `Lookup.Provider` since 3.11.

Nested Class Summary
`static interface` | `Node.Cookie` Marker interface for all cookies.
`static interface` | `Node.Handle` Serializable node reference.
`static class` | `Node.IndexedProperty` Description of an indexed property and operations on it.
`static class` | `Node.Property` Description of a Bean property on a node, and operations on it.
`static class` | `Node.PropertySet` Class that represents one set of properties.

Field Summary
`static Node` | `EMPTY` An empty leaf node.
`static String` | `PROP_COOKIE` Property for a node's cookie set.
`static String` | `PROP_DISPLAY_NAME` Property for node display name.
`static String` | `PROP_ICON` Property for the normal (closed) icon of a node.
`static String` | `PROP_LEAF` Property saying whether the Node is Leaf
`static String` | `PROP_NAME` Property for internal (not displayable) name of a node.
`static String` | `PROP_OPENED_ICON` Property for the opened icon of a node.
`static String` | `PROP_PARENT_NODE` Property for a node's parent.
`static String` | `PROP_PROPERTY_SETS` Property for a node's list of property sets.
`static String` | `PROP_SHORT_DESCRIPTION` Property for short description of a node.

Constructor Summary
`protected` | `Node(Children h)` Creates a new node with a given hierarchy of children.
`protected` | `Node(Children h, Lookup lookup)` Creates a new node with a given hierarchy of children and a lookup providing content for `getCookie(java.lang.Class)` and `getLookup()` methods.

Method Summary
`void` | `addNodeListener(NodeListener l)` Add a listener to changes in the node's intrinsic properties (name, cookies, etc.).
`void` | `addPropertyChangeListener(PropertyChangeListener l)` Add a listener to the node's computed Bean properties.
`abstract boolean` | `canCopy()` Test whether this node permits copying.
`abstract boolean` | `canCut()` Test whether this node permits cutting.
`abstract boolean` | `canDestroy()` Test whether this node can be deleted.
`abstract boolean` | `canRename()` Test whether this node can be renamed.
`abstract Transferable` | `clipboardCopy()` Called when a node is to be copied to the clipboard.
`abstract Transferable` | `clipboardCut()` Called when a node is to be cut to the clipboard.
`protected Object` | `clone()` Implements `Object.clone()` to behave correctly if cloning is desired.
`abstract Node` | `cloneNode()` Clone the node.
`void` | `destroy()` Remove the node from its parent and deletes it.
`abstract Transferable` | `drag()` Called when a drag is started with this node.
`boolean` | `equals(Object obj)` Compares for equaliness.
`protected void` | `fireCookieChange()` Fires a change event for `PROP_COOKIE`.
`protected void` | `fireDisplayNameChange(String o, String n)` Allow subclasses that override the getDisplayName method to fire the changes of the name by itself.
`protected void` | `fireIconChange()` Fire a change event for `PROP_ICON`.
`protected void` | `fireNameChange(String o, String n)` Allow subclasses that override the getName method to fire the changes of the name by itself.
`protected void` | `fireNodeDestroyed()` To all node listeners fire node destroyed notification.
`protected void` | `fireOpenedIconChange()` Fire a change event for `PROP_OPENED_ICON`.
`protected void` | `firePropertyChange(String name, Object o, Object n)` Fire a property change event.
`protected void` | `firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n)` Fires a (Bean) property change event (for `PROP_PROPERTY_SETS`).
`protected void` | `fireShortDescriptionChange(String o, String n)` Allow subclasses that override the getShortDescription method to fire the changes of the description by itself.
`SystemAction[]` | `getActions()` Deprecated. Use getActions (false) instead.
`Action[]` | `getActions(boolean context)` Get the set of actions that are associated with this node.
`Children` | `getChildren()` Get the list of children.
`SystemAction[]` | `getContextActions()` Deprecated. Use getActions (true) instead.
`JPopupMenu` | `getContextMenu()` Make a context menu for this node.
`Node.Cookie` | `getCookie(Class type)` Get a cookie for this node.
`abstract Component` | `getCustomizer()` Get the customizer component.
`SystemAction` | `getDefaultAction()` Deprecated. Use `getPreferredAction()` instead.
`abstract PasteType` | `getDropType(Transferable t, int action, int index)` Determine if there is a paste operation that can be performed on provided transferable.
`abstract Node.Handle` | `getHandle()` Obtain handle for this node (for serialization).
`abstract HelpCtx` | `getHelpCtx()` Get context help associated with this node.
`String` | `getHtmlDisplayName()` Return a variant of the display name containing HTML markup conforming to the limited subset of font-markup HTML supported by the lightweight HTML renderer `org.openide.awt.HtmlRenderer` (font color, bold, italic and strikethrough supported; font colors can be UIManager color keys if they are prefixed with a ! character, i.e.
`abstract Image` | `getIcon(int type)` Find an icon for this node (in the closed state).
`Lookup` | `getLookup()` Obtains a Lookup represeting additional content of this Node.
`abstract NewType[]` | `getNewTypes()` Get the new types that can be created in this node.
`abstract Image` | `getOpenedIcon(int type)` Find an icon for this node (in the open state).
`Node` | `getParentNode()` Get the parent node.
`abstract PasteType[]` | `getPasteTypes(Transferable t)` Determine which paste operations are allowed when a given transferable is in the clipboard.
`Action` | `getPreferredAction()` Gets the preferred action for this node.
`abstract Node.PropertySet[]` | `getPropertySets()` Get the list of property sets for this node.
`abstract boolean` | `hasCustomizer()` Test whether there is a customizer for this node.
`protected boolean` | `hasPropertyChangeListener()` Allows to figure out, whether the node has any PropertyChangeListeners attached.
`boolean` | `isLeaf()` Test whether the node is a leaf, or may contain children.
`void` | `removeNodeListener(NodeListener l)` Remove a node listener.
`void` | `removePropertyChangeListener(PropertyChangeListener l)` Remove a Bean property change listener.
`protected void` | `setChildren(Children ch)` Allows to change Children of the node.
`void` | `setDisplayName(String s)` Set the display name.
`void` | `setName(String s)` Set the system name.
`void` | `setShortDescription(String s)` Set the short description of the node.
`String` | `toString()`

Methods inherited from class java.beans.FeatureDescriptor
`attributeNames, getDisplayName, getName, getShortDescription, getValue, isExpert, isHidden, isPreferred, setExpert, setHidden, setPreferred, setValue`

Methods inherited from class java.lang.Object
`finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### EMPTY

    public static final Node EMPTY

  An empty leaf node.

### PROP_DISPLAY_NAME

    public static final String PROP_DISPLAY_NAME

  Property for node display name.

  See Also:
    Constant Field Values

### PROP_NAME

    public static final String PROP_NAME

  Property for internal (not displayable) name of a node. This name is often used to look up a node in the hierarchy, so it should be chosen to be simple.

  See Also:
    Constant Field Values

### PROP_SHORT_DESCRIPTION

    public static final String PROP_SHORT_DESCRIPTION

  Property for short description of a node.

  See Also:
    Constant Field Values

### PROP_ICON

    public static final String PROP_ICON

  Property for the normal (closed) icon of a node.

  See Also:
    Constant Field Values

### PROP_OPENED_ICON

    public static final String PROP_OPENED_ICON

  Property for the opened icon of a node.

  See Also:
    Constant Field Values

### PROP_PARENT_NODE

    public static final String PROP_PARENT_NODE

  Property for a node's parent.

  See Also:
    Constant Field Values

### PROP_PROPERTY_SETS

    public static final String PROP_PROPERTY_SETS

  Property for a node's list of property sets.

  See Also:
    Constant Field Values

### PROP_COOKIE

    public static final String PROP_COOKIE

  Property for a node's cookie set.

  See Also:
    Constant Field Values

### PROP_LEAF

    public static final String PROP_LEAF

  Property saying whether the Node is Leaf

  Since:
    3.1
  See Also:
    Constant Field Values

Constructor Detail

### Node

    protected Node(Children h)
            throws IllegalStateException

  Creates a new node with a given hierarchy of children.

  Parameters:
    `h` - the children to use for this node
  Throws:
    `IllegalStateException` - if the children object is already in use by a different node

### Node

    protected Node(Children h,
                   Lookup lookup)
            throws IllegalStateException

  Creates a new node with a given hierarchy of children and a lookup providing content for `getCookie(java.lang.Class)` and `getLookup()` methods.

  As the lookup needs to be constucted before Node's constructor is called, it might not be obvious how to add Node or other objects into it without type casting. Here is the recommended suggestion that uses public/private pair of constructors:

          public MyNode(Children ch, FileObject file) {
              this(ch, file, new InstanceContent());
          }

          /** A private constructor that takes an InstanceContent and
               * uses it as internals for the Node lookup and also allow us
               * to modify the content, for example by adding a reference
               * to the node itself or any other object we want to represent.
               *
               * @param ch children we wish to use
               * @param file sample object we wish to have in lookup
               * @param content the content created by the first constructor
               */
          private MyNode(Children ch, FileObject file, InstanceContent content) {
              super(ch, new AbstractLookup(content));
              // adds the node to our own lookup
              content.add (this);
              // adds aditional items to the lookup
              content.add (file);
          }

  Parameters:
    `h` - the children to use for this node
    `lookup` - the lookup to provide content of `getLookup()` and also `getCookie(java.lang.Class)`
  Throws:
    `IllegalStateException` - if the children object is already in use by a different node
  Since:
    3.11

Method Detail

### clone

    protected Object clone()
                    throws CloneNotSupportedException

  Implements `Object.clone()` to behave correctly if cloning is desired. But `Cloneable` is not declared by default.

  The default implementation checks whether the child list implements `Cloneable`, and if so, it clones the children. If the child list does not support cloning, `Children.LEAF` is used instead for the children. The parent of this node is set to `null` and an empty set of listeners is attached to the node.

  Overrides:
    `clone` in class `Object`
  Returns:
    the cloned version of the node
  Throws:
    `CloneNotSupportedException` - if the children cannot be cloned in spite of implementing `Cloneable`

### cloneNode

    public abstract Node cloneNode()

  Clone the node. The newly created node should reference the same object is this node does, but it should not be inserted as a child to any other node. Also it should have an empty set of listeners. In all other respects the node should behave exactly as the original one does.

  Returns:
    copy of this node

### setName

    public void setName(String s)

  Set the system name. Fires a property change event.

  Overrides:
    `setName` in class `FeatureDescriptor`
  Parameters:
    `s` - the new name
  Throws:
    `IllegalArgumentException` - if the new name cannot represent a valid node name

### setDisplayName

    public void setDisplayName(String s)

  Set the display name. Fires a property change event.

  Overrides:
    `setDisplayName` in class `FeatureDescriptor`
  Parameters:
    `s` - the new name

### setShortDescription

    public void setShortDescription(String s)

  Set the short description of the node. Fires a property change event.

  This description may be used for tool tips, etc.

  Overrides:
    `setShortDescription` in class `FeatureDescriptor`
  Parameters:
    `s` - the new description

### getIcon

    public abstract Image getIcon(int type)

  Find an icon for this node (in the closed state).

  Parameters:
    `type` - constant from `BeanInfo`
  Returns:
    icon to use to represent the node

### getOpenedIcon

    public abstract Image getOpenedIcon(int type)

  Find an icon for this node (in the open state). This icon is used when the node may have children and is expanded.

  Parameters:
    `type` - constant from `BeanInfo`
  Returns:
    icon to use to represent the node when open

### getHelpCtx

    public abstract HelpCtx getHelpCtx()

  Get context help associated with this node.

  Specified by:
    `getHelpCtx` in interface `HelpCtx.Provider`
  Returns:
    the context help object (could be `null` or `HelpCtx.DEFAULT_HELP`)

### getChildren

    public final Children getChildren()

  Get the list of children.

  Returns:
    the children

### setChildren

    protected final void setChildren(Children ch)

  Allows to change Children of the node. Call to this method aquires write lock on the nodes hierarchy. Take care not to call this method under read lock.

  Parameters:
    `ch` - New children to be set on the node.
  Since:
    3.1

### isLeaf

    public final boolean isLeaf()

  Test whether the node is a leaf, or may contain children.

  Returns:
    `true` if the children list is actually `Children.LEAF`

### getParentNode

    public final Node getParentNode()

  Get the parent node.

  Returns:
    the parent node, or `null` if this node is the root of a hierarchy

### canRename

    public abstract boolean canRename()

  Test whether this node can be renamed. If true, one can use `FeatureDescriptor.getName()` to obtain the current name and `setName(java.lang.String)` to change it.

  Returns:
    `true` if the node can be renamed

### canDestroy

    public abstract boolean canDestroy()

  Test whether this node can be deleted.

  Returns:
    `true` if can

### destroy

    public void destroy()
                 throws IOException

  Remove the node from its parent and deletes it. The default implementation obtains write access to the `children's lock`, and removes the node from its parent (if any). Also fires a property change.

  This may be overridden by subclasses to do any additional cleanup.

  Throws:
    `IOException` - if something fails

### getPropertySets

    public abstract Node.PropertySet[] getPropertySets()

  Get the list of property sets for this node. E.g. typically there may be one for normal Bean properties, one for expert properties, and one for hidden properties.

  Returns:
    the property sets

### clipboardCopy

    public abstract Transferable clipboardCopy()
                                        throws IOException

  Called when a node is to be copied to the clipboard.

  Returns:
    the transferable object representing the content of the clipboard
  Throws:
    `IOException` - when the copy cannot be performed

### clipboardCut

    public abstract Transferable clipboardCut()
                                       throws IOException

  Called when a node is to be cut to the clipboard.

  Returns:
    the transferable object representing the content of the clipboard
  Throws:
    `IOException` - when the cut cannot be performed

### drag

    public abstract Transferable drag()
                               throws IOException

  Called when a drag is started with this node. The node can attach a transfer listener to ExTransferable and will be then notified about progress of the drag (accept/reject).

  Returns:
    transferable to represent this node during a drag
  Throws:
    `IOException` - if a drag cannot be started

### canCopy

    public abstract boolean canCopy()

  Test whether this node permits copying.

  Returns:
    `true` if so

### canCut

    public abstract boolean canCut()

  Test whether this node permits cutting.

  Returns:
    `true` if so

### getPasteTypes

    public abstract PasteType[] getPasteTypes(Transferable t)

  Determine which paste operations are allowed when a given transferable is in the clipboard. For example, a node representing a Java package will permit classes to be pasted into it.

  Parameters:
    `t` - the transferable in the clipboard
  Returns:
    array of operations that are allowed

### getDropType

    public abstract PasteType getDropType(Transferable t,
                                          int action,
                                          int index)

  Determine if there is a paste operation that can be performed on provided transferable. Used by drag'n'drop code to check whether the drop is possible.

  Parameters:
    `t` - the transferable
    `action` - the drag'n'drop action to do DnDConstants.ACTION_MOVE, ACTION_COPY, ACTION_LINK
    `index` - index between children the drop occured at or -1 if not specified
  Returns:
    null if the transferable cannot be accepted or the paste type to execute when the drop occures

### getNewTypes

    public abstract NewType[] getNewTypes()

  Get the new types that can be created in this node. For example, a node representing a Java package will permit classes to be added.

  Returns:
    array of new type operations that are allowed

### getActions

    public Action[] getActions(boolean context)

  Get the set of actions that are associated with this node. This set is used to construct the popup menu for the node.

  By default this method delegates to the deprecated getActions or getContextActions method depending on the value of suplied argument.

  It is supposed to be overridden by subclasses accordingly.

  Parameters:
    `context` - whether to find actions for context meaning or for the node itself
  Returns:
    a list of actions (you may include nulls for separators)
  Since:
    3.29

### getActions

    public SystemAction[] getActions()

  Deprecated. Use getActions (false) instead.

  Get the set of actions associated with this node. This may be used e.g. in constructing a `context menu`.

  By default returns the actions in `NodeOp.getDefaultActions()`.

  Returns:
    system actions appropriate to the node

### getContextActions

    public SystemAction[] getContextActions()

  Deprecated. Use getActions (true) instead.

  Get a special set of actions for situations when this node is displayed as a context.

  For example, right-clicking on a parent node in a hierarchical view (such as the normal Explorer) should use `getActions`. However, if this node is serving as the parent of a (say) a window tab full of icons (e.g., in `explorer.view.IconView`), and the users right-clicks on the empty space in this pane, then this method should be used to get the appropriate actions for a popup menu.

  Note that in the Windows UI system, e.g., these action sets are quite different.

  Returns:
    actions for a context. In the default implementation, same as `getActions(boolean)`.

### getDefaultAction

    public SystemAction getDefaultAction()

  Deprecated. Use `getPreferredAction()` instead.

  Gets the default action for this node.

  Returns:
    `null` indicating there should be none default action

### getPreferredAction

    public Action getPreferredAction()

  Gets the preferred action for this node. This action can but need not to be one from the action array returned from `getActions(boolean)`. In case it is, the popup menu created from those actions is encouraged to highlight the preferred action. Override in subclasses accordingly.

  Returns:
    the preferred action, or `null` if there is none
  Since:
    3.29

### getContextMenu

    public final JPopupMenu getContextMenu()

  Make a context menu for this node. The menu is constructed from the set of actions returned by `getActions(boolean)`.

  Returns:
    the popup menu

### hasCustomizer

    public abstract boolean hasCustomizer()

  Test whether there is a customizer for this node. If true, the customizer can be obtained via `getCustomizer()`.

  Returns:
    `true` if there is a customizer

### getCustomizer

    public abstract Component getCustomizer()

  Get the customizer component.

  Returns:
    the component, or `null` if there is no customizer

### getCookie

    public Node.Cookie getCookie(Class type)

  Get a cookie for this node.

  The set of cookies can change. If a node changes its set of cookies, it fires a property change event with `PROP_COOKIE`.

  If the Node was constructed with a `Lookup` in constructor than this method delegates to the provided lookup object.

  Parameters:
    `type` - the representation class of the cookie
  Returns:
    a cookie assignable to that class, or `null` if this node has no such cookie
  See Also:
    `Lookup`

### getLookup

    public final Lookup getLookup()

  Obtains a Lookup represeting additional content of this Node. If the lookup was provided in a constructor, it is returned here, if not, a lookup based on the content of getCookie method is provided.

  Specified by:
    `getLookup` in interface `Lookup.Provider`
  Returns:
    lookup for this node
  Since:
    3.11

### getHtmlDisplayName

    public String getHtmlDisplayName()

  Return a variant of the display name containing HTML markup conforming to the limited subset of font-markup HTML supported by the lightweight HTML renderer `org.openide.awt.HtmlRenderer` (font color, bold, italic and strikethrough supported; font colors can be UIManager color keys if they are prefixed with a ! character, i.e. `<font color='!controlShadow'>`). Enclosing `<html>` tags are not needed. If returning non-null, HTML markup characters that should be literally renderered must be escaped (`>` becomes `&gt;` and so forth).

  This method should return either an HTML display name or null; it should not return the non-HTML display name.

  Note there is no property corresponding to the HTML display name - if it should change, a change in the display name should be fired; this should not be a mechanism for returning anything other than a marked up version of the return value of `getDisplayName`.

  Returns:
    a String containing conformant HTML markup which represents the display name, or null. The default implementation returns null.
  Since:
    4.30
  See Also:
    `HtmlRenderer`

### getHandle

    public abstract Node.Handle getHandle()

  Obtain handle for this node (for serialization). The handle can be serialized and `Node.Handle.getNode()` used after deserialization to obtain the original node.

  Returns:
    the handle, or `null` if this node is not persistable

### addNodeListener

    public final void addNodeListener(NodeListener l)

  Add a listener to changes in the node's intrinsic properties (name, cookies, etc.).

  The listener is not notified about changes in subnodes until the method `getChildren().getNodes()` is called.

  Parameters:
    `l` - the listener to add

### removeNodeListener

    public final void removeNodeListener(NodeListener l)

  Remove a node listener.

  Parameters:
    `l` - the listener

### addPropertyChangeListener

    public final void addPropertyChangeListener(PropertyChangeListener l)

  Add a listener to the node's computed Bean properties.

  Parameters:
    `l` - the listener

### hasPropertyChangeListener

    protected final boolean hasPropertyChangeListener()

  Allows to figure out, whether the node has any PropertyChangeListeners attached.

  Returns:
    True if node has one or more PropertyChangeListeners attached.
  Since:
    1.36

### removePropertyChangeListener

    public final void removePropertyChangeListener(PropertyChangeListener l)

  Remove a Bean property change listener.

  Parameters:
    `l` - the listener

### firePropertyChange

    protected final void firePropertyChange(String name,
                                            Object o,
                                            Object n)

  Fire a property change event.

  Parameters:
    `name` - name of changed property (from `getPropertySets()`); may be null
    `o` - old value; may be null
    `n` - new value; may be null
  See Also:
    `PropertyChangeEvent`

### fireNameChange

    protected final void fireNameChange(String o,
                                        String n)

  Allow subclasses that override the getName method to fire the changes of the name by itself. Please notice that default implementation of setName will fire the change by itself.

### fireDisplayNameChange

    protected final void fireDisplayNameChange(String o,
                                               String n)

  Allow subclasses that override the getDisplayName method to fire the changes of the name by itself. Please notice that default implementation of setDisplayName will fire the change by itself.

### fireShortDescriptionChange

    protected final void fireShortDescriptionChange(String o,
                                                    String n)

  Allow subclasses that override the getShortDescription method to fire the changes of the description by itself. Please notice that default implementation of setShortDescription will fire the change by itself.

### fireIconChange

    protected final void fireIconChange()

  Fire a change event for `PROP_ICON`.

### fireOpenedIconChange

    protected final void fireOpenedIconChange()

  Fire a change event for `PROP_OPENED_ICON`.

### fireNodeDestroyed

    protected final void fireNodeDestroyed()

  To all node listeners fire node destroyed notification.

### firePropertySetsChange

    protected final void firePropertySetsChange(Node.PropertySet[] o,
                                                Node.PropertySet[] n)

  Fires a (Bean) property change event (for `PROP_PROPERTY_SETS`).

  Parameters:
    `o` - the old set
    `n` - the new set

### fireCookieChange

    protected final void fireCookieChange()

  Fires a change event for `PROP_COOKIE`. The old and new values are set to null.

### equals

    public boolean equals(Object obj)

  Compares for equaliness. Does special treatment of FilterNodes. If argument is FilterNode then this node can be equal with it if it is its original.

  Overrides:
    `equals` in class `Object`
  Parameters:
    `obj` - object to compare
  Returns:
    true if the obj is `==` or is filter node of this node

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.openide.nodes 6.7.22
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Built on December 7 2006. | Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.