Class BeanNode<T>

Type Parameters:
T - the type of bean to be represented
All Implemented Interfaces:
org.openide.util.HelpCtx.Provider, org.openide.util.Lookup.Provider

public class BeanNode<T> extends AbstractNode

Represents a JavaBeans component as a node.

You may use this node type for an already-existing JavaBean (possibly using BeanContext) in order for its JavaBean properties to be reflected as corresponding node properties. Thus, it serves as a compatibility wrapper.

The bean passed in the constructor will be available in the node's lookup, though not directly. Instead, the node's Lookup will contain an InstanceCookie from which you can retrieve the bean instance.

  • Constructor Details

  • Method Details

    • setSynchronizeName

      protected void setSynchronizeName(boolean watch)
      Set whether or not to keep the node name and Bean name synchronized automatically. If enabled, the node will listen to changes in the name of the bean and update the (system) name of the node appropriately. The name of the bean can be obtained by calling getName (), getDisplayName () or from FeatureDescriptor.getDisplayName().

      Also when the (system) name of the node is changing, the change propagates if possible to methods setName (String) or setDisplayName (String). (This does not apply to setting the display name of the node, however.)

      By default this feature is turned on.

      Parameters:
      watch - true if the name of the node should be synchronized with the name of the bean, false if the name of the node should be independent or manually updated
    • getBean

      protected T getBean()
      Provides access to the bean represented by this BeanNode.
      Returns:
      instance of the bean represented by this BeanNode
    • destroy

      public void destroy() throws IOException
      Detaches all listeners from the bean and destroys it.
      Overrides:
      destroy in class Node
      Throws:
      IOException - if there was a problem
    • canDestroy

      public boolean canDestroy()
      Can this node be removed?
      Overrides:
      canDestroy in class AbstractNode
      Returns:
      true in this implementation
    • setName

      public void setName(String s)
      Set the node name. Also may attempt to change the name of the bean, according to setSynchronizeName(boolean).
      Overrides:
      setName in class AbstractNode
      Parameters:
      s - the new name
    • canRename

      public boolean canRename()
      Can this node be renamed?
      Overrides:
      canRename in class AbstractNode
      Returns:
      true if there is no name synchronization, or there is a valid setter method for the name
    • getIcon

      public Image getIcon(int type)
      Get an icon for this node in the closed state. Uses the Bean's icon if possible.
      Overrides:
      getIcon in class AbstractNode
      Parameters:
      type - constant from BeanInfo
      Returns:
      icon to use
    • getOpenedIcon

      public Image getOpenedIcon(int type)
      Get an icon for this node in the open state.
      Overrides:
      getOpenedIcon in class AbstractNode
      Parameters:
      type - type constants
      Returns:
      icon to use. The default implementation just uses getIcon(int).
    • 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
      Overrides:
      getHelpCtx in class AbstractNode
      Returns:
      the context help object (could be null or HelpCtx.DEFAULT_HELP)
    • createProperties

      protected void createProperties(T bean, BeanInfo info)
      Prepare node properties based on the bean, storing them into the current property sheet. Called when the bean info is ready. This implementation always creates a set for standard properties and may create a set for expert ones if there are any.
      Parameters:
      bean - bean to compute properties for
      info - information about the bean
      See Also:
    • canCopy

      public boolean canCopy()
      Can this node be copied?
      Overrides:
      canCopy in class AbstractNode
      Returns:
      true in the default implementation
    • canCut

      public boolean canCut()
      Can this node be cut?
      Overrides:
      canCut in class AbstractNode
      Returns:
      false in the default implementation
    • 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)
    • hasCustomizer

      public boolean hasCustomizer()
      Description copied from class: AbstractNode
      Does this node have a customizer?
      Overrides:
      hasCustomizer in class AbstractNode
      Returns:
      false
    • getCustomizer

      public Component getCustomizer()
      Description copied from class: AbstractNode
      Get the customizer.
      Overrides:
      getCustomizer in class AbstractNode
      Returns:
      null in the default implementation
    • computeProperties

      public static BeanNode.Descriptor computeProperties(Object bean, BeanInfo info)
      Computes a descriptor for properties from a bean info.

      Property code names are taken from the property descriptor names according to the JavaBeans specification. For example, a pair of methods getFoo and setFoo would result in a node property with code name foo. If you call MyBean.setFoo(...), this should result in a property change event with name foo; if you are using these properties in some other context (attached to something other than a BeanNode) then be careful to fire changes with the correct name, or there may be problems with refreshing display of the property etc.

      Parameters:
      bean - bean to create properties for
      info - about the bean
      Returns:
      three property lists
    • getPreferredAction

      public Action getPreferredAction()
      Description copied from class: AbstractNode
      Gets preferred action. By default, null.
      Overrides:
      getPreferredAction in class AbstractNode
      Returns:
      preferred action
      See Also: