org.openide.nodes
Class AbstractNode

java.lang.Object
  |
  +--java.beans.FeatureDescriptor
        |
        +--org.openide.nodes.Node
              |
              +--org.openide.nodes.AbstractNode
Direct Known Subclasses:
BeanNode, DataNode, ElementNode, IndexedNode

public class AbstractNode
extends Node

A basic implementation of a node.

It simplifies creation of the display name, based on a message format and the system name. It also simplifies working with icons: one need only specify the base name and all icons will be loaded when needed. Other common requirements are handled as well.


Inner classes inherited from class org.openide.nodes.Node
Node.Cookie, Node.Handle, Node.IndexedProperty, Node.Property, Node.PropertySet
 
Field Summary
protected  MessageFormat displayFormat
          Message format to use for creation of the display name.
protected  SystemAction[] systemActions
          Actions for the node.
 
Fields inherited from class org.openide.nodes.Node
EMPTY, PROP_COOKIE, PROP_DISPLAY_NAME, PROP_ICON, PROP_NAME, PROP_OPENED_ICON, PROP_PARENT_NODE, PROP_PROPERTY_SETS, PROP_SHORT_DESCRIPTION
 
Constructor Summary
AbstractNode(Children children)
          Create a new abstract node with a given child set.
 
Method Summary
 boolean canCopy()
          Can this node be copied?
 boolean canCut()
          Can this node be cut?
 boolean canDestroy()
          Can this node be destroyed?
 boolean canRename()
          Can this node be renamed?
 Transferable clipboardCopy()
          Copy this node to the clipboard.
 Transferable clipboardCut()
          Cut this node to the clipboard.
 Node cloneNode()
          Clone the node.
protected  SystemAction[] createActions()
          Lazily initialize set of node's actions (overridable).
protected  void createPasteTypes(Transferable t, List s)
          Accumulate the paste types that this node can handle for a given transferable.
protected  Sheet createSheet()
          Initialize a default property sheet; commonly overridden.
 Transferable drag()
          This implementation only calls clipboardCopy supposing that copy to clipboard and copy by d'n'd are similar.
 SystemAction[] getActions()
          Get all actions for the node.
 Node.Cookie getCookie(Class type)
          Get a cookie from the node.
protected  CookieSet getCookieSet()
          Get the cookie set.
 Component getCustomizer()
          Get the customizer.
 SystemAction getDefaultAction()
          Get the default action for this node.
 PasteType getDropType(Transferable t, int action, int index)
          Default implementation that tries to delegate the implementation to the createPasteTypes method.
 Node.Handle getHandle()
          Get a serializable handle for this node.
 HelpCtx getHelpCtx()
          Get context help associated with this node.
 Image getIcon(int type)
          Find an icon for this node.
 NewType[] getNewTypes()
          Get the new types that can be created in this node.
 Image getOpenedIcon(int type)
          Finds an icon for this node when opened.
 PasteType[] getPasteTypes(Transferable t)
          Determine which paste operations are allowed when a given transferable is in the clipboard.
 Node.PropertySet[] getPropertySets()
          Get a list of property sets.
protected  Sheet getSheet()
          Get the current property sheet.
 boolean hasCustomizer()
          Does this node have a customizer?
protected  void setCookieSet(CookieSet s)
          Deprecated. just use getCookieSet().add(...) instead
 void setDefaultAction(SystemAction action)
          Set a default action for the node.
 void setIconBase(String base)
          Change the icon.
 void setName(String s)
          Set the system name.
protected  void setSheet(Sheet s)
          Set the set of properties.
 
Methods inherited from class org.openide.nodes.Node
addNodeListener, addPropertyChangeListener, clone, destroy, fireCookieChange, fireDisplayNameChange, fireIconChange, fireNameChange, fireNodeDestroyed, fireOpenedIconChange, firePropertyChange, firePropertySetsChange, fireShortDescriptionChange, getChildren, getContextActions, getContextMenu, getParentNode, hasPropertyChangeListener, isLeaf, removeNodeListener, removePropertyChangeListener, setDisplayName, setShortDescription, 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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

