30.7.10

Nodes API

  • The Nodes API is the third and uppermost layer in the NetBeans Resource Management System.
  • The role of the Nodes API
    • is visual representation of data
  • Connection
    • Closely connected to this API is the Explorer & Property Sheet API
      • Which is the container and manager of nodes.
  • Usage
    • To present data to the user interface of an application
    • to give the user actions, functionality, and properties for interacting with underlying data.
  • Other usage
    • Need not merely present data
      • It can be used for many other things as well.
        • Examples:
          • An action hiding beneath a node could be invoked when the node is double-click.
  • Nodes and Business Logic
    • A node is not typically concerned with business logic
    • Bug focuses on providing a presentation layer, delegating user interaction to action classes and, where applicable, to its related DataObject.
  • Hierarchy of Node subclasses

image

  • AbstractNode
    • Provides the simplest form of the Node class.
    • Use this class to instance a new Node directly, without needing to implement or extend any of the Node classes.
  • FilterNode
    • Creates a proxy Node that delegates its method calls to the original Node.
    • This kind of Node is used when data needs to be displayed in different ways.
  • BeanNode
    • is used to represent a JavaBean.
  • IndexedNode
    • lets its children be organized based on a given index.
  • DataNode
    • Is most commonly used when representing data from files.
    • Is the Node type representing DataObject such as those you learned about in the previous sections.

Node Container

  • Each Node object has its own Children object, providing a container for child nodes, which are the nodes'’s subnodes.
  • The Children object is responsible for the creation, addition, and structuring of child notes.
  • Each node within the Children object has the Node that owns the Children object as its parent.
  • For nodes that do not have their own children, such as our DataNode for MP3 files, we pass in Children.LEAF as an empty container.

Different Children container class variations and their uses

  • Children.Array
    • Superclass for all other Children classes.
    • You should not derive from this class directly.
    • This container class messages its nodes in an Array.
    • The nodes wil be appended at the end of the array and will be delivered in the same order.
  • Children.Keys<T>
    • Typical superclass for your implementation.
    • Nodes are connected with a key.
    • These keys are also used for ordering.
  • Children.Map<T>
    • The nodes are stored in a Map.
    • The nodes are associated with a key.
      • which is also used for deleting nodes
  • Children.SortedArray
    • Extends the Children.Array class with a Comparator
  • Children.SortedMap<T>
    • Extends the Children.Map<T> class with a Comparator.

Actions

  • A node makes a context menu available to the user,
    • allowing context-sensitive actions.
  • A DataNode obtains its context menu’s actions from the DataLoader of the DataObject it represents.
  • A DataLoader defines a MIME-specific folder in the layer file via the method actionContex(),
    • where action are registered.
  • These are read and added automatically to the context menu.
  • For nodes that do not represent DataObject(s)
    • The getActions() method in the Node is used to define the actions in the context menu.
    • Override this method in your class to add

Event Handling

  • To react to Node events, use a PropertyChangeListener, as well as a NodeListener.
    • PropertyChangeListener
      • to be informed of changes to Node properties provided via the getPropertySet() method.
    • NodeListener
      • Can listen to internal node changes, such as changes to the name, the parent node, and the child nodes.
      • The Node class makes a range of property keys available, such as PROP_NAME and PROG_LEAF
  • NodeListener
    • childrenAdded(NodeMemberEvent evt)
    • childrenRemoved(NodeMemberEvent evt)
    • childrenReordered(NodeMemberEvent evt)
    • nodeDestroyed(NodeEvent evt)
    • propertyChange(PropertyChangeEvent evt)
  • NodeAdapter

Implementing Nodes and Children

No comments: