org.openide.nodes 7.2.1

org.openide.nodes
Class FilterNode

java.lang.Object
  extended by java.beans.FeatureDescriptor
      extended by org.openide.nodes.Node
          extended by org.openide.nodes.FilterNode
All Implemented Interfaces:
HelpCtx.Provider, Lookup.Provider

public class FilterNode
extends Node

A proxy for another node. Unless otherwise mentioned, all methods of the original node are delegated to. If desired, you can disable delegation of certain methods which are concrete in Node by calling disableDelegation(int).

Note: it is fine to subclass this class and use it to filter things. But please do not ever try to cast a node to FilterNode: it probably means you are doing something wrong. Instead, ask whatever Node you have for a proper kind of cookie (e.g. DataObject).


Nested Class Summary
static class FilterNode.Children
          Children for a filter node.
protected static class FilterNode.NodeAdapter
          Adapter that listens on changes in an original node and refires them in a proxy.
protected static class FilterNode.PropertyChangeAdapter
          Adapter that listens on changes in an original node and refires them in a proxy.
 
Nested classes/interfaces inherited from class org.openide.nodes.Node
Node.Cookie, Node.Handle, Node.IndexedProperty<T,E>, Node.Property<T>, Node.PropertySet
 
Field Summary
protected static int DELEGATE_DESTROY
          Whether to delegate destroy.
protected static int DELEGATE_GET_ACTIONS
          Whether to delegate getActions.
protected static int DELEGATE_GET_CONTEXT_ACTIONS
          Whether to delegate getContextActions.
protected static int DELEGATE_GET_DISPLAY_NAME
          Whether to delegate getDisplayName.
protected static int DELEGATE_GET_NAME
          Whether to delegate getName.
protected static int DELEGATE_GET_SHORT_DESCRIPTION
          Whether to delegate getShortDescription.
protected static int DELEGATE_GET_VALUE
          Whether to delegate getValue.
protected static int DELEGATE_SET_DISPLAY_NAME
          Whether to delegate setDisplayName.
protected static int DELEGATE_SET_NAME
          Whether to delegate setName.
protected static int DELEGATE_SET_SHORT_DESCRIPTION
          Whether to delegate setShortDescription.
protected static int DELEGATE_SET_VALUE
          Whether to delegate setValue.
 
Fields inherited from class org.openide.nodes.Node
EMPTY, PROP_COOKIE, PROP_DISPLAY_NAME, PROP_ICON, PROP_LEAF, PROP_NAME, PROP_OPENED_ICON, PROP_PARENT_NODE, PROP_PROPERTY_SETS, PROP_SHORT_DESCRIPTION
 
Constructor Summary
FilterNode(Node original)
          Create proxy.
FilterNode(Node original, Children children)
          Create proxy with a different set of children.
FilterNode(Node original, Children children, Lookup lookup)
          Constructs new filter node with a provided children and lookup.
 
Method Summary
 boolean canCopy()
          Test whether this node permits copying.
 boolean canCut()
          Test whether this node permits cutting.
 boolean canDestroy()
          Test whether this node can be deleted.
 boolean canRename()
          Test whether this node can be renamed.
protected  void changeOriginal(Node original, boolean changeChildren)
          Changes the original node for this node.
 Transferable clipboardCopy()
          Called when a node is to be copied to the clipboard.
 Transferable clipboardCut()
          Called when a node is to be cut to the clipboard.
 Node cloneNode()
          Create new filter node for the original.
protected  NodeListener createNodeListener()
          Creates a node listener that allows listening on the original node and propagating events to the proxy.
protected  PropertyChangeListener createPropertyChangeListener()
          Create a property change listener that allows listening on the original node properties (contained in property sets) and propagating them to the proxy.
 void destroy()
          Remove the node from its parent and deletes it.
protected  void disableDelegation(int mask)
          Disable delegation of a set of methods.
 Transferable drag()
          Called when a drag is started with this node.
protected  void enableDelegation(int mask)
          Enable delegation of a set of methods.
 boolean equals(Object o)
          Test equality of original nodes.