displayFormat

protected MessageFormat displayFormat
Message format to use for creation of the display name. It permits conversion of text from FeatureDescriptor.getName() to the one sent to Node.setDisplayName(java.lang.String). The format can take one parameter, {0}, which will be filled by a value from getName().

The default format just uses the simple name; subclasses may change it, though it will not take effect until the next setName(java.lang.String) call.

Can be set to null. Then there is no connection between the name and display name; they may be independently modified.


systemActions

protected SystemAction[] systemActions
Actions for the node. They are used only for the pop-up menus of this node.
Constructor Detail

AbstractNode

public AbstractNode(Children children)
Create a new abstract node with a given child set.
Parameters:
children - the children to use for this node
Method Detail

cloneNode

public Node cloneNode()
Clone the node. If the object implements Cloneable, that is used; otherwise a filter node is created.
Overrides:
cloneNode in class Node
Returns:
copy of this node

setName

public void setName(String s)
Set the system name. Fires a property change event. Also may change the display name according to displayFormat.
Overrides:
setName in class Node
Parameters:
s - the new name

setIconBase

public void setIconBase(String base)
Change the icon. One need only specify the base resource name; the real name of the icon is obtained by the applying icon message formats.

For example, for the base /resource/MyIcon, the following images may be used according to the icon state and presentation type:

This method may be used to dynamically switch between different sets of icons for different configurations. If the set is changed, an icon property change event is fired.

Parameters:
base - base resouce name

getIcon

public Image getIcon(int type)
Find an icon for this node. Uses an icon set.
Overrides:
getIcon in class Node
Parameters:
type - constants from BeanInfo
Returns:
icon to use to represent the bean

getOpenedIcon

public Image getOpenedIcon(int type)
Finds an icon for this node when opened. This icon should represent the node only when it is opened (when it can have children).
Overrides:
getOpenedIcon in class Node
Parameters:
type - as in getIcon(int)
Returns:
icon to use to represent the bean when opened

getHelpCtx

public HelpCtx getHelpCtx()
Description copied from class: Node
Get context help associated with this node.
Overrides:
getHelpCtx in class Node
Following copied from class: org.openide.nodes.Node
Returns:
the context help object (could be null or HelpCtx.DEFAULT_HELP)

canRename

public boolean canRename()
Can this node be renamed?
Overrides:
canRename in class Node
Returns:
false

canDestroy

public boolean canDestroy()
Can this node be destroyed?
Overrides:
canDestroy in class Node
Returns:
false

setSheet

protected final void setSheet(Sheet s)
Set the set of properties. A listener is attached to the provided sheet and any change of the sheet is propagated to the node by firing a Node.PROP_PROPERTY_SETS change event.
Parameters:
s - the sheet to use

createSheet

protected Sheet createSheet()
Initialize a default property sheet; commonly overridden. If getSheet() is called and there is not yet a sheet, this method is called to allow a subclass to specify its properties.

Warning: Do not call getSheet in this method.

The default implementation returns an empty sheet.

Returns:
the sheet with initialized values (never null)

getSheet

protected final Sheet getSheet()
Get the current property sheet. If the sheet has been previously set by a call to setSheet(org.openide.nodes.Sheet), that sheet is returned. Otherwise createSheet() is called.
Returns:
the sheet (never null)

getPropertySets

public Node.PropertySet[] getPropertySets()
Get a list of property sets.
Overrides:
getPropertySets in class Node
Returns:
the property sets for this node
See Also:
getSheet()

clipboardCopy

public Transferable clipboardCopy()
                           throws IOException
Copy this node to the clipboard.
Overrides:
clipboardCopy in class Node
Returns:
ExTransferable.Single with one copy flavor
Throws:
IOException - if it could not copy
See Also:
NodeTransfer

clipboardCut

public Transferable clipboardCut()
                          throws IOException
Cut this node to the clipboard.
Overrides:
clipboardCut in class Node
Returns:
ExTransferable.Single with one cut flavor
Throws:
IOException - if it could not cut
See Also:
NodeTransfer

drag

