Class Node
- All Implemented Interfaces:
org.openide.util.HelpCtx.Provider
,org.openide.util.Lookup.Provider
- Direct Known Subclasses:
AbstractNode
,FilterNode
The node has three purposes:
- visually represent the object in the tree hierarchy (i.e. Explorer)
- provide sets of properties for that object (i.e. Component Inspector, Property Sheet)
- 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
Nested ClassesModifier and TypeClassDescriptionstatic interface
Marker interface for all cookies.static interface
Serializable node reference.static class
Description of an indexed property and operations on it.static class
Description of a Bean property on a node, and operations on it.static class
Class that represents one set of properties. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Node
An empty leaf node.static final String
Property for a node's cookie set.static final String
Property for node display name.static final String
Property for the normal (closed) icon of a node.static final String
Property saying whether the Node is Leafstatic final String
Property for internal (not displayable) name of a node.static final String
Property for the opened icon of a node.static final String
Property for a node's parent.static final String
Property for a node's list of property sets.static final String
Property for short description of a node. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new node with a given hierarchy of children.protected
Creates a new node with a given hierarchy of children and a lookup providing content forgetCookie(java.lang.Class<T>)
andgetLookup()
methods. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Add a listener to changes in the node's intrinsic properties (name, cookies, etc.).final void
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
Test whether this node can be deleted.abstract boolean
Test whether this node can be renamed.abstract Transferable
Called when a node is to be copied to the clipboard.abstract Transferable
Called when a node is to be cut to the clipboard.protected Object
clone()
ImplementsObject.clone()
to behave correctly if cloning is desired.abstract Node
Clone the node.void
destroy()
Called when a node is deleted.abstract Transferable
drag()
Called when a drag is started with this node.boolean
Compares for equality.protected final void
Fires a change event forPROP_COOKIE
.protected final void
Allow subclasses that override the getDisplayName method to fire the changes of the name by itself.protected final void
Fire a change event forPROP_ICON
.protected final void
fireNameChange
(String o, String n) Allow subclasses that override the getName method to fire the changes of the name by itself.protected final void
To all node listeners fire node destroyed notification.protected final void
Fire a change event forPROP_OPENED_ICON
.protected final void
firePropertyChange
(String name, Object o, Object n) Fire a property change event.protected final void
Fires a (Bean) property change event (forPROP_PROPERTY_SETS
).protected final void
Allow subclasses that override the getShortDescription method to fire the changes of the description by itself.org.openide.util.actions.SystemAction[]
Deprecated.Use getActions (false) instead.Action[]
getActions
(boolean context) Get the set of actions that are associated with this node.final Children
Get the list of children.org.openide.util.actions.SystemAction[]
Deprecated.Use getActions (true) instead.final JPopupMenu
Makes a context menu for this node.<T extends Node.Cookie>
TGet a cookie for this node.abstract Component
Get the customizer component.org.openide.util.actions.SystemAction
Deprecated.UsegetPreferredAction()
instead.abstract org.openide.util.datatransfer.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
Obtain handle for this node (for serialization).abstract org.openide.util.HelpCtx
Get context help associated with this node.Return a variant of the display name containing HTML markup conforming to the limited subset of font-markup HTML supported by the lightweight HTML rendererorg.openide.awt.HtmlRenderer
(font color, bold, italic and strike-through 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).final org.openide.util.Lookup
Obtains a Lookup representing additional content of this Node.abstract org.openide.util.datatransfer.NewType[]
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).final Node
Get the parent node.abstract org.openide.util.datatransfer.PasteType[]
Determine which paste operations are allowed when a given transferable is in the clipboard.Gets the preferred action for this node.abstract Node.PropertySet[]
Get the list of property sets for this node.abstract boolean
Test whether there is a customizer for this node.int
hashCode()
protected final boolean
Allows to figure out, whether the node has any PropertyChangeListeners attached.final boolean
isLeaf()
Test whether the node is a leaf, or may contain children.final void
Remove a node listener.final void
Remove a Bean property change listener.protected final void
setChildren
(Children ch) Allows to change Children of the node.void
Set the display name.void
setHidden
(boolean hidden) Deprecated.Has no effect.void
Set the system name.void
Set the short description of the node.toString()
Methods inherited from class java.beans.FeatureDescriptor
attributeNames, getDisplayName, getName, getShortDescription, getValue, isExpert, isHidden, isPreferred, setExpert, setPreferred, setValue
-
Field Details
-
EMPTY
An empty leaf node. -
PROP_DISPLAY_NAME
-
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:
-
PROP_SHORT_DESCRIPTION
Property for short description of a node.- See Also:
-
PROP_ICON
-
PROP_OPENED_ICON
-
PROP_PARENT_NODE
-
PROP_PROPERTY_SETS
Property for a node's list of property sets.- See Also:
-
PROP_COOKIE
-
PROP_LEAF
-
-
Constructor Details
-
Node
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
Creates a new node with a given hierarchy of children and a lookup providing content forgetCookie(java.lang.Class<T>)
andgetLookup()
methods.As the lookup needs to be constructed 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 additional items to the lookup content.add (file); }
- Parameters:
h
- the children to use for this nodelookup
- the lookup to provide content ofgetLookup()
and alsogetCookie(java.lang.Class<T>)
- Throws:
IllegalStateException
- if the children object is already in use by a different node- Since:
- 3.11
-
-
Method Details
-
clone
ImplementsObject.clone()
to behave correctly if cloning is desired. ButCloneable
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 tonull
and an empty set of listeners is attached to the node.- Overrides:
clone
in classObject
- Returns:
- the cloned version of the node
- Throws:
CloneNotSupportedException
- if the children cannot be cloned in spite of implementingCloneable
-
cloneNode
Clone the node. The newly created node should reference the same object as this node does, but it may be added as a child to a different parent 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
Set the system name. Fires a property change event.- Overrides:
setName
in classFeatureDescriptor
- Parameters:
s
- the new name- Throws:
IllegalArgumentException
- if the new name cannot represent a valid node name
-
setDisplayName
Set the display name. Fires a property change event.- Overrides:
setDisplayName
in classFeatureDescriptor
- Parameters:
s
- the new name
-
setShortDescription
Set the short description of the node. Fires a property change event.This description may be used for tool tips, etc.
- Overrides:
setShortDescription
in classFeatureDescriptor
- Parameters:
s
- the new description
-
setHidden
Deprecated.Has no effect. To make a node disappear, simply remove it from the children of its parent. For example, you might callChildren.Keys.setKeys(Collection)
with a smaller collection.- Overrides:
setHidden
in classFeatureDescriptor
-
getIcon
-
getOpenedIcon
-
getHelpCtx
public abstract org.openide.util.HelpCtx getHelpCtx()Get context help associated with this node.- Specified by:
getHelpCtx
in interfaceorg.openide.util.HelpCtx.Provider
- Returns:
- the context help object (could be
null
orHelpCtx.DEFAULT_HELP
)
-
getChildren
-
setChildren
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 actuallyChildren.LEAF
-
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 useFeatureDescriptor.getName()
to obtain the current name andsetName(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
Called when a node is deleted. Generally you would never call this method yourself (only override it); perform modifications on the underlying model itself.The default implementation obtains write access to
Children.MUTEX
, and removes the node from its parent (if any). Also fires a property change.Subclasses which return true from
canDestroy()
should override this method to remove the associated model object from its parent. There is no need to call the super method in this case.There is no guarantee that after this method has been called, other methods such as
getIcon(int)
will not also be called for a little while.- Throws:
IOException
- if something fails
-
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
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
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
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
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 org.openide.util.datatransfer.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 transferableaction
- the drag'n'drop action to do DnDConstants.ACTION_MOVE, ACTION_COPY, ACTION_LINKindex
- index between children the drop occurred at or -1 if not specified- Returns:
- null if the transferable cannot be accepted or the paste type to execute when the drop occurs
-
getNewTypes
public abstract org.openide.util.datatransfer.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
Get the set of actions that are associated with this node. This set is used to construct the context menu for the node.By default this method delegates to the deprecated getActions or getContextActions method depending on the value of supplied 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
Deprecated.Use getActions (false) instead.Get the set of actions associated with this node. This may be used e.g. in constructing acontext menu
.By default returns the actions in
NodeOp.getDefaultActions()
.- Returns:
- system actions appropriate to the node
-
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., inIconView
), 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 context 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
Deprecated.UsegetPreferredAction()
instead.Gets the default action for this node.- Returns:
null
indicating there should be none default action
-
getPreferredAction
Gets the preferred action for this node. This action can but need not to be one from the action array returned fromgetActions(boolean)
. In case it is, the context 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
Makes a context menu for this node.Component action maps are not taken into consideration.
Utilities.actionsToPopup(Action[], Component)
is a better choice if you want to use actions such as "Paste" which look at action maps.- Returns:
- the context menu as per
NodeOp.findContextMenu(org.openide.nodes.Node[])
-
hasCustomizer
public abstract boolean hasCustomizer()Test whether there is a customizer for this node. If true, the customizer can be obtained viagetCustomizer()
.- Returns:
true
if there is a customizer
-
getCustomizer
Get the customizer component.- Returns:
- the component, or
null
if there is no customizer
-
getCookie
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:
-
getLookup
public final org.openide.util.Lookup getLookup()Obtains a Lookup representing 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 ofgetCookie(java.lang.Class)
method is provided.- Specified by:
getLookup
in interfaceorg.openide.util.Lookup.Provider
- Returns:
- lookup for this node
- Since:
- 3.11
-
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 rendererorg.openide.awt.HtmlRenderer
(font color, bold, italic and strike-through 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 rendered must be escaped (>
becomes>
and so forth).This method should return either an HTML display name or null; it should not return the non-HTML display name.
Note the specified foreground color has to have a high luminescence difference to the background color in order to be used (displayed). If not, the specified foreground color will be ignored and the default color will be used. Luminescence of a color is calculated as following:
(Red value * 299 + Green value * 587 + Blue value * 114) / 1000
and the difference has to be greater or equal to 80.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:
-
getHandle
Obtain handle for this node (for serialization). The handle can be serialized andNode.Handle.getNode()
used after deserialization to obtain the original node.- Returns:
- the handle, or
null
if this node is not persistable
-
addNodeListener
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
Remove a node listener.- Parameters:
l
- the listener
-
addPropertyChangeListener
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
Remove a Bean property change listener.- Parameters:
l
- the listener
-
firePropertyChange
Fire a property change event.- Parameters:
name
- name of changed property (fromgetPropertySets()
); may be nullo
- old value; may be nulln
- new value; may be null- See Also:
-
fireNameChange
-
fireDisplayNameChange
-
fireShortDescriptionChange
-
fireIconChange
protected final void fireIconChange()Fire a change event forPROP_ICON
. -
fireOpenedIconChange
protected final void fireOpenedIconChange()Fire a change event forPROP_OPENED_ICON
. -
fireNodeDestroyed
protected final void fireNodeDestroyed()To all node listeners fire node destroyed notification. -
firePropertySetsChange
Fires a (Bean) property change event (forPROP_PROPERTY_SETS
).- Parameters:
o
- the old setn
- the new set
-
fireCookieChange
protected final void fireCookieChange()Fires a change event forPROP_COOKIE
. The old and new values are set to null. -
equals
Compares for equality. Does special treatment of FilterNodes. If argument is FilterNode then this node can be equal with it if it is its original. -
hashCode
-
toString
- Overrides:
toString
in classFeatureDescriptor
-