org.openide.nodes 7.2.1

org.openide.nodes
Class AbstractNode

java.lang.Object
  extended by java.beans.FeatureDescriptor
      extended by org.openide.nodes.Node
          extended by org.openide.nodes.AbstractNode
All Implemented Interfaces:
HelpCtx.Provider, Lookup.Provider
Direct Known Subclasses:
BeanNode, 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.


Nested Class Summary
 
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  MessageFormat displayFormat
          Message format to use for creation of the display name.
protected  SystemAction[] systemActions
          Deprecated. Override Node.getActions(boolean) instead of using this field.
 
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
AbstractNode(Children children)
          Create a new abstract node with a given child set.
AbstractNode(Children children, Lookup lookup)
          Create a new abstract node with a given child set and associated lookup.
 
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()
          Deprecated. Override Node.getActions(boolean) instead.
protected  void createPasteTypes(Transferable t, List<PasteType> 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()
          Deprecated. Override Node.getActions(boolean) instead.
<T extends Node.Cookie>
T
getCookie(Class<T> type)
          Get a cookie from the node.
protected  CookieSet getCookieSet()
          Get the cookie set.
 Component getCustomizer()
          Get the customizer.
 SystemAction getDefaultAction()
          Deprecated. Use getPreferredAction() instead.
 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.
 Action getPreferredAction()
          Gets preferred action.
 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)
          Deprecated. Override getPreferredAction() instead.
 void setIconBase(String base)
          Deprecated. Use setIconBaseWithExtension(java.lang.String)
 void setIconBaseWithExtension(String baseExt)
          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, equals, fireCookieChange, fireDisplayNameChange, fireIconChange, fireNameChange, fireNodeDestroyed, fireOpenedIconChange, firePropertyChange, firePropertySetsChange, fireShortDescriptionChange, getActions, getChildren, getContextActions, getContextMenu, getHtmlDisplayName, getLookup, getParentNode, hasPropertyChangeListener, isLeaf, removeNodeListener, removePropertyChangeListener, setChildren, 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
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

@Deprecated
protected SystemAction[] systemActions
Deprecated. Override Node.getActions(boolean) instead of using this field.
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

AbstractNode

public AbstractNode(Children children,
                    Lookup lookup)
Create a new abstract node with a given child set and associated lookup. If you use this constructor, please do not call methods getCookieSet() and setCookieSet(org.openide.nodes.CookieSet) they will throw an exception.

More info on the correct usage of constructor with Lookup can be found in the Node.Node(org.openide.nodes.Children, org.openide.util.Lookup) javadoc.

Parameters:
children - the children to use for this node
lookup - the lookup to provide content of Node.getLookup() and also getCookie(java.lang.Class)
Since:
3.11
Method Detail

cloneNode

public Node cloneNode()
Clone the node. If the object implements Cloneable, that is used; otherwise a filter node is created.

Specified by:
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

@Deprecated
public void setIconBase(String base)
Deprecated. Use setIconBaseWithExtension(java.lang.String)

Change the icon. One need only specify the base resource name without extension; the real name of the icon is obtained by the applying icon message formats. The method effectively behaves as if it was just delegating to setIconBaseWithExtension(java.lang.String) using base + ".gif" as parameter.

Parameters:
base - base resouce name (no initial slash)

setIconBaseWithExtension

public final void setIconBaseWithExtension(String baseExt)
Change the icon. One need only specify the base name of the icon resource, including the resource extension; the real name of the icon is obtained by inserting proper infixes into the resource name.

For example, for the base org/foo/resource/MyIcon.png 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:
baseExt - base resouce name with extension (no initial slash)
Since:
org.openide.nodes 6.5

getIcon

public Image getIcon(int type)
Find an icon for this node. Uses an icon set.

Specified by:
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).

Specified by:
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.

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()
Can this node be renamed?

Specified by:
canRename in class Node
Returns:
false

canDestroy

public boolean canDestroy()
Can this node be destroyed?

Specified by:
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.

Specified by:
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.

Specified by:
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.

Specified by:
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.

Specified by:
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?

Specified by:
canCopy in class Node
Returns:
true

canCut

public boolean canCut()
Can this node be cut?

Specified by:
canCut in class Node
Returns:
false

createPasteTypes

protected void createPasteTypes(Transferable t,
                                List<PasteType> 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).

Specified by:
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.

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 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.

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

getPreferredAction

public Action getPreferredAction()
Gets preferred action. By default, null.

Overrides:
getPreferredAction in class Node
Returns:
preferred action
Since:
3.29
See Also:
Node.getPreferredAction()

getDefaultAction

@Deprecated
public SystemAction getDefaultAction()
Deprecated. Use getPreferredAction() instead.

Gets the default action. Overrides superclass method.

Overrides:
getDefaultAction in class Node
Returns:
if there is a default action set, then returns it

setDefaultAction

@Deprecated
public void setDefaultAction(SystemAction action)
Deprecated. Override getPreferredAction() instead.

Set a default action for the node.

Parameters:
action - the new default action, or null for none

getActions

@Deprecated
public SystemAction[] getActions()
Deprecated. Override Node.getActions(boolean) instead.

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

@Deprecated
protected SystemAction[] createActions()
Deprecated. Override Node.getActions(boolean) instead.

Lazily initialize set of node's actions (overridable). The default implementation returns null.

Warning: do not call getActions() within this method.

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?

Specified by:
hasCustomizer in class Node
Returns:
false

getCustomizer

public Component getCustomizer()
Get the customizer.

Specified by:
getCustomizer in class Node
Returns:
null in the default implementation

setCookieSet

@Deprecated
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
Throws:
IllegalStateException - If you pass a Lookup instance into the constructor, this method cannot be called.

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)
Throws:
IllegalStateException - If you pass a Lookup instance into the constructor, this method cannot be called.

getCookie

public <T extends Node.Cookie> T getCookie(Class<T> 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
See Also:
Lookup

getHandle

public Node.Handle getHandle()
Get a serializable handle for this node.

Specified by:
getHandle in class Node
Returns:
a DefaultHandle 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.