org.openide.util.HelpCtx.Provider, org.openide.util.Lookup.ProviderAbstractNode, FilterNodepublic abstract class Node
extends java.beans.FeatureDescriptor
implements org.openide.util.Lookup.Provider, org.openide.util.HelpCtx.Provider
The node has three purposes:
Frequently nodes are created to represent DataObjects.
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.
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
Node.Cookie |
Marker interface for all cookies.
|
static interface |
Node.Handle |
Serializable node reference.
|
static class |
Node.IndexedProperty<T,E> |
Description of an indexed property and operations on it.
|
static class |
Node.Property<T> |
Description of a Bean property on a node, and operations on it.
|
static class |
Node.PropertySet |
Class that represents one set of properties.
|
| Modifier and Type | Field | Description |
|---|---|---|
static Node |
EMPTY |
An empty leaf node.
|
static java.lang.String |
PROP_COOKIE |
Property for a node's cookie set.
|
static java.lang.String |
PROP_DISPLAY_NAME |
Property for node display name.
|
static java.lang.String |
PROP_ICON |
Property for the normal (closed) icon of a node.
|
static java.lang.String |
PROP_LEAF |
Property saying whether the Node is Leaf
|
static java.lang.String |
PROP_NAME |
Property for internal (not displayable) name of a node.
|
static java.lang.String |
PROP_OPENED_ICON |
Property for the opened icon of a node.
|
static java.lang.String |
PROP_PARENT_NODE |
Property for a node's parent.
|
static java.lang.String |
PROP_PROPERTY_SETS |
Property for a node's list of property sets.
|
static java.lang.String |
PROP_SHORT_DESCRIPTION |
Property for short description of a node.
|
| Modifier | Constructor | Description |
|---|---|---|
protected |
Node(Children h) |
Creates a new node with a given hierarchy of children.
|
protected |
Node(Children h,
org.openide.util.Lookup lookup) |
Creates a new node with a given hierarchy of children and a lookup
providing content for
getCookie(java.lang.Class<T>) and getLookup() methods. |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addNodeListener(NodeListener l) |
Add a listener to changes in the node's intrinsic properties (name, cookies, etc.).
|
void |
addPropertyChangeListener(java.beans.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 java.awt.datatransfer.Transferable |
clipboardCopy() |
Called when a node is to be copied to the clipboard.
|
abstract java.awt.datatransfer.Transferable |
clipboardCut() |
Called when a node is to be cut to the clipboard.
|
protected java.lang.Object |
clone() |
Implements
Object.clone() to behave correctly if cloning is desired. |
abstract Node |
cloneNode() |
Clone the node.
|
void |
destroy() |
Called when a node is deleted.
|
abstract java.awt.datatransfer.Transferable |
drag() |
Called when a drag is started with this node.
|
boolean |
equals(java.lang.Object obj) |
Compares for equality.
|
protected void |
fireCookieChange() |
Fires a change event for
PROP_COOKIE. |
protected void |
fireDisplayNameChange(java.lang.String o,
java.lang.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(java.lang.String o,
java.lang.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(java.lang.String name,
java.lang.Object o,
java.lang.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(java.lang.String o,
java.lang.String n) |
Allow subclasses that override the getShortDescription method to fire
the changes of the description by itself.
|
org.openide.util.actions.SystemAction[] |
getActions() |
Deprecated.
Use getActions (false) instead.
|
javax.swing.Action[] |
getActions(boolean context) |
Get the set of actions that are associated with this node.
|
Children |
getChildren() |
Get the list of children.
|
org.openide.util.actions.SystemAction[] |
getContextActions() |
Deprecated.
Use getActions (true) instead.
|
javax.swing.JPopupMenu |
getContextMenu() |
Makes a context menu for this node.
|
<T extends Node.Cookie> |
getCookie(java.lang.Class<T> type) |
Get a cookie for this node.
|
abstract java.awt.Component |
getCustomizer() |
Get the customizer component.
|
org.openide.util.actions.SystemAction |
getDefaultAction() |
Deprecated.
Use
getPreferredAction() instead. |
abstract org.openide.util.datatransfer.PasteType |
getDropType(java.awt.datatransfer.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 org.openide.util.HelpCtx |
getHelpCtx() |
Get context help associated with this node.
|
java.lang.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 strike-through supported; font
colors can be UIManager color keys if they are prefixed with
a ! character, i.e. |
abstract java.awt.Image |
getIcon(int type) |
Find an icon for this node (in the closed state).
|
org.openide.util.Lookup |
getLookup() |
Obtains a Lookup representing additional content of this Node.
|
abstract org.openide.util.datatransfer.NewType[] |
getNewTypes() |
Get the new types that can be created in this node.
|
abstract java.awt.Image |
getOpenedIcon(int type) |
Find an icon for this node (in the open state).
|
Node |
getParentNode() |
Get the parent node.
|
abstract org.openide.util.datatransfer.PasteType[] |
getPasteTypes(java.awt.datatransfer.Transferable t) |
Determine which paste operations are allowed when a given transferable is in the clipboard.
|
javax.swing.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.
|
int |
hashCode() |
|
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(java.beans.PropertyChangeListener l) |
Remove a Bean property change listener.
|
protected void |
setChildren(Children ch) |
Allows to change Children of the node.
|
void |
setDisplayName(java.lang.String s) |
Set the display name.
|
void |
setHidden(boolean hidden) |
Deprecated.
Has no effect. To make a node disappear, simply remove it from the
children of its parent. For example, you might call
Children.Keys.setKeys(Collection) with a smaller collection. |
void |
setName(java.lang.String s) |
Set the system name.
|
void |
setShortDescription(java.lang.String s) |
Set the short description of the node.
|
java.lang.String |
toString() |
public static final Node EMPTY
public static final java.lang.String PROP_DISPLAY_NAME
public static final java.lang.String PROP_NAME
public static final java.lang.String PROP_SHORT_DESCRIPTION
public static final java.lang.String PROP_ICON
public static final java.lang.String PROP_OPENED_ICON
public static final java.lang.String PROP_PARENT_NODE
public static final java.lang.String PROP_PROPERTY_SETS
public static final java.lang.String PROP_COOKIE
public static final java.lang.String PROP_LEAF
protected Node(Children h) throws java.lang.IllegalStateException
h - the children to use for this nodejava.lang.IllegalStateException - if the children object is already in use by
a different nodeprotected Node(Children h, org.openide.util.Lookup lookup) throws java.lang.IllegalStateException
getCookie(java.lang.Class<T>) and getLookup() 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);
}
h - the children to use for this nodelookup - the lookup to provide content of getLookup()
and also getCookie(java.lang.Class<T>)java.lang.IllegalStateException - if the children object is already in use by
a different nodeprotected java.lang.Object clone()
throws java.lang.CloneNotSupportedException
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.
clone in class java.lang.Objectjava.lang.CloneNotSupportedException - if the children cannot be cloned
in spite of implementing Cloneablepublic abstract Node cloneNode()
public void setName(java.lang.String s)
setName in class java.beans.FeatureDescriptors - the new namejava.lang.IllegalArgumentException - if the new name cannot represent
a valid node namepublic void setDisplayName(java.lang.String s)
setDisplayName in class java.beans.FeatureDescriptors - the new namepublic void setShortDescription(java.lang.String s)
This description may be used for tool tips, etc.
setShortDescription in class java.beans.FeatureDescriptors - the new description@Deprecated public void setHidden(boolean hidden)
Children.Keys.setKeys(Collection) with a smaller collection.setHidden in class java.beans.FeatureDescriptorpublic abstract java.awt.Image getIcon(int type)
type - constant from BeanInfopublic abstract java.awt.Image getOpenedIcon(int type)
type - constant from BeanInfopublic abstract org.openide.util.HelpCtx getHelpCtx()
getHelpCtx in interface org.openide.util.HelpCtx.Providernull or HelpCtx.DEFAULT_HELP)public final Children getChildren()
protected final void setChildren(Children ch)
ch - New children to be set on the node.public final boolean isLeaf()
true if the children list is actually Children.LEAFpublic final Node getParentNode()
null if this node is the root of a hierarchypublic abstract boolean canRename()
FeatureDescriptor.getName() to obtain the current name and
setName(java.lang.String) to change it.true if the node can be renamedpublic abstract boolean canDestroy()
true if canpublic void destroy()
throws java.io.IOException
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.
java.io.IOException - if something failspublic abstract Node.PropertySet[] getPropertySets()
public abstract java.awt.datatransfer.Transferable clipboardCopy()
throws java.io.IOException
java.io.IOException - when the
copy cannot be performedpublic abstract java.awt.datatransfer.Transferable clipboardCut()
throws java.io.IOException
java.io.IOException - when the
cut cannot be performedpublic abstract java.awt.datatransfer.Transferable drag()
throws java.io.IOException
java.io.IOException - if a drag cannot be startedpublic abstract boolean canCopy()
true if sopublic abstract boolean canCut()
true if sopublic abstract org.openide.util.datatransfer.PasteType[] getPasteTypes(java.awt.datatransfer.Transferable t)
t - the transferable in the clipboardpublic abstract org.openide.util.datatransfer.PasteType getDropType(java.awt.datatransfer.Transferable t,
int action,
int index)
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 specifiedpublic abstract org.openide.util.datatransfer.NewType[] getNewTypes()
public javax.swing.Action[] getActions(boolean context)
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.
context - whether to find actions for context meaning or for the
node itself@Deprecated public org.openide.util.actions.SystemAction[] getActions()
context menu.
By default returns the actions in NodeOp.getDefaultActions().
@Deprecated public org.openide.util.actions.SystemAction[] getContextActions()
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
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 context menu.
Note that in the Windows UI system, e.g., these action sets are quite different.
getActions(boolean).@Deprecated public org.openide.util.actions.SystemAction getDefaultAction()
getPreferredAction() instead.null indicating there should be none default actionpublic javax.swing.Action getPreferredAction()
getActions(boolean).
In case it is, the context menu created from those actions
is encouraged to highlight the preferred action.
Override in subclasses accordingly.null if there is nonepublic final javax.swing.JPopupMenu getContextMenu()
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.
NodeOp.findContextMenu(org.openide.nodes.Node[])public abstract boolean hasCustomizer()
getCustomizer().true if there is a customizerpublic abstract java.awt.Component getCustomizer()
null if there is no customizerpublic <T extends Node.Cookie> T getCookie(java.lang.Class<T> type)
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.
type - the representation class of the cookienull if this node has no such cookieLookuppublic final org.openide.util.Lookup getLookup()
getLookup in interface org.openide.util.Lookup.Providerpublic java.lang.String getHtmlDisplayName()
org.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.
HtmlRendererpublic abstract Node.Handle getHandle()
Node.Handle.getNode() used after
deserialization to obtain the original node.null if this node is not persistablepublic final void addNodeListener(NodeListener l)
The listener is not notified about changes in subnodes until the
method getChildren().getNodes() is called.
l - the listener to addpublic final void removeNodeListener(NodeListener l)
l - the listenerpublic final void addPropertyChangeListener(java.beans.PropertyChangeListener l)
l - the listenerprotected final boolean hasPropertyChangeListener()
public final void removePropertyChangeListener(java.beans.PropertyChangeListener l)
l - the listenerprotected final void firePropertyChange(java.lang.String name,
java.lang.Object o,
java.lang.Object n)
name - name of changed property (from getPropertySets()); may be nullo - old value; may be nulln - new value; may be nullPropertyChangeEventprotected final void fireNameChange(java.lang.String o,
java.lang.String n)
protected final void fireDisplayNameChange(java.lang.String o,
java.lang.String n)
protected final void fireShortDescriptionChange(java.lang.String o,
java.lang.String n)
protected final void fireIconChange()
PROP_ICON.protected final void fireOpenedIconChange()
PROP_OPENED_ICON.protected final void fireNodeDestroyed()
protected final void firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n)
PROP_PROPERTY_SETS).o - the old setn - the new setprotected final void fireCookieChange()
PROP_COOKIE.
The old and new values are set to null.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - object to compare== or is filter node of this nodepublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.beans.FeatureDescriptorBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.