protected  void finalize()
          Removes all listeners (property and node) on the original node.
 SystemAction[] getActions()
          Deprecated. 
 Action[] getActions(boolean context)
          Get the set of actions that are associated with this node.
 SystemAction[] getContextActions()
          Deprecated. 
<T extends Node.Cookie>
T
getCookie(Class<T> type)
          Delegates to original, if no special lookup provided in constructor, Otherwise it delegates to the lookup.
 Component getCustomizer()
          Get the customizer component.
 SystemAction getDefaultAction()
          Deprecated. 
 String getDisplayName()
           
 PasteType getDropType(Transferable t, int action, int index)
          Determine if there is a paste operation that can be performed on provided transferable.
 Node.Handle getHandle()
          If this is FilterNode without any changes (subclassed, changed children) and the original provides handle, stores them and returns a new handle for the proxy.
 HelpCtx getHelpCtx()
          Get context help associated with this node.
 String getHtmlDisplayName()
          Get a display name containing HTML markup.
 Image getIcon(int type)
          Find an icon for this node (in the closed state).
 String getName()
           
 NewType[] getNewTypes()
          Get the new types that can be created in this node.
 Image getOpenedIcon(int type)
          Find an icon for this node (in the open state).
protected  Node getOriginal()
          Get the original node.
 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.
 Node.PropertySet[] getPropertySets()
          Get the list of property sets for this node.
 String getShortDescription()
           
 Object getValue(String attributeName)
           
 boolean hasCustomizer()
          Test whether there is a customizer for this node.
 int hashCode()
          Hash by original nodes.
 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.
 void setValue(String attributeName, Object value)
           
 
Methods inherited from class org.openide.nodes.Node
addNodeListener, addPropertyChangeListener, clone, fireCookieChange, fireDisplayNameChange, fireIconChange, fireNameChange, fireNodeDestroyed, fireOpenedIconChange, firePropertyChange, firePropertySetsChange, fireShortDescriptionChange, getChildren, getContextMenu, getLookup, getParentNode, hasPropertyChangeListener, isLeaf, removeNodeListener, removePropertyChangeListener, setChildren, toString
 
Methods inherited from class java.beans.FeatureDescriptor
attributeNames, isExpert, isHidden, isPreferred, setExpert, setHidden, setPreferred
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DELEGATE_SET_NAME

protected static final int DELEGATE_SET_NAME
Whether to delegate setName.

See Also:
Constant Field Values

DELEGATE_GET_NAME

protected static final int DELEGATE_GET_NAME
Whether to delegate getName.

See Also:
Constant Field Values

DELEGATE_SET_DISPLAY_NAME

protected static final int DELEGATE_SET_DISPLAY_NAME
Whether to delegate setDisplayName.

See Also:
Constant Field Values

DELEGATE_GET_DISPLAY_NAME

protected static final int DELEGATE_GET_DISPLAY_NAME
Whether to delegate getDisplayName.

See Also:
Constant Field Values

DELEGATE_SET_SHORT_DESCRIPTION

protected static final int DELEGATE_SET_SHORT_DESCRIPTION
Whether to delegate setShortDescription.

See Also:
Constant Field Values

DELEGATE_GET_SHORT_DESCRIPTION

protected static final int DELEGATE_GET_SHORT_DESCRIPTION
Whether to delegate getShortDescription.

See Also:
Constant Field Values

DELEGATE_DESTROY

protected static final int DELEGATE_DESTROY
Whether to delegate destroy.

See Also:
Constant Field Values

DELEGATE_GET_ACTIONS

protected static final int DELEGATE_GET_ACTIONS
Whether to delegate getActions.

See Also:
Constant Field Values

DELEGATE_GET_CONTEXT_ACTIONS

protected static final int DELEGATE_GET_CONTEXT_ACTIONS
Whether to delegate getContextActions.

See Also:
Constant Field Values

DELEGATE_SET_VALUE

protected static final int DELEGATE_SET_VALUE
Whether to delegate setValue.

Since:
4.25
See Also:
Constant Field Values

DELEGATE_GET_VALUE

protected static final int DELEGATE_GET_VALUE
Whether to delegate getValue.

Since:
4.25
See Also:
Constant Field Values
Constructor Detail

FilterNode

