Class AbstractNode

All Implemented Interfaces:
org.openide.util.HelpCtx.Provider, org.openide.util.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.

  • Field Details

    • 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 org.openide.util.actions.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 Details

  • Method Details

    • 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)
      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:

      • org/foo/resource/MyIcon.png
      • org/foo/resource/MyIconOpen.png
      • org/foo/resource/MyIcon32.png
      • org/foo/resource/MyIconOpen32.png

      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 org.openide.util.HelpCtx getHelpCtx()
      Description copied from class: Node
      Get context help associated with this node.
      Specified by:
      getHelpCtx in interface org.openide.util.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:
    • 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:
    • 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:
    • 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<org.openide.util.datatransfer.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 org.openide.util.datatransfer.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<org.openide.util.datatransfer.PasteType>).
      Specified by:
      getPasteTypes in class Node
      Parameters:
      t - the transferable in the clipboard
      Returns:
      array of operations that are allowed
    • getDropType

      public org.openide.util.datatransfer.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 org.openide.util.datatransfer.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:
    • getDefaultAction

      @Deprecated public org.openide.util.actions.SystemAction getDefaultAction()
      Deprecated.
      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(org.openide.util.actions.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 org.openide.util.actions.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 org.openide.util.actions.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