public Transferable drag()
                  throws IOException
This implementation only calls clipboardCopy supposing that copy to clipboard and copy by d'n'd are similar.
Overrides:
drag in class Node
Returns:
transferable to represent this node during a drag
Throws:
IOException - when the cut cannot be performed

canCopy

public boolean canCopy()
Can this node be copied?
Overrides:
canCopy in class Node
Returns:
true

canCut

public boolean canCut()
Can this node be cut?
Overrides:
canCut in class Node
Returns:
false

createPasteTypes

protected void createPasteTypes(Transferable t,
                                List s)
Accumulate the paste types that this node can handle for a given transferable.

The default implementation simply tests whether the transferable supports intelligent pasting via NodeTransfer.findPaste(java.awt.datatransfer.Transferable), and if so, it obtains the paste types from the transfer data and inserts them into the set.

Subclass implementations should typically call super (first or last) so that they add to, rather than replace, a superclass's available paste types; especially as the default implementation in AbstractNode is generally desirable to retain.

Parameters:
t - a transferable containing clipboard data
s - a list of PasteTypes that will have added to it all types valid for this node (ordered as they will be presented to the user)

getPasteTypes

public final PasteType[] getPasteTypes(Transferable t)
Determine which paste operations are allowed when a given transferable is in the clipboard. Subclasses should override createPasteTypes(java.awt.datatransfer.Transferable, java.util.List).
Overrides:
getPasteTypes in class Node
Parameters:
t - the transferable in the clipboard
Returns:
array of operations that are allowed

getDropType

public PasteType getDropType(Transferable t,
                             int action,
                             int index)
Default implementation that tries to delegate the implementation to the createPasteTypes method. Simply calls the method and tries to take the first provided argument. Ignores the action argument and index.
Overrides:
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 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 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.
Overrides:
getNewTypes in class Node
Following copied from class: org.openide.nodes.Node
Returns:
array of new type operations that are allowed

getDefaultAction

public SystemAction getDefaultAction()
Description copied from class: Node
Get the default action for this node. This action can but need not be one from the list returned from Node.getActions(). If so, the popup menu returned from Node.getContextMenu() is encouraged to highlight the action.
Overrides:
getDefaultAction in class Node
Following copied from class: org.openide.nodes.Node
Returns:
default action, or null if there should be none

setDefaultAction

public void setDefaultAction(SystemAction action)
Set a default action for the node.
Parameters:
action - the new default action, or null for none

getActions

public SystemAction[] getActions()
Get all actions for the node. Initialized with createActions(), or with the superclass's list.
Overrides:
getActions in class Node
Returns:
actions for the node

createActions

protected SystemAction[] createActions()
Lazily initialize set of node's actions (overridable). The default implementation returns null.

Warning: do not call getActions() within this method. If necessary, call NodeOp.getDefaultActions() to merge in.

Returns:
array of actions for this node, or null to use the default node actions

hasCustomizer

public boolean hasCustomizer()
Does this node have a customizer?
Overrides:
hasCustomizer in class Node
Returns:
false

getCustomizer

public Component getCustomizer()
Get the customizer.
Overrides:
getCustomizer in class Node
Returns:
null in the default implementation

setCookieSet

protected final void setCookieSet(CookieSet s)
Deprecated. just use getCookieSet().add(...) instead

Set the cookie set. A listener is attached to the provided cookie set, and any change of the sheet is propagated to the node by firing Node.PROP_COOKIE change events.
Parameters:
s - the cookie set to use

getCookieSet

protected final CookieSet getCookieSet()
Get the cookie set.
Returns:
the cookie set created by setCookieSet(org.openide.nodes.CookieSet), or an empty set (never null)

getCookie

public Node.Cookie getCookie(Class type)
Get a cookie from the node. Uses the cookie set as determined by getCookieSet().
Overrides:
getCookie in class Node
Parameters:
type - the representation class
Returns:
the cookie or null

getHandle

public Node.Handle getHandle()
Get a serializable handle for this node.
Overrides:
getHandle in class Node
Returns:
a DefaultHandle in the default implementation


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