public FilterNode(Node original)
Create proxy.

Parameters:
original - the node to delegate to

FilterNode

public FilterNode(Node original,
                  Children children)
Create proxy with a different set of children.

Parameters:
original - the node to delegate to
children - a set of children for this node

FilterNode

public FilterNode(Node original,
                  Children children,
                  Lookup lookup)
Constructs new filter node with a provided children and lookup. The lookup is used to implement getCookie(java.lang.Class) calls that just call lookup.lookup(clazz). If this constructor is used, the code shall not override getCookie(java.lang.Class) method, but do all its state manipulation in the lookup. Look at Node.Node(org.openide.nodes.Children, org.openide.util.Lookup) constructor for best practices usage of this constructor.

Parameters:
original - the node we delegate to
children - the children to use for the filter node or null if default children should be provided
lookup - lookup to use. Do not pass orginal.getLookup() into this parameter. In such case use the FilterNode(Node, Children) constructor.
Since:
4.4
Method Detail

finalize

protected void finalize()
Removes all listeners (property and node) on the original node. Called from NodeListener.nodeDestroyed(org.openide.nodes.NodeEvent), but can be called by any subclass to stop reflecting changes in the original node.

Overrides:
finalize in class Object

enableDelegation

protected final void enableDelegation(int mask)
Enable delegation of a set of methods. These will be delegated to the original node. Since all available methods are delegated by default, normally you will not need to call this.

Parameters:
mask - bitwise disjunction of DELEGATE_XXX constants
Throws:
IllegalArgumentException - if the mask is invalid

disableDelegation

protected final void disableDelegation(int mask)
Disable delegation of a set of methods. The methods will retain their behavior from Node.

For example, if you wish to subclass FilterNode, giving your node a distinctive display name and tooltip, and performing some special action upon deletion, you may do so without risk of affecting the original node as follows:

 public MyNode extends FilterNode {
   public MyNode (Node orig) {
     super (orig, new MyChildren (orig));
     disableDelegation (DELEGATE_GET_DISPLAY_NAME | DELEGATE_SET_DISPLAY_NAME |
                        DELEGATE_GET_SHORT_DESCRIPTION | DELEGATE_SET_SHORT_DESCRIPTION |
                        DELEGATE_DESTROY);
     // these will affect only the filter node:
     setDisplayName ("Linking -> " + orig.getDisplayName ());
     setShortDescription ("Something different.");
   }
   public boolean canRename () { return false; }
   public void destroy () throws IOException {
     doMyCleanup ();
     super.destroy (); // calls Node.destroy(), not orig.destroy()
   }
 }
 

You may still manually delegate where desired using getOriginal(). Other methods abstract in Node may simply be overridden without any special handling.

Parameters:
mask - bitwise disjunction of DELEGATE_XXX constants
Throws:
IllegalArgumentException - if the mask is invalid

cloneNode

public Node cloneNode()
Create new filter node for the original. Subclasses do not have to override this, but if they do not, the default implementation will filter the subclass filter, which is not very efficient.

Specified by:
cloneNode in class Node
Returns:
copy of this node

changeOriginal

protected final void changeOriginal(Node original,
                                    boolean changeChildren)
Changes the original node for this node.

Parameters:
original - The new original node.
changeChildren - If set to true changes children of this node according to the new original node. If you pass children which are not instance of class FilterNode.Children into the constructor set this parameter to false. Be aware that this method aquires write lock on the nodes hierarchy (Children.MUTEX). Take care not to call this method under read lock.
Throws:
IllegalStateException - if children which are not instance of FilterNode.Children were passed into the constructor and the method was called with the parameter changeChildren set to true.
Since:
1.39

setValue

public void setValue(String attributeName,
                     Object value)
Overrides:
setValue in class FeatureDescriptor

getValue

public Object getValue(String attributeName)
Overrides:
getValue in class FeatureDescriptor

setName

public void setName(String s)
Description copied from class: Node
Set the system name. Fires a property change event.

Overrides:
setName in class Node
Parameters:
s - the new name

getName

public String getName()
Overrides:
getName in class FeatureDescriptor

setDisplayName

public void setDisplayName(String s)
Description copied from class: Node
Set the display name. Fires a property change event.

Overrides:
setDisplayName in class Node
Parameters:
s - the new name

getDisplayName

public String getDisplayName()
Overrides:
getDisplayName in class FeatureDescriptor

setShortDescription

public void setShortDescription(String s)
Description copied from class: Node
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 Node
Parameters:
s - the new description

getShortDescription

public String getShortDescription()
Overrides:
getShortDescription in class FeatureDescriptor

getIcon

public Image getIcon(int type)
Description copied from class: Node
Find an icon for this node (in the closed state).

Specified by:
getIcon in class Node
Parameters:
type - constant from BeanInfo
Returns:
icon to use to represent the node

getOpenedIcon

public Image getOpenedIcon(int type)
Description copied from class: Node
Find an icon for this node (in the open state). This icon is used when the node may have children and is expanded.

Specified by:
getOpenedIcon in class Node
Parameters:
type - constant from BeanInfo
Returns:
icon to use to represent the node when open

getHelpCtx

public HelpCtx getHelpCtx()
Description copied from class: Node
Get context help associated with this node.

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

canRename

public boolean canRename()
Description copied from class: Node
Test whether this node can be renamed. If true, one can use FeatureDescriptor.getName() to obtain the current name and Node.setName(java.lang.String) to change it.

Specified by:
canRename in class Node
Returns:
true if the node can be renamed

canDestroy

public boolean canDestroy()
Description copied from class: Node
Test whether this node can be deleted.

Specified by:
canDestroy in class Node
Returns:
true if can

destroy

public void destroy()
             throws IOException
Description copied from class: Node
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.

Overrides:
destroy in class Node
Throws:
IOException - if something fails

getPropertySets

public Node.PropertySet[] getPropertySets()
Description copied from class: Node
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.

Specified by:
getPropertySets in class Node
Returns:
the property sets

clipboardCopy

public Transferable clipboardCopy()
                           throws IOException
Description copied from class: Node
Called when a node is to be copied to the clipboard.

Specified by:
clipboardCopy in class Node
Returns:
the transferable object representing the content of the clipboard
Throws:
IOException - when the copy cannot be performed

clipboardCut

public Transferable clipboardCut()
                          throws IOException
Description copied from class: Node
Called when a node is to be cut to the clipboard.

Specified by:
clipboardCut in class Node
Returns:
the transferable object representing the content of the clipboard
Throws:
IOException - when the cut cannot be performed

canCopy

public boolean canCopy()
Description copied from class: Node
Test whether this node permits copying.

Specified by:
canCopy in class Node
Returns:
true if so

canCut

public boolean canCut()
Description copied from class: Node
Test whether this node permits cutting.

Specified by:
canCut in class Node
Returns:
true if so

drag

public Transferable drag()
                  throws IOException
Description copied from class: Node
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).

Specified by:
drag in class Node
Returns:
transferable to represent this node during a drag
Throws:
IOException - if a drag cannot be started

getDropType

public PasteType getDropType(Transferable t,
                             int action,
                             int index)
Description copied from class: Node
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.

Specified by:
getDropType in class Node
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 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

getPasteTypes

public PasteType[] getPasteTypes(Transferable t)
Description copied from class: Node
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.

Specified by:
getPasteTypes in class Node
Parameters:
t - the transferable in the clipboard
Returns:
array of operations that are allowed

getNewTypes

public NewType[] getNewTypes()
Description copied from class: Node
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.

Specified by:
getNewTypes in class Node
Returns:
array of new type operations that are allowed

getActions

@Deprecated
public SystemAction[] getActions()
Deprecated. 

Description copied from class: Node
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().

Overrides:
getActions in class Node
Returns:
system actions appropriate to the node

getContextActions

@Deprecated
public SystemAction[] getContextActions()
Deprecated. 

Description copied from class: Node
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 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.

Overrides:
getContextActions in class Node
Returns:
actions for a context. In the default implementation, same as Node.getActions(boolean).

getDefaultAction

@Deprecated
public SystemAction getDefaultAction()
Deprecated. 

Description copied from class: Node
Gets the default action for this node.

Overrides:
getDefaultAction in class Node
Returns:
null indicating there should be none default action

getActions

public Action[] getActions(boolean context)
Description copied from class: Node
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.

Overrides:
getActions in class Node
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)

getPreferredAction

public Action getPreferredAction()
Description copied from class: Node
Gets the preferred action for this node. This action can but need not to be one from the action array returned from Node.getActions(boolean). In case it is, the context menu created from those actions is encouraged to highlight the preferred action. Override in subclasses accordingly.

Overrides:
getPreferredAction in class Node
Returns:
the preferred action, or null if there is none

getHtmlDisplayName

public String getHtmlDisplayName()
Get a display name containing HTML markup. Note: If you subclass FilterNode and override getDisplayName(), this method will always return null unless you override it as well (assuming that if you're changing the display name, you don't want an HTML display name constructed from the original node's display name to be what shows up in views of this node). If getDisplayName() is not overridden, this method will return whatever the original node returns from this method.

Note that if you do override getDisplayName, you should also override this method to return null.

Overrides:
getHtmlDisplayName in class Node
Returns:
An HTML display name, if available, or null if no display name is available
See Also:
Node.getHtmlDisplayName()

hasCustomizer

public boolean hasCustomizer()
Description copied from class: Node
Test whether there is a customizer for this node. If true, the customizer can be obtained via Node.getCustomizer().

Specified by:
hasCustomizer in class Node
Returns:
true if there is a customizer

getCustomizer

public Component getCustomizer()
Description copied from class: Node
Get the customizer component.

Specified by:
getCustomizer in class Node
Returns:
the component, or null if there is no customizer

getCookie

public <T extends Node.Cookie> T getCookie(Class<T> type)
Delegates to original, if no special lookup provided in constructor, Otherwise it delegates to the lookup. Never override this method if the lookup is provided in constructor.

Overrides:
getCookie in class Node
Parameters:
type - the class to look for
Returns:
instance of that class or null if this class of cookie is not supported
See Also:
Node.getCookie(java.lang.Class)

getHandle

public Node.Handle getHandle()
If this is FilterNode without any changes (subclassed, changed children) and the original provides handle, stores them and returns a new handle for the proxy.

Subclasses must override this if they wish for their nodes to be properly serializable.

Specified by:
getHandle in class Node
Returns:
the handle, or null if this node is subclassed or uses changed children

equals

public boolean equals(Object o)
Test equality of original nodes. Note that for subclasses of FilterNode, or filter nodes with non-default children, the test reverts to object identity. Note: if you wish that the Index cookie works correctly on filtered nodes and their subnodes, and you are subclassing FilterNode or using non-default children, you will probably want to override this method to test equality of the specified node with this filter node's original node; otherwise Move Up and Move Down actions may be disabled.

Note though that it is often better to provide your own index cookie from a filter node. Only then it is possible to change the number of children relative to the original. And in many cases this is easier anyway, as for example with DataFolder.Index for data folders.

Overrides:
equals in class Node
Parameters:
o - something to compare to, presumably a node or FilterNode of one
Returns:
true if this node's original node is the same as the parameter (or original node of parameter)

hashCode

public int hashCode()
Hash by original nodes. Note that for subclasses of FilterNode, or filter nodes with non-default children, the hash reverts to the identity hash code.

Overrides:
hashCode in class Object
Returns:
the delegated hash code

getOriginal

protected Node getOriginal()
Get the original node.

Yes this is supposed to be protected! If you are not subclassing FilterNode yourself, you should not be calling it (nor casting to FilterNode). Use cookies instead.

Returns:
the node proxied to

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Create a property change listener that allows listening on the original node properties (contained in property sets) and propagating them to the proxy.

This method is called during initialization and allows subclasses to modify the default behaviour.

Returns:
a FilterNode.PropertyChangeAdapter in the default implementation

createNodeListener

protected NodeListener createNodeListener()
Creates a node listener that allows listening on the original node and propagating events to the proxy.

Intended for overriding by subclasses, as with createPropertyChangeListener().

Returns:
a FilterNode.NodeAdapter in the default implementation

org.openide.nodes 7.2.1

Built on January 29 2008